GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_image_reader_pixel_read_callback_set.c Lines: 403 403 100.0 %
Date: 2026-03-06 19:21:09 Branches: 108 108 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
10
 **************************************************************************/
11
12
13
/**************************************************************************/
14
/**************************************************************************/
15
/**                                                                       */
16
/** GUIX Component                                                        */
17
/**                                                                       */
18
/**   Image Reader Management (Image Reader)                              */
19
/**                                                                       */
20
/**************************************************************************/
21
22
#define GX_SOURCE_CODE
23
24
/* Include necessary system files.  */
25
26
#include "gx_api.h"
27
#include "gx_system.h"
28
#include "gx_utility.h"
29
#include "gx_image_reader.h"
30
31
#if defined(GX_SOFTWARE_DECODER_SUPPORT)
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _gx_image_reader_8bit_alpha_read                    PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Kenneth Maxwell, Microsoft Corporation                              */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function reads 8bit alpha value from input pixelmap data.      */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    image_reader                         Image reader control block     */
49
/*    index                                Row index.                     */
50
/*    pixel                                Retrieved pixel.               */
51
/*                                                                        */
52
/*  OUTPUT                                                                */
53
/*                                                                        */
54
/*    Completion Status                                                   */
55
/*                                                                        */
56
/*  CALLS                                                                 */
57
/*                                                                        */
58
/*    None                                                                */
59
/*                                                                        */
60
/*  CALLED BY                                                             */
61
/*                                                                        */
62
/*    _gx_image_reader_pixel_read_callback_set                            */
63
/*                                                                        */
64
/**************************************************************************/
65
10273056
static UINT _gx_image_reader_8bit_alpha_read(GX_IMAGE_READER *image_reader, INT index, GX_PIXEL *pixel)
66
{
67
GX_UBYTE *pLine;
68
69
10273056
    pLine = image_reader -> gx_image_reader_getdata;
70
10273056
    pLine += index;
71
72
10273056
    pixel -> gx_pixel_red = 0;
73
10273056
    pixel -> gx_pixel_green = 0;
74
10273056
    pixel -> gx_pixel_blue = 0;
75
10273056
    pixel -> gx_pixel_alpha = *pLine;
76
77
10273056
    return GX_SUCCESS;
78
}
79
80
/**************************************************************************/
81
/*                                                                        */
82
/*  FUNCTION                                               RELEASE        */
83
/*                                                                        */
84
/*    _gx_image_reader_1bit_pixel_read                    PORTABLE C      */
85
/*                                                           6.1          */
86
/*  AUTHOR                                                                */
87
/*                                                                        */
88
/*    Kenneth Maxwell, Microsoft Corporation                              */
89
/*                                                                        */
90
/*  DESCRIPTION                                                           */
91
/*                                                                        */
92
/*    This function reads a pixel from input pixelmap data structure.     */
93
/*                                                                        */
94
/*  INPUT                                                                 */
95
/*                                                                        */
96
/*    image_reader                         Image reader control block     */
97
/*    index                                Row index.                     */
98
/*    pixel                                Retrieved pixel.               */
99
/*                                                                        */
100
/*  OUTPUT                                                                */
101
/*                                                                        */
102
/*    Completion Status                                                   */
103
/*                                                                        */
104
/*  CALLS                                                                 */
105
/*                                                                        */
106
/*    None                                                                */
107
/*                                                                        */
108
/*  CALLED BY                                                             */
109
/*                                                                        */
110
/*    _gx_image_reader_pixel_read_callback_set                            */
111
/*                                                                        */
112
/**************************************************************************/
113
13312
static UINT _gx_image_reader_1bit_pixel_read(GX_IMAGE_READER *image_reader, INT index, GX_PIXEL *pixel)
114
{
115
GX_UBYTE *pLine;
116
GX_COLOR *pal;
117
UINT      palindex;
118
119
13312
    pLine = image_reader -> gx_image_reader_getdata;
120
13312
    pLine += (index >> 3);
121
122
13312
    palindex = *pLine;
123
13312
    palindex >>= (7 - (index & 0x7));
124
13312
    palindex &= 0x01;
125
126
13312
    if ((image_reader -> gx_image_reader_png_trans) &&
127
3072
        (palindex == image_reader -> gx_image_reader_png_trans[0]))
128
    {
129
        /* Transparent */
130
1572
        pixel -> gx_pixel_alpha = 0;
131
1572
        pixel -> gx_pixel_red = 0;
132
1572
        pixel -> gx_pixel_green = 0;
133
1572
        pixel -> gx_pixel_blue = 0;
134
    }
135
    else
136
    {
137
11740
        pal = (GX_COLOR *)image_reader -> gx_image_reader_png_palette;
138
139
11740
        if (pal)
140
        {
141
            /* Palette */
142
6144
            if (palindex < image_reader -> gx_image_reader_png_palette_size)
143
            {
144
5120
                pixel -> gx_pixel_red = (GX_UBYTE)(pal[palindex] >> 16);
145
5120
                pixel -> gx_pixel_green = (GX_UBYTE)(pal[palindex] >> 8);
146
5120
                pixel -> gx_pixel_blue = (GX_UBYTE)pal[palindex];
147
5120
                pixel -> gx_pixel_alpha = 0xff;
148
            }
149
            else
150
            {
151
1024
                memset(pixel, 0, sizeof(GX_PIXEL));
152
            }
153
        }
154
        else
155
        {
156
            /* Gray */
157
5596
            palindex *= 255;
158
5596
            pixel -> gx_pixel_red = (GX_UBYTE)palindex;
159
5596
            pixel -> gx_pixel_green = (GX_UBYTE)palindex;
160
5596
            pixel -> gx_pixel_blue = (GX_UBYTE)palindex;
161
5596
            pixel -> gx_pixel_alpha = 0xff;
162
        }
163
    }
164
165
13312
    return GX_SUCCESS;
166
}
167
168
/**************************************************************************/
169
/*                                                                        */
170
/*  FUNCTION                                               RELEASE        */
171
/*                                                                        */
172
/*    _gx_image_reader_2bit_pixel_read                    PORTABLE C      */
173
/*                                                           6.1          */
174
/*  AUTHOR                                                                */
175
/*                                                                        */
176
/*    Kenneth Maxwell, Microsoft Corporation                              */
177
/*                                                                        */
178
/*  DESCRIPTION                                                           */
179
/*                                                                        */
180
/*    This function reads a pixel from input pixelmap data structure.     */
181
/*                                                                        */
182
/*  INPUT                                                                 */
183
/*                                                                        */
184
/*    image_reader                         Image reader control block     */
185
/*    index                                Row index.                     */
186
/*    pixel                                Retrieved pixel.               */
187
/*                                                                        */
188
/*  OUTPUT                                                                */
189
/*                                                                        */
190
/*    Completion Status                                                   */
191
/*                                                                        */
192
/*  CALLS                                                                 */
193
/*                                                                        */
194
/*    None                                                                */
195
/*                                                                        */
196
/*  CALLED BY                                                             */
197
/*                                                                        */
198
/*    _gx_image_reader_pixel_read_callback_set                            */
199
/*                                                                        */
200
/**************************************************************************/
201
12288
static UINT _gx_image_reader_2bit_pixel_read(GX_IMAGE_READER *image_reader, INT index, GX_PIXEL *pixel)
202
{
203
GX_UBYTE *pLine;
204
GX_COLOR *pal;
205
UINT      palindex;
206
207
12288
    pLine = image_reader -> gx_image_reader_getdata;
208
12288
    pLine += (index >> 2);
209
210
12288
    palindex = *pLine;
211
12288
    palindex >>= (3 - (index & 0x3)) * 2;
212
12288
    palindex &= 0x03;
213
214
12288
    if ((image_reader -> gx_image_reader_png_trans) &&
215
2048
        (palindex == image_reader -> gx_image_reader_png_trans[0]))
216
    {
217
        /* Transparent */
218
512
        pixel -> gx_pixel_alpha = 0;
219
512
        pixel -> gx_pixel_red = 0;
220
512
        pixel -> gx_pixel_green = 0;
221
512
        pixel -> gx_pixel_blue = 0;
222
    }
223
    else
224
    {
225
11776
        pal = image_reader -> gx_image_reader_png_palette;
226
227
11776
        if (pal)
228
        {
229
            /* Palette */
230
6144
            if (palindex < image_reader -> gx_image_reader_png_palette_size)
231
            {
232
5632
                pixel -> gx_pixel_red = (GX_UBYTE)(pal[palindex] >> 16);
233
5632
                pixel -> gx_pixel_green = (GX_UBYTE)(pal[palindex] >> 8);
234
5632
                pixel -> gx_pixel_blue = (GX_UBYTE)pal[palindex];
235
5632
                pixel -> gx_pixel_alpha = 0xff;
236
            }
237
            else
238
            {
239
512
                memset(pixel, 0, sizeof(GX_PIXEL));
240
            }
241
        }
242
        else
243
        {
244
            /* Gray */
245
5632
            palindex = palindex * 255 / 3;
246
5632
            pixel -> gx_pixel_red = (GX_UBYTE)palindex;
247
5632
            pixel -> gx_pixel_green = (GX_UBYTE)palindex;
248
5632
            pixel -> gx_pixel_blue = (GX_UBYTE)palindex;
249
5632
            pixel -> gx_pixel_alpha = 0xff;
250
        }
251
    }
252
253
12288
    return GX_SUCCESS;
254
}
255
256
257
/**************************************************************************/
258
/*                                                                        */
259
/*  FUNCTION                                               RELEASE        */
260
/*                                                                        */
261
/*    _gx_image_reader_4bit_pixel_read                    PORTABLE C      */
262
/*                                                           6.1          */
263
/*  AUTHOR                                                                */
264
/*                                                                        */
265
/*    Kenneth Maxwell, Microsoft Corporation                              */
266
/*                                                                        */
267
/*  DESCRIPTION                                                           */
268
/*                                                                        */
269
/*    This function reads a pixel from input pixelmap data structure.     */
270
/*                                                                        */
271
/*  INPUT                                                                 */
272
/*                                                                        */
273
/*    image_reader                         Image reader control block     */
274
/*    index                                Row index.                     */
275
/*    pixel                                Retrieved pixel.               */
276
/*                                                                        */
277
/*  OUTPUT                                                                */
278
/*                                                                        */
279
/*    Completion Status                                                   */
280
/*                                                                        */
281
/*  CALLS                                                                 */
282
/*                                                                        */
283
/*    None                                                                */
284
/*                                                                        */
285
/*  CALLED BY                                                             */
286
/*                                                                        */
287
/*    _gx_image_reader_pixel_read_callback_set                            */
288
/*                                                                        */
289
/**************************************************************************/
290
18432
static UINT _gx_image_reader_4bit_pixel_read(GX_IMAGE_READER *image_reader, INT index, GX_PIXEL *pixel)
291
{
292
GX_UBYTE *pLine;
293
GX_COLOR *pal;
294
UINT      palindex;
295
296
18432
    pLine = image_reader -> gx_image_reader_getdata;
297
18432
    pLine += (index >> 1);
298
299
18432
    palindex = *pLine;
300
18432
    palindex >>= (1 - (index & 0x01)) * 4;
301
18432
    palindex &= 0x0f;
302
303
18432
    if ((image_reader -> gx_image_reader_png_trans) &&
304
4096
        (palindex == image_reader -> gx_image_reader_png_trans[0]))
305
    {
306
        /* Transparent */
307
2064
        pixel -> gx_pixel_alpha = 0;
308
2064
        pixel -> gx_pixel_red = 0;
309
2064
        pixel -> gx_pixel_green = 0;
310
2064
        pixel -> gx_pixel_blue = 0;
311
    }
312
    else
313
    {
314
16368
        pal = image_reader -> gx_image_reader_png_palette;
315
316
16368
        if (pal)
317
        {
318
            /* Pixel */
319
10240
            if (palindex < image_reader -> gx_image_reader_png_palette_size)
320
            {
321
10016
                pixel -> gx_pixel_red = (GX_UBYTE)(pal[palindex] >> 16);
322
10016
                pixel -> gx_pixel_green = (GX_UBYTE)(pal[palindex] >> 8);
323
10016
                pixel -> gx_pixel_blue = (GX_UBYTE)pal[palindex];
324
10016
                pixel -> gx_pixel_alpha = 0xff;
325
            }
326
            else
327
            {
328
224
                memset(pixel, 0, sizeof(GX_PIXEL));
329
            }
330
        }
331
        else
332
        {
333
            /* Gray */
334
6128
            palindex = palindex * 255 / 15;
335
6128
            pixel -> gx_pixel_red = (GX_UBYTE)palindex;
336
6128
            pixel -> gx_pixel_green = (GX_UBYTE)palindex;
337
6128
            pixel -> gx_pixel_blue = (GX_UBYTE)palindex;
338
6128
            pixel -> gx_pixel_alpha = 0xff;
339
        }
340
    }
341
342
18432
    return GX_SUCCESS;
343
}
344
345
/**************************************************************************/
346
/*                                                                        */
347
/*  FUNCTION                                               RELEASE        */
348
/*                                                                        */
349
/*    _gx_image_reader_8bit_pixel_read                    PORTABLE C      */
350
/*                                                           6.1          */
351
/*  AUTHOR                                                                */
352
/*                                                                        */
353
/*    Kenneth Maxwell, Microsoft Corporation                              */
354
/*                                                                        */
355
/*  DESCRIPTION                                                           */
356
/*                                                                        */
357
/*    This function reads a pixel from input pixelmap data structure.     */
358
/*                                                                        */
359
/*  INPUT                                                                 */
360
/*                                                                        */
361
/*    image_reader                         Image reader control block     */
362
/*    index                                Row index.                     */
363
/*    pixel                                Retrieved pixel.               */
364
/*                                                                        */
365
/*  OUTPUT                                                                */
366
/*                                                                        */
367
/*    Completion Status                                                   */
368
/*                                                                        */
369
/*  CALLS                                                                 */
370
/*                                                                        */
371
/*    None                                                                */
372
/*                                                                        */
373
/*  CALLED BY                                                             */
374
/*                                                                        */
375
/*    _gx_image_reader_pixel_read_callback_set                            */
376
/*                                                                        */
377
/**************************************************************************/
378
47104
static UINT _gx_image_reader_8bit_pixel_read(GX_IMAGE_READER *image_reader, INT index, GX_PIXEL *pixel)
379
{
380
GX_COLOR *palette;
381
UINT      palsize;
382
UINT      palindex;
383
384
47104
    palindex = *(image_reader -> gx_image_reader_getdata + index);
385
386
47104
    if ((image_reader -> gx_image_reader_png_trans) &&
387
16384
        (palindex == image_reader -> gx_image_reader_png_trans[0]))
388
    {
389
        /* Transparent */
390
8048
        pixel -> gx_pixel_alpha = 0;
391
8048
        pixel -> gx_pixel_red = 0;
392
8048
        pixel -> gx_pixel_green = 0;
393
8048
        pixel -> gx_pixel_blue = 0;
394
    }
395
    else
396
    {
397
39056
        palette = image_reader -> gx_image_reader_png_palette;
398
39056
        palsize = image_reader -> gx_image_reader_png_palette_size;
399
400
39056
        if (palette)
401
        {
402
            /* Palette */
403
22672
            if (palindex < palsize)
404
            {
405
22664
                pixel -> gx_pixel_red = (GX_UBYTE)(palette[palindex] >> 16);
406
22664
                pixel -> gx_pixel_green = (GX_UBYTE)(palette[palindex] >> 8);
407
22664
                pixel -> gx_pixel_blue = (GX_UBYTE)palette[palindex];
408
22664
                pixel -> gx_pixel_alpha = 0xff;
409
            }
410
            else
411
            {
412
8
                memset(pixel, 0, sizeof(GX_PIXEL));
413
            }
414
        }
415
        else
416
        {
417
            /* Gray */
418
16384
            pixel -> gx_pixel_red = (GX_UBYTE)palindex;
419
16384
            pixel -> gx_pixel_green = (GX_UBYTE)palindex;
420
16384
            pixel -> gx_pixel_blue = (GX_UBYTE)palindex;
421
16384
            pixel -> gx_pixel_alpha = 0xff;
422
        }
423
    }
424
425
47104
    return GX_SUCCESS;
426
}
427
428
/**************************************************************************/
429
/*                                                                        */
430
/*  FUNCTION                                               RELEASE        */
431
/*                                                                        */
432
/*    _gx_image_reader_8bit_palette_pixel_read            PORTABLE C      */
433
/*                                                           6.1          */
434
/*  AUTHOR                                                                */
435
/*                                                                        */
436
/*    Kenneth Maxwell, Microsoft Corporation                              */
437
/*                                                                        */
438
/*  DESCRIPTION                                                           */
439
/*                                                                        */
440
/*    This function reads a pixel from input pixelmap data structure.     */
441
/*                                                                        */
442
/*  INPUT                                                                 */
443
/*                                                                        */
444
/*    image_reader                         Image reader control block     */
445
/*    index                                Row index.                     */
446
/*    pixel                                Retrieved pixel.               */
447
/*                                                                        */
448
/*  OUTPUT                                                                */
449
/*                                                                        */
450
/*    Completion Status                                                   */
451
/*                                                                        */
452
/*  CALLS                                                                 */
453
/*                                                                        */
454
/*    None                                                                */
455
/*                                                                        */
456
/*  CALLED BY                                                             */
457
/*                                                                        */
458
/*    _gx_image_reader_pixel_read_callback_set                            */
459
/*                                                                        */
460
/**************************************************************************/
461
6854362
static UINT _gx_image_reader_8bit_palette_pixel_read(GX_IMAGE_READER *image_reader, INT index, GX_PIXEL *pixel)
462
{
463
6854362
GX_COLOR *palette = image_reader -> gx_image_reader_palette;
464
UINT      palindex;
465
466
6854362
    palindex = *(image_reader -> gx_image_reader_getdata + index);
467
468
6854362
    if (palette)
469
    {
470
        /* Palette */
471

6713386
        if ((image_reader -> gx_image_reader_mode & GX_IMAGE_READER_MODE_ALPHA) &&
472
            (GX_TRANSPARENT_COLOR == palindex))
473
        {
474
168056
            pixel -> gx_pixel_alpha = 0;
475
168056
            pixel -> gx_pixel_red = 0;
476
168056
            pixel -> gx_pixel_green = 0;
477
168056
            pixel -> gx_pixel_blue = 0;
478
        }
479
        else
480
        {
481
6545330
            pixel -> gx_pixel_red = (GX_UBYTE)(palette[palindex] >> 16);
482
6545330
            pixel -> gx_pixel_green = (GX_UBYTE)(palette[palindex] >> 8);
483
6545330
            pixel -> gx_pixel_blue = (GX_UBYTE)palette[palindex];
484
6545330
            pixel -> gx_pixel_alpha = 0xff;
485
        }
486
    }
487
    else
488
    {
489
140976
        memset(pixel, 0, sizeof(GX_PIXEL));
490
    }
491
492
6854362
    return GX_SUCCESS;
493
}
494
495
/**************************************************************************/
496
/*                                                                        */
497
/*  FUNCTION                                               RELEASE        */
498
/*                                                                        */
499
/*    _gx_image_reader_16bit_gray_alpha_read              PORTABLE C      */
500
/*                                                           6.1          */
501
/*  AUTHOR                                                                */
502
/*                                                                        */
503
/*    Kenneth Maxwell, Microsoft Corporation                              */
504
/*                                                                        */
505
/*  DESCRIPTION                                                           */
506
/*                                                                        */
507
/*    This function reads a pixel from input pixelmap data structure.     */
508
/*                                                                        */
509
/*  INPUT                                                                 */
510
/*                                                                        */
511
/*    image_reader                         Image reader control block     */
512
/*    index                                Row index.                     */
513
/*    pixel                                Retrieved pixel.               */
514
/*                                                                        */
515
/*  OUTPUT                                                                */
516
/*                                                                        */
517
/*    Completion Status                                                   */
518
/*                                                                        */
519
/*  CALLS                                                                 */
520
/*                                                                        */
521
/*    None                                                                */
522
/*                                                                        */
523
/*  CALLED BY                                                             */
524
/*                                                                        */
525
/*    _gx_image_reader_pixel_read_callback_set                            */
526
/*                                                                        */
527
/**************************************************************************/
528
48448
static UINT _gx_image_reader_16bit_gray_alpha_read(GX_IMAGE_READER *image_reader, INT index, GX_PIXEL *pixel)
529
{
530
GX_UBYTE *pLine;
531
532
48448
    pLine = image_reader -> gx_image_reader_getdata;
533
48448
    pLine += (index << 1);
534
535
    /* Trans is prohibited for this color types, since a full alpha channel is already present. */
536
48448
    pixel -> gx_pixel_red = *pLine;
537
48448
    pixel -> gx_pixel_green = *pLine;
538
48448
    pixel -> gx_pixel_blue = *pLine++;
539
48448
    pixel -> gx_pixel_alpha = *pLine;
540
541
48448
    return GX_SUCCESS;
542
}
543
544
/**************************************************************************/
545
/*                                                                        */
546
/*  FUNCTION                                               RELEASE        */
547
/*                                                                        */
548
/*    _gx_image_reader_32bit_gray_alpha_read              PORTABLE C      */
549
/*                                                           6.1          */
550
/*  AUTHOR                                                                */
551
/*                                                                        */
552
/*    Kenneth Maxwell, Microsoft Corporation                              */
553
/*                                                                        */
554
/*  DESCRIPTION                                                           */
555
/*                                                                        */
556
/*    This function reads a pixel from input pixelmap data structure.     */
557
/*                                                                        */
558
/*                                                                        */
559
/*  INPUT                                                                 */
560
/*                                                                        */
561
/*    image_reader                         Image reader control block     */
562
/*    index                                Row index.                     */
563
/*    pixel                                Retrieved pixel.               */
564
/*                                                                        */
565
/*  OUTPUT                                                                */
566
/*                                                                        */
567
/*    Completion Status                                                   */
568
/*                                                                        */
569
/*  CALLS                                                                 */
570
/*                                                                        */
571
/*    None                                                                */
572
/*                                                                        */
573
/*  CALLED BY                                                             */
574
/*                                                                        */
575
/*    _gx_image_reader_pixel_read_callback_set                            */
576
/*                                                                        */
577
/**************************************************************************/
578
4096
static UINT _gx_image_reader_32bit_gray_alpha_read(GX_IMAGE_READER *image_reader, INT index, GX_PIXEL *pixel)
579
{
580
GX_UBYTE *pLine;
581
582
4096
    pLine = image_reader -> gx_image_reader_getdata;
583
4096
    pLine += (index << 2);
584
585
4096
    pixel -> gx_pixel_red = *pLine;
586
4096
    pixel -> gx_pixel_green = pixel -> gx_pixel_red;
587
4096
    pixel -> gx_pixel_blue = pixel -> gx_pixel_red;
588
4096
    pLine += 2;
589
4096
    pixel -> gx_pixel_alpha = (GX_UBYTE)*pLine;
590
591
4096
    return GX_SUCCESS;
592
}
593
594
/**************************************************************************/
595
/*                                                                        */
596
/*  FUNCTION                                               RELEASE        */
597
/*                                                                        */
598
/*    _gx_image_reader_24bit_pixel_read                   PORTABLE C      */
599
/*                                                           6.1          */
600
/*  AUTHOR                                                                */
601
/*                                                                        */
602
/*    Kenneth Maxwell, Microsoft Corporation                              */
603
/*                                                                        */
604
/*  DESCRIPTION                                                           */
605
/*                                                                        */
606
/*    This function reads a pixel from input pixelmap data structure.     */
607
/*                                                                        */
608
/*  INPUT                                                                 */
609
/*                                                                        */
610
/*    image_reader                         Image reader control block     */
611
/*    index                                Row index.                     */
612
/*    pixel                                Retrieved pixel.               */
613
/*                                                                        */
614
/*  OUTPUT                                                                */
615
/*                                                                        */
616
/*    Completion Status                                                   */
617
/*                                                                        */
618
/*  CALLS                                                                 */
619
/*                                                                        */
620
/*    None                                                                */
621
/*                                                                        */
622
/*  CALLED BY                                                             */
623
/*                                                                        */
624
/*    _gx_image_reader_pixel_read_callback_set                            */
625
/*                                                                        */
626
/**************************************************************************/
627
8603020
static UINT _gx_image_reader_24bit_pixel_read(GX_IMAGE_READER *image_reader, INT index, GX_PIXEL *pixel)
628
{
629
GX_UBYTE *pLine;
630
8603020
GX_COLOR *pTrans = image_reader -> gx_image_reader_png_trans;
631
632
8603020
    pLine = image_reader -> gx_image_reader_getdata;
633
8603020
    pLine += index * 3;
634
635
8603020
    pixel -> gx_pixel_red = *pLine++;
636
8603020
    pixel -> gx_pixel_green = *pLine++;
637
8603020
    pixel -> gx_pixel_blue = *pLine;
638
639
8603020
    if ((pTrans) &&
640
10240
        (pixel -> gx_pixel_red == pTrans[0]) &&
641
5052
        (pixel -> gx_pixel_green == pTrans[1]) &&
642
4542
        (pixel -> gx_pixel_blue == pTrans[2]))
643
    {
644
4032
        pixel -> gx_pixel_alpha = 0;
645
    }
646
    else
647
    {
648
8598988
        pixel -> gx_pixel_alpha = 0xff;
649
    }
650
651
8603020
    return GX_SUCCESS;
652
}
653
654
/**************************************************************************/
655
/*                                                                        */
656
/*  FUNCTION                                               RELEASE        */
657
/*                                                                        */
658
/*    _gx_image_reader_48bit_pixel_read                   PORTABLE C      */
659
/*                                                           6.1          */
660
/*  AUTHOR                                                                */
661
/*                                                                        */
662
/*    Kenneth Maxwell, Microsoft Corporation                              */
663
/*                                                                        */
664
/*  DESCRIPTION                                                           */
665
/*                                                                        */
666
/*    This function reads a pixel from input pixelmap data structure.     */
667
/*                                                                        */
668
/*  INPUT                                                                 */
669
/*                                                                        */
670
/*    image_reader                         Image reader control block     */
671
/*    index                                Row index.                     */
672
/*    pixel                                Retrieved pixel.               */
673
/*                                                                        */
674
/*  OUTPUT                                                                */
675
/*                                                                        */
676
/*    Completion Status                                                   */
677
/*                                                                        */
678
/*  CALLS                                                                 */
679
/*                                                                        */
680
/*    None                                                                */
681
/*                                                                        */
682
/*  CALLED BY                                                             */
683
/*                                                                        */
684
/*    _gx_image_reader_pixel_read_callback_set                            */
685
/*                                                                        */
686
/**************************************************************************/
687
34816
static UINT _gx_image_reader_48bit_pixel_read(GX_IMAGE_READER *image_reader, INT index, GX_PIXEL *pixel)
688
{
689
GX_UBYTE *pLine;
690
34816
GX_COLOR *pTrans = image_reader -> gx_image_reader_png_trans;
691
692
34816
    pLine = image_reader -> gx_image_reader_getdata;
693
34816
    pLine += index * 6;
694
695
34816
    pixel -> gx_pixel_red = *pLine;
696
34816
    pLine += 2;
697
34816
    pixel -> gx_pixel_green = *pLine;
698
34816
    pLine += 2;
699
34816
    pixel -> gx_pixel_blue = *pLine;
700
701
34816
    if ((pTrans) &&
702
10240
        (pixel -> gx_pixel_red == (GX_UBYTE)pTrans[0]) &&
703
4088
        (pixel -> gx_pixel_green == (GX_UBYTE)pTrans[1]) &&
704
4026
        (pixel -> gx_pixel_blue == (GX_UBYTE)pTrans[2]))
705
    {
706
4024
        pixel -> gx_pixel_alpha = 0;
707
    }
708
    else
709
    {
710
30792
        pixel -> gx_pixel_alpha = 0xff;
711
    }
712
713
34816
    return GX_SUCCESS;
714
}
715
716
/**************************************************************************/
717
/*                                                                        */
718
/*  FUNCTION                                               RELEASE        */
719
/*                                                                        */
720
/*    _gx_image_reader_64bit_pixel_read                   PORTABLE C      */
721
/*                                                           6.1          */
722
/*  AUTHOR                                                                */
723
/*                                                                        */
724
/*    Kenneth Maxwell, Microsoft Corporation                              */
725
/*                                                                        */
726
/*  DESCRIPTION                                                           */
727
/*                                                                        */
728
/*    This function reads a pixel from input pixelmap data structure.     */
729
/*                                                                        */
730
/*  INPUT                                                                 */
731
/*                                                                        */
732
/*    image_reader                         Image reader control block     */
733
/*    index                                Row index.                     */
734
/*    pixel                                Retrieved pixel.               */
735
/*                                                                        */
736
/*  OUTPUT                                                                */
737
/*                                                                        */
738
/*    Completion Status                                                   */
739
/*                                                                        */
740
/*  CALLS                                                                 */
741
/*                                                                        */
742
/*    None                                                                */
743
/*                                                                        */
744
/*  CALLED BY                                                             */
745
/*                                                                        */
746
/*    _gx_image_reader_pixel_read_callback_set                            */
747
/*                                                                        */
748
/**************************************************************************/
749
4096
static UINT _gx_image_reader_64bit_pixel_read(GX_IMAGE_READER *image_reader, INT index, GX_PIXEL *pixel)
750
{
751
GX_UBYTE *pLine;
752
753
4096
    pLine = image_reader -> gx_image_reader_getdata;
754
4096
    pLine += (index << 3);
755
756
4096
    pixel -> gx_pixel_red = *pLine;
757
4096
    pLine += 2;
758
4096
    pixel -> gx_pixel_green = *pLine;
759
4096
    pLine += 2;
760
4096
    pixel -> gx_pixel_blue = *pLine;
761
4096
    pLine += 2;
762
4096
    pixel -> gx_pixel_alpha = *pLine;
763
764
4096
    return GX_SUCCESS;
765
}
766
767
/**************************************************************************/
768
/*                                                                        */
769
/*  FUNCTION                                               RELEASE        */
770
/*                                                                        */
771
/*    _gx_image_reader_32argb_pixel_read                  PORTABLE C      */
772
/*                                                           6.1          */
773
/*  AUTHOR                                                                */
774
/*                                                                        */
775
/*    Kenneth Maxwell, Microsoft Corporation                              */
776
/*                                                                        */
777
/*  DESCRIPTION                                                           */
778
/*                                                                        */
779
/*    This function reads a pixel from input pixelmap data structure.     */
780
/*                                                                        */
781
/*  INPUT                                                                 */
782
/*                                                                        */
783
/*    image_reader                         Image reader control block     */
784
/*    index                                Row index.                     */
785
/*    pixel                                Retrieved pixel.               */
786
/*                                                                        */
787
/*  OUTPUT                                                                */
788
/*                                                                        */
789
/*    Completion Status                                                   */
790
/*                                                                        */
791
/*  CALLS                                                                 */
792
/*                                                                        */
793
/*    None                                                                */
794
/*                                                                        */
795
/*  CALLED BY                                                             */
796
/*                                                                        */
797
/*    _gx_image_reader_pixel_read_callback_set                            */
798
/*                                                                        */
799
/**************************************************************************/
800
5003064
static UINT _gx_image_reader_32argb_pixel_read(GX_IMAGE_READER *image_reader, INT index, GX_PIXEL *pixel)
801
{
802
GX_COLOR *pLine;
803
804
5003064
    pLine = (GX_COLOR *)image_reader -> gx_image_reader_getdata;
805
5003064
    pLine += index;
806
807
5003064
    pixel -> gx_pixel_alpha = (GX_UBYTE)((*pLine) >> 24);
808
5003064
    pixel -> gx_pixel_red = (GX_UBYTE)((*pLine) >> 16);
809
5003064
    pixel -> gx_pixel_green = (GX_UBYTE)((*pLine) >> 8);
810
5003064
    pixel -> gx_pixel_blue = (GX_UBYTE)(*pLine);
811
812
5003064
    return GX_SUCCESS;
813
}
814
815
/**************************************************************************/
816
/*                                                                        */
817
/*  FUNCTION                                               RELEASE        */
818
/*                                                                        */
819
/*    _gx_image_reader_32bit_pixel_read                   PORTABLE C      */
820
/*                                                           6.1          */
821
/*  AUTHOR                                                                */
822
/*                                                                        */
823
/*    Kenneth Maxwell, Microsoft Corporation                              */
824
/*                                                                        */
825
/*  DESCRIPTION                                                           */
826
/*                                                                        */
827
/*    This function reads a pixel from input pixelmap data structure.     */
828
/*                                                                        */
829
/*  INPUT                                                                 */
830
/*                                                                        */
831
/*    image_reader                         Image reader control block     */
832
/*    index                                Row index.                     */
833
/*    pixel                                Retrieved pixel.               */
834
/*                                                                        */
835
/*  OUTPUT                                                                */
836
/*                                                                        */
837
/*    Completion Status                                                   */
838
/*                                                                        */
839
/*  CALLS                                                                 */
840
/*                                                                        */
841
/*    None                                                                */
842
/*                                                                        */
843
/*  CALLED BY                                                             */
844
/*                                                                        */
845
/*    _gx_image_reader_pixel_read_callback_set                            */
846
/*                                                                        */
847
/**************************************************************************/
848
13849630
static UINT _gx_image_reader_32bit_pixel_read(GX_IMAGE_READER *image_reader, INT index, GX_PIXEL *pixel)
849
{
850
GX_UBYTE *pget;
851
852
13849630
    pget = (GX_UBYTE *)image_reader -> gx_image_reader_getdata;
853
13849630
    pget += (index << 2);
854
855
13849630
    pixel -> gx_pixel_red = *pget++;
856
13849630
    pixel -> gx_pixel_green = *pget++;
857
13849630
    pixel -> gx_pixel_blue = *pget++;
858
13849630
    pixel -> gx_pixel_alpha = *pget++;
859
860
13849630
    return GX_SUCCESS;
861
}
862
863
/**************************************************************************/
864
/*                                                                        */
865
/*  FUNCTION                                               RELEASE        */
866
/*                                                                        */
867
/*    _gx_image_reader_16bit_gray_read                    PORTABLE C      */
868
/*                                                           6.1          */
869
/*  AUTHOR                                                                */
870
/*                                                                        */
871
/*    Kenneth Maxwell, Microsoft Corporation                              */
872
/*                                                                        */
873
/*  DESCRIPTION                                                           */
874
/*                                                                        */
875
/*    This function reads a pixel from input pixelmap data structure.     */
876
/*                                                                        */
877
/*  INPUT                                                                 */
878
/*                                                                        */
879
/*    image_reader                         Image reader control block     */
880
/*    index                                Row index.                     */
881
/*    pixel                                Retrieved pixel.               */
882
/*                                                                        */
883
/*  OUTPUT                                                                */
884
/*                                                                        */
885
/*    Completion Status                                                   */
886
/*                                                                        */
887
/*  CALLS                                                                 */
888
/*                                                                        */
889
/*    None                                                                */
890
/*                                                                        */
891
/*  CALLED BY                                                             */
892
/*                                                                        */
893
/*    _gx_image_reader_pixel_read_callback_set                            */
894
/*                                                                        */
895
/**************************************************************************/
896
16384
static UINT _gx_image_reader_16bit_gray_read(GX_IMAGE_READER *image_reader, INT index, GX_PIXEL *pixel)
897
{
898
GX_UBYTE *pget;
899
900
16384
    pget = (GX_UBYTE *)image_reader -> gx_image_reader_getdata;
901
16384
    pget += (index << 1);
902
903
16384
    if ((image_reader -> gx_image_reader_png_trans) &&
904
4096
        ((*pget) == (GX_UBYTE)image_reader -> gx_image_reader_png_trans[0]))
905
    {
906
2012
        pixel -> gx_pixel_alpha = 0;
907
2012
        pixel -> gx_pixel_red = 0;
908
2012
        pixel -> gx_pixel_green = 0;
909
2012
        pixel -> gx_pixel_blue = 0;
910
    }
911
    else
912
    {
913
14372
        pixel -> gx_pixel_red = *pget;
914
14372
        pixel -> gx_pixel_green = *pget;
915
14372
        pixel -> gx_pixel_blue = *pget;
916
14372
        pixel -> gx_pixel_alpha = 0xff;
917
    }
918
919
16384
    return GX_SUCCESS;
920
}
921
922
/**************************************************************************/
923
/*                                                                        */
924
/*  FUNCTION                                               RELEASE        */
925
/*                                                                        */
926
/*    _gx_image_reader_565rgb_pixel_read                  PORTABLE C      */
927
/*                                                           6.1          */
928
/*  AUTHOR                                                                */
929
/*                                                                        */
930
/*    Kenneth Maxwell, Microsoft Corporation                              */
931
/*                                                                        */
932
/*  DESCRIPTION                                                           */
933
/*                                                                        */
934
/*    This function reads a pixel from input pixelmap data structure.     */
935
/*                                                                        */
936
/*  INPUT                                                                 */
937
/*                                                                        */
938
/*    image_reader                         Image reader control block     */
939
/*    index                                Row index.                     */
940
/*    pixel                                Retrieved pixel.               */
941
/*                                                                        */
942
/*  OUTPUT                                                                */
943
/*                                                                        */
944
/*    Completion Status                                                   */
945
/*                                                                        */
946
/*  CALLS                                                                 */
947
/*                                                                        */
948
/*    None                                                                */
949
/*                                                                        */
950
/*  CALLED BY                                                             */
951
/*                                                                        */
952
/*    _gx_image_reader_pixel_read_callback_set                            */
953
/*                                                                        */
954
/**************************************************************************/
955
9296783
static UINT _gx_image_reader_565rgb_pixel_read(GX_IMAGE_READER *image_reader, INT index, GX_PIXEL *pixel)
956
{
957
USHORT   *pLine;
958
GX_UBYTE *pAlpha;
959
960
9296783
    pLine = (USHORT *)image_reader -> gx_image_reader_getdata;
961
9296783
    pLine += index;
962
963
9296783
    pixel -> gx_pixel_red = (GX_UBYTE)(((*pLine) & 0xf800) >> 8);
964
9296783
    pixel -> gx_pixel_green = (GX_UBYTE)(((*pLine) & 0x07e0) >> 3);
965
9296783
    pixel -> gx_pixel_blue = (GX_UBYTE)(((*pLine) & 0x001f) << 3);
966
967
9296783
    if (image_reader -> gx_image_reader_mode & GX_IMAGE_READER_MODE_ALPHA)
968
    {
969
1777547
        pAlpha = (GX_UBYTE *)image_reader -> gx_image_reader_getauxdata;
970
1777547
        pAlpha += index;
971
972
1777547
        pixel -> gx_pixel_alpha = (*pAlpha);
973
    }
974
    else
975
    {
976
7519236
        pixel -> gx_pixel_alpha = 0;
977
    }
978
979
9296783
    return GX_SUCCESS;
980
}
981
982
/**************************************************************************/
983
/*                                                                        */
984
/*  FUNCTION                                               RELEASE        */
985
/*                                                                        */
986
/*    _gx_image_reader_1555xrgb_pixel_read                PORTABLE C      */
987
/*                                                           6.1          */
988
/*  AUTHOR                                                                */
989
/*                                                                        */
990
/*    Kenneth Maxwell, Microsoft Corporation                              */
991
/*                                                                        */
992
/*  DESCRIPTION                                                           */
993
/*                                                                        */
994
/*    This function reads an 1555xrgb format pixel from input pixelmap    */
995
/*    data structure.                                                     */
996
/*                                                                        */
997
/*  INPUT                                                                 */
998
/*                                                                        */
999
/*    image_reader                         Image reader control block     */
1000
/*    index                                Row index.                     */
1001
/*    pixel                                Retrieved pixel.               */
1002
/*                                                                        */
1003
/*  OUTPUT                                                                */
1004
/*                                                                        */
1005
/*    Completion Status                                                   */
1006
/*                                                                        */
1007
/*  CALLS                                                                 */
1008
/*                                                                        */
1009
/*    None                                                                */
1010
/*                                                                        */
1011
/*  CALLED BY                                                             */
1012
/*                                                                        */
1013
/*    _gx_image_reader_pixel_read_callback_set                            */
1014
/*                                                                        */
1015
/**************************************************************************/
1016
2672758
static UINT _gx_image_reader_1555xrgb_pixel_read(GX_IMAGE_READER *image_reader, INT index, GX_PIXEL *pixel)
1017
{
1018
USHORT   *pLine;
1019
GX_UBYTE *pAlpha;
1020
1021
2672758
    pLine = (USHORT *)image_reader -> gx_image_reader_getdata;
1022
2672758
    pLine += index;
1023
1024
2672758
    pixel -> gx_pixel_red = (GX_UBYTE)(((*pLine) & 0x7c00) >> 7);
1025
2672758
    pixel -> gx_pixel_green = (GX_UBYTE)(((*pLine) & 0x03e0) >> 2);
1026
2672758
    pixel -> gx_pixel_blue = (GX_UBYTE)(((*pLine) & 0x001f) << 3);
1027
1028
2672758
    if (image_reader -> gx_image_reader_mode & GX_IMAGE_READER_MODE_ALPHA)
1029
    {
1030
1448126
        pAlpha = (GX_UBYTE *)image_reader -> gx_image_reader_getauxdata;
1031
1448126
        pAlpha += index;
1032
1033
1448126
        pixel -> gx_pixel_alpha = (*pAlpha);
1034
    }
1035
    else
1036
    {
1037
1224632
        pixel -> gx_pixel_alpha = 0;
1038
    }
1039
1040
2672758
    return GX_SUCCESS;
1041
}
1042
1043
/**************************************************************************/
1044
/*                                                                        */
1045
/*  FUNCTION                                               RELEASE        */
1046
/*                                                                        */
1047
/*    _gx_image_reader_4444argb_pixel_read                PORTABLE C      */
1048
/*                                                           6.1          */
1049
/*  AUTHOR                                                                */
1050
/*                                                                        */
1051
/*    Kenneth Maxwell, Microsoft Corporation                              */
1052
/*                                                                        */
1053
/*  DESCRIPTION                                                           */
1054
/*                                                                        */
1055
/*    This function reads an 4444argb format pixel from input pixelmap    */
1056
/*    data structure.                                                     */
1057
/*                                                                        */
1058
/*  INPUT                                                                 */
1059
/*                                                                        */
1060
/*    image_reader                         Image reader control block     */
1061
/*    index                                Row index.                     */
1062
/*    pixel                                Retrieved pixel.               */
1063
/*                                                                        */
1064
/*  OUTPUT                                                                */
1065
/*                                                                        */
1066
/*    Completion Status                                                   */
1067
/*                                                                        */
1068
/*  CALLS                                                                 */
1069
/*                                                                        */
1070
/*    None                                                                */
1071
/*                                                                        */
1072
/*  CALLED BY                                                             */
1073
/*                                                                        */
1074
/*    _gx_image_reader_pixel_read_callback_set                            */
1075
/*                                                                        */
1076
/**************************************************************************/
1077
1505626
static UINT _gx_image_reader_4444argb_pixel_read(GX_IMAGE_READER *image_reader, INT index, GX_PIXEL *pixel)
1078
{
1079
USHORT        color;
1080
1505626
const USHORT *data = (USHORT *)(image_reader -> gx_image_reader_getdata);
1081
1082
1505626
    color = *(data + index);
1083
1084
1505626
    pixel -> gx_pixel_alpha = (GX_UBYTE)((color & 0xf000) >> 8);
1085
1505626
    pixel -> gx_pixel_red = (GX_UBYTE)((color & 0xf00) >> 4);
1086
1505626
    pixel -> gx_pixel_green = (GX_UBYTE)(color & 0xf0);
1087
1505626
    pixel -> gx_pixel_blue = (GX_UBYTE)((color & 0xf) << 4);
1088
1089
1505626
    return GX_SUCCESS;
1090
}
1091
1092
/**************************************************************************/
1093
/*                                                                        */
1094
/*  FUNCTION                                               RELEASE        */
1095
/*                                                                        */
1096
/*    _gx_image_reader_4bit_grayscale_pixel_read          PORTABLE C      */
1097
/*                                                           6.1          */
1098
/*  AUTHOR                                                                */
1099
/*                                                                        */
1100
/*    Kenneth Maxwell, Microsoft Corporation                              */
1101
/*                                                                        */
1102
/*  DESCRIPTION                                                           */
1103
/*                                                                        */
1104
/*    This function reads an 4bit grayscale format pixel (no transparency)*/
1105
/*    from input pixelmap data structure.                                 */
1106
/*                                                                        */
1107
/*  INPUT                                                                 */
1108
/*                                                                        */
1109
/*    image_reader                         Image reader control block     */
1110
/*    index                                Row index.                     */
1111
/*    pixel                                Retrieved pixel.               */
1112
/*                                                                        */
1113
/*  OUTPUT                                                                */
1114
/*                                                                        */
1115
/*    Completion Status                                                   */
1116
/*                                                                        */
1117
/*  CALLS                                                                 */
1118
/*                                                                        */
1119
/*    None                                                                */
1120
/*                                                                        */
1121
/*  CALLED BY                                                             */
1122
/*                                                                        */
1123
/*    _gx_image_reader_pixel_read_callback_set                            */
1124
/*                                                                        */
1125
/**************************************************************************/
1126
833722
static UINT _gx_image_reader_4bit_grayscale_pixel_read(GX_IMAGE_READER *image_reader, INT index, GX_PIXEL *pixel)
1127
{
1128
GX_UBYTE color;
1129
1130
833722
    color = *(image_reader -> gx_image_reader_getdata + (index >> 1));
1131
1132
833722
    if (index & 1)
1133
    {
1134
414352
        color &= 0x0f;
1135
    }
1136
    else
1137
    {
1138
419370
        color &= 0xf0;
1139
419370
        color >>= 4;
1140
    }
1141
1142
833722
    color |= (GX_UBYTE)(color << 4);
1143
833722
    pixel -> gx_pixel_red = color;
1144
833722
    pixel -> gx_pixel_green = color;
1145
833722
    pixel -> gx_pixel_blue = color;
1146
833722
    pixel -> gx_pixel_alpha = 0xff;
1147
1148
833722
    return GX_SUCCESS;
1149
}
1150
1151
/**************************************************************************/
1152
/*                                                                        */
1153
/*  FUNCTION                                               RELEASE        */
1154
/*                                                                        */
1155
/*    _gx_image_reader_4bit_grayscale_transparent_read    PORTABLE C      */
1156
/*                                                           6.1          */
1157
/*  AUTHOR                                                                */
1158
/*                                                                        */
1159
/*    Kenneth Maxwell, Microsoft Corporation                              */
1160
/*                                                                        */
1161
/*  DESCRIPTION                                                           */
1162
/*                                                                        */
1163
/*    This function reads an 4bit grayscale format pixel                  */
1164
/*    (with transparency)from input pixelmap data structure.              */
1165
/*                                                                        */
1166
/*  INPUT                                                                 */
1167
/*                                                                        */
1168
/*    image_reader                         Image reader control block     */
1169
/*    index                                Row index.                     */
1170
/*    pixel                                Retrieved pixel.               */
1171
/*                                                                        */
1172
/*  OUTPUT                                                                */
1173
/*                                                                        */
1174
/*    Completion Status                                                   */
1175
/*                                                                        */
1176
/*  CALLS                                                                 */
1177
/*                                                                        */
1178
/*    None                                                                */
1179
/*                                                                        */
1180
/*  CALLED BY                                                             */
1181
/*                                                                        */
1182
/*    _gx_image_reader_pixel_read_callback_set                            */
1183
/*                                                                        */
1184
/**************************************************************************/
1185
588752
static UINT _gx_image_reader_4bit_grayscale_transparent_read(GX_IMAGE_READER *image_reader, INT index, GX_PIXEL *pixel)
1186
{
1187
588752
const GX_UBYTE *data = image_reader -> gx_image_reader_getdata;
1188
588752
const GX_UBYTE *auxdata = image_reader -> gx_image_reader_getauxdata;
1189
588752
INT             aux_index = (index >> 3);
1190
588752
INT             color_index = (index >> 1);
1191
588752
GX_UBYTE        color = *(data + color_index);
1192
588752
GX_UBYTE        transparency = *(auxdata + aux_index);
1193
1194
    /* Get transparent mask. */
1195
588752
    transparency = (GX_UBYTE)(transparency >> (7 - (index & 0x07)));
1196
1197
588752
    if (transparency & 0x01)
1198
    {
1199
134620
        color = 0;
1200
134620
        pixel -> gx_pixel_alpha = 0;
1201
    }
1202
    else
1203
    {
1204
454132
        if (index & 1)
1205
        {
1206
227466
            color &= 0xf;
1207
        }
1208
        else
1209
        {
1210
226666
            color &= 0xf0;
1211
226666
            color >>= 4;
1212
        }
1213
454132
        color = (GX_UBYTE)(color | color << 4);
1214
454132
        pixel -> gx_pixel_alpha = 0xff;
1215
    }
1216
1217
588752
    pixel -> gx_pixel_red = color;
1218
588752
    pixel -> gx_pixel_green = color;
1219
588752
    pixel -> gx_pixel_blue = color;
1220
1221
588752
    return GX_SUCCESS;
1222
}
1223
1224
/**************************************************************************/
1225
/*                                                                        */
1226
/*  FUNCTION                                               RELEASE        */
1227
/*                                                                        */
1228
/*    _gx_image_reader_1bpp_pixel_read                    PORTABLE C      */
1229
/*                                                           6.1          */
1230
/*  AUTHOR                                                                */
1231
/*                                                                        */
1232
/*    Kenneth Maxwell, Microsoft Corporation                              */
1233
/*                                                                        */
1234
/*  DESCRIPTION                                                           */
1235
/*                                                                        */
1236
/*    This function reads an 1bpp format pixel (no transparency) from     */
1237
/*    input pixelmap data structure.                                      */
1238
/*                                                                        */
1239
/*  INPUT                                                                 */
1240
/*                                                                        */
1241
/*    image_reader                         Image reader control block     */
1242
/*    index                                Row index.                     */
1243
/*    pixel                                Retrieved pixel.               */
1244
/*                                                                        */
1245
/*  OUTPUT                                                                */
1246
/*                                                                        */
1247
/*    Completion Status                                                   */
1248
/*                                                                        */
1249
/*  CALLS                                                                 */
1250
/*                                                                        */
1251
/*    None                                                                */
1252
/*                                                                        */
1253
/*  CALLED BY                                                             */
1254
/*                                                                        */
1255
/*    _gx_image_reader_pixel_read_callback_set                            */
1256
/*                                                                        */
1257
/**************************************************************************/
1258
617554
static UINT _gx_image_reader_1bpp_pixel_read(GX_IMAGE_READER *image_reader, INT index, GX_PIXEL *pixel)
1259
{
1260
GX_UBYTE color;
1261
1262
617554
    color = *(image_reader -> gx_image_reader_getdata + (index >> 3));
1263
1264
617554
    if (color & (0x80 >> (index & 0x07)))
1265
    {
1266
386380
        pixel -> gx_pixel_red = 0xff;
1267
386380
        pixel -> gx_pixel_green = 0xff;
1268
386380
        pixel -> gx_pixel_blue = 0xff;
1269
    }
1270
    else
1271
    {
1272
231174
        pixel -> gx_pixel_red = 0;
1273
231174
        pixel -> gx_pixel_green = 0;
1274
231174
        pixel -> gx_pixel_blue = 0;
1275
    }
1276
617554
    pixel -> gx_pixel_alpha = 0xff;
1277
1278
617554
    return GX_SUCCESS;
1279
}
1280
1281
/**************************************************************************/
1282
/*                                                                        */
1283
/*  FUNCTION                                               RELEASE        */
1284
/*                                                                        */
1285
/*    _gx_image_reader_1bpp_transparent_read              PORTABLE C      */
1286
/*                                                           6.1          */
1287
/*  AUTHOR                                                                */
1288
/*                                                                        */
1289
/*    Kenneth Maxwell, Microsoft Corporation                              */
1290
/*                                                                        */
1291
/*  DESCRIPTION                                                           */
1292
/*                                                                        */
1293
/*    This function reads an 1bpp format pixel (no transparency) from     */
1294
/*    input pixelmap data structure.                                      */
1295
/*                                                                        */
1296
/*  INPUT                                                                 */
1297
/*                                                                        */
1298
/*    image_reader                         Image reader control block     */
1299
/*    index                                Row index.                     */
1300
/*    pixel                                Retrieved pixel.               */
1301
/*                                                                        */
1302
/*  OUTPUT                                                                */
1303
/*                                                                        */
1304
/*    Completion Status                                                   */
1305
/*                                                                        */
1306
/*  CALLS                                                                 */
1307
/*                                                                        */
1308
/*    None                                                                */
1309
/*                                                                        */
1310
/*  CALLED BY                                                             */
1311
/*                                                                        */
1312
/*    _gx_image_reader_pixel_read_callback_set                            */
1313
/*                                                                        */
1314
/**************************************************************************/
1315
648696
static UINT _gx_image_reader_1bpp_transparent_read(GX_IMAGE_READER *image_reader, INT index, GX_PIXEL *pixel)
1316
{
1317
GX_UBYTE color;
1318
1319
648696
    color = *(image_reader -> gx_image_reader_getdata + (index >> 2));
1320
1321
648696
    if (color & (0x40 >> ((index & 0x03) << 1)))
1322
    {
1323
495628
        if (color & (0x80 >> ((index & 0x03) << 1)))
1324
        {
1325
224414
            pixel -> gx_pixel_red = 0xff;
1326
224414
            pixel -> gx_pixel_green = 0xff;
1327
224414
            pixel -> gx_pixel_blue = 0xff;
1328
        }
1329
        else
1330
        {
1331
271214
            pixel -> gx_pixel_red = 0;
1332
271214
            pixel -> gx_pixel_green = 0;
1333
271214
            pixel -> gx_pixel_blue = 0;
1334
        }
1335
495628
        pixel -> gx_pixel_alpha = 0xff;
1336
    }
1337
    else
1338
    {
1339
153068
        pixel -> gx_pixel_red = 0;
1340
153068
        pixel -> gx_pixel_green = 0;
1341
153068
        pixel -> gx_pixel_blue = 0;
1342
153068
        pixel -> gx_pixel_alpha = 0;
1343
    }
1344
1345
648696
    return GX_SUCCESS;
1346
}
1347
1348
1349
/**************************************************************************/
1350
/*                                                                        */
1351
/*  FUNCTION                                               RELEASE        */
1352
/*                                                                        */
1353
/*    _gx_image_reader_pixel_read_callback_set            PORTABLE C      */
1354
/*                                                           6.1          */
1355
/*  AUTHOR                                                                */
1356
/*                                                                        */
1357
/*    Kenneth Maxwell, Microsoft Corporation                              */
1358
/*                                                                        */
1359
/*  DESCRIPTION                                                           */
1360
/*                                                                        */
1361
/*    This function sets pixel read callback of the image reader.         */
1362
/*                                                                        */
1363
/*  INPUT                                                                 */
1364
/*                                                                        */
1365
/*    image_reader                          Image reader control block    */
1366
/*    inmap                                 Input pixelmap                */
1367
/*                                                                        */
1368
/*  OUTPUT                                                                */
1369
/*                                                                        */
1370
/*    Completion Status                                                   */
1371
/*                                                                        */
1372
/*  CALLS                                                                 */
1373
/*                                                                        */
1374
/*    _gx_image_reader_1bit_pixel_read      Read 1bit internal format     */
1375
/*                                            pixel                       */
1376
/*    _gx_image_reader_2bit_pixel_read      Read 2bit internal format     */
1377
/*                                            pixel                       */
1378
/*    _gx_image_reader_4bit_pixel_read      Read 4bit internal format     */
1379
/*                                            pixel                       */
1380
/*    _gx_image_reader_8bit_pixel_read      Read 8bit internal format     */
1381
/*                                            pixel                       */
1382
/*    _gx_image_reader_16bit_gray_read      Read 16bit internal format    */
1383
/*                                            pixel                       */
1384
/*    _gx_image_reader_16bit_gray_alpha_read                              */
1385
/*                                          Read 16bit gray:alpha internal*/
1386
/*                                            format pixel                */
1387
/*    _gx_image_reader_32bit_gray_alpha_read                              */
1388
/*                                          Read 32bit gray:alpha internal*/
1389
/*                                            format pixel                */
1390
/*    _gx_image_reader_24bit_pixel_read     Read 24bit internal format    */
1391
/*                                            pixel                       */
1392
/*    _gx_image_reader_32bit_pixel_read     Read 32bit internal format    */
1393
/*                                            pixel                       */
1394
/*    _gx_image_reader_48bit_pixel_read     Read 48bit internal format    */
1395
/*                                            pixel                       */
1396
/*    _gx_image_reader_64bit_pixel_read     Read 64bit internal format    */
1397
/*                                            pixel                       */
1398
/*    _gx_image_reader_32argb_pixel_read    Read 32argb guix format pixel */
1399
/*                                            pixel                       */
1400
/*    _gx_image_reader_565rgb_pixel_read    Read 565rgb guix format pixel */
1401
/*    _gx_image_reader_1555xrgb_pixel_read  Read 1555xrgb guix format     */
1402
/*                                            pixel                       */
1403
/*    _gx_image_reader_8bit_palette_pixel_read                            */
1404
/*                                          Read 8bit palette guix format */
1405
/*                                            pixel                       */
1406
/*    _gx_image_reader_8bit_alpha_read      Read 8bit alphamap guix format*/
1407
/*                                            pixel                       */
1408
/*    _gx_image_reader_4444argb_pixel_read  Read 4444argb guix format     */
1409
/*                                            pixel                       */
1410
/*    _gx_image_reader_4bit_grayscale_transparent_read                    */
1411
/*                                          Read 4bit grayscale guix      */
1412
/*                                            format pixel with           */
1413
/*                                            transparency                */
1414
/*    _gx_image_reader_4bit_grayscale_pixel_read                          */
1415
/*                                          Read 4bit grayscale guix      */
1416
/*                                            format pxiel                */
1417
/*    _gx_image_reader_1bpp_transparent_read                              */
1418
/*                                          Read 1bpp guix format pixel   */
1419
/*                                            with transparency           */
1420
/*    _gx_image_reader_1bpp_pixel_read      Read 1bpp guix format pixel   */
1421
/*                                                                        */
1422
/*  CALLED BY                                                             */
1423
/*                                                                        */
1424
/*    gx_image_reader_colorspace_convert                                  */
1425
/*                                                                        */
1426
/**************************************************************************/
1427
1176
UINT _gx_image_reader_pixel_read_callback_set(GX_IMAGE_READER *image_reader, GX_PIXELMAP *inmap)
1428
{
1429
1430





1176
    switch (inmap -> gx_pixelmap_format)
1431
    {
1432
13
    case GX_IMAGE_FORMAT_1BPP:
1433
13
        if (inmap -> gx_pixelmap_aux_data)
1434
        {
1435
6
            image_reader -> gx_image_reader_png_palette = (GX_COLOR *)inmap -> gx_pixelmap_aux_data;
1436
6
            image_reader -> gx_image_reader_png_palette_size = inmap -> gx_pixelmap_aux_data_size / sizeof(GX_COLOR);
1437
        }
1438
13
        image_reader -> gx_image_reader_pixel_read = _gx_image_reader_1bit_pixel_read;
1439
13
        image_reader -> gx_image_reader_input_stride = (UINT)(inmap -> gx_pixelmap_width >> 3);
1440
13
        break;
1441
1442
12
    case GX_IMAGE_FORMAT_2BPP:
1443
12
        if (inmap -> gx_pixelmap_aux_data)
1444
        {
1445
6
            image_reader -> gx_image_reader_png_palette = (GX_COLOR *)inmap -> gx_pixelmap_aux_data;
1446
6
            image_reader -> gx_image_reader_png_palette_size = inmap -> gx_pixelmap_aux_data_size / sizeof(GX_COLOR);
1447
        }
1448
12
        image_reader -> gx_image_reader_pixel_read = _gx_image_reader_2bit_pixel_read;
1449
12
        image_reader -> gx_image_reader_input_stride = (UINT)(inmap -> gx_pixelmap_width >> 2);
1450
12
        break;
1451
1452
18
    case GX_IMAGE_FORMAT_4BPP:
1453
18
        if (inmap -> gx_pixelmap_aux_data)
1454
        {
1455
10
            image_reader -> gx_image_reader_png_palette = (GX_COLOR *)inmap -> gx_pixelmap_aux_data;
1456
10
            image_reader -> gx_image_reader_png_palette_size = inmap -> gx_pixelmap_aux_data_size / sizeof(GX_COLOR);
1457
        }
1458
1459
18
        image_reader -> gx_image_reader_pixel_read = _gx_image_reader_4bit_pixel_read;
1460
18
        image_reader -> gx_image_reader_input_stride = (UINT)(inmap -> gx_pixelmap_width >> 1);
1461
18
        break;
1462
1463
46
    case GX_IMAGE_FORMAT_8BPP:
1464
46
        if (inmap -> gx_pixelmap_aux_data)
1465
        {
1466
30
            image_reader -> gx_image_reader_png_palette = (GX_COLOR *)inmap -> gx_pixelmap_aux_data;
1467
30
            image_reader -> gx_image_reader_png_palette_size = inmap -> gx_pixelmap_aux_data_size / sizeof(GX_COLOR);
1468
        }
1469
1470
46
        image_reader -> gx_image_reader_pixel_read = _gx_image_reader_8bit_pixel_read;
1471
46
        image_reader -> gx_image_reader_input_stride = (UINT)inmap -> gx_pixelmap_width;
1472
46
        break;
1473
1474
16
    case GX_IMAGE_FORMAT_16BPP_GRAY:
1475
16
        image_reader -> gx_image_reader_pixel_read = _gx_image_reader_16bit_gray_read;
1476
16
        image_reader -> gx_image_reader_input_stride = (UINT)(inmap -> gx_pixelmap_width << 1);
1477
16
        break;
1478
1479
8
    case GX_IMAGE_FORMAT_16BPP_GRAY_ALPHA: /* Internal format: gray: alpha byte stream. */
1480
8
        image_reader -> gx_image_reader_pixel_read = _gx_image_reader_16bit_gray_alpha_read;
1481
8
        image_reader -> gx_image_reader_input_stride = (UINT)(inmap -> gx_pixelmap_width << 1);
1482
8
        break;
1483
1484
4
    case GX_IMAGE_FORMAT_32BPP_GRAY_ALPHA: /* Internal format: gray: alpha byte stream. */
1485
4
        image_reader -> gx_image_reader_pixel_read = _gx_image_reader_32bit_gray_alpha_read;
1486
4
        image_reader -> gx_image_reader_input_stride = (UINT)(inmap -> gx_pixelmap_width << 2);
1487
4
        break;
1488
1489
318
    case GX_IMAGE_FORMAT_24BPP: /* Internal format: r:g:b byte stream. */
1490
318
        image_reader -> gx_image_reader_pixel_read = _gx_image_reader_24bit_pixel_read;
1491
318
        image_reader -> gx_image_reader_input_stride = (UINT)(inmap -> gx_pixelmap_width * 3);
1492
318
        break;
1493
1494
321
    case GX_IMAGE_FORMAT_32BPP: /* Internal format: r:g:b:a byte strem. */
1495
321
        image_reader -> gx_image_reader_pixel_read = _gx_image_reader_32bit_pixel_read;
1496
321
        image_reader -> gx_image_reader_input_stride = (UINT)(inmap -> gx_pixelmap_width << 2);
1497
321
        break;
1498
1499
34
    case GX_IMAGE_FORMAT_48BPP:
1500
34
        image_reader -> gx_image_reader_pixel_read = _gx_image_reader_48bit_pixel_read;
1501
34
        image_reader -> gx_image_reader_input_stride = (UINT)(inmap -> gx_pixelmap_width * 6);
1502
34
        break;
1503
1504
4
    case GX_IMAGE_FORMAT_64BPP:
1505
4
        image_reader -> gx_image_reader_pixel_read = _gx_image_reader_64bit_pixel_read;
1506
4
        image_reader -> gx_image_reader_input_stride = (UINT)(inmap -> gx_pixelmap_width << 3);
1507
4
        break;
1508
1509
37
    case GX_COLOR_FORMAT_32ARGB:
1510
    case GX_COLOR_FORMAT_24XRGB:
1511
37
        image_reader -> gx_image_reader_pixel_read = _gx_image_reader_32argb_pixel_read;
1512
37
        image_reader -> gx_image_reader_input_stride = (UINT)(inmap -> gx_pixelmap_width << 2);
1513
37
        break;
1514
1515
63
    case GX_COLOR_FORMAT_565RGB:
1516
63
        image_reader -> gx_image_reader_pixel_read = _gx_image_reader_565rgb_pixel_read;
1517
63
        image_reader -> gx_image_reader_input_stride = (UINT)(inmap -> gx_pixelmap_width << 1);
1518
63
        break;
1519
1520
32
    case GX_COLOR_FORMAT_1555XRGB:
1521
32
        image_reader -> gx_image_reader_pixel_read = _gx_image_reader_1555xrgb_pixel_read;
1522
32
        image_reader -> gx_image_reader_input_stride = (UINT)(inmap -> gx_pixelmap_width << 1);
1523
32
        break;
1524
1525
56
    case GX_COLOR_FORMAT_8BIT_PALETTE:
1526
56
        image_reader -> gx_image_reader_pixel_read = _gx_image_reader_8bit_palette_pixel_read;
1527
56
        image_reader -> gx_image_reader_input_stride = (UINT)inmap -> gx_pixelmap_width;
1528
56
        break;
1529
1530
124
    case GX_COLOR_FORMAT_8BIT_ALPHAMAP:
1531
124
        image_reader -> gx_image_reader_pixel_read = _gx_image_reader_8bit_alpha_read;
1532
124
        image_reader -> gx_image_reader_input_stride = (UINT)inmap -> gx_pixelmap_width;
1533
124
        break;
1534
1535
20
    case GX_COLOR_FORMAT_4444ARGB:
1536
20
        image_reader -> gx_image_reader_pixel_read = _gx_image_reader_4444argb_pixel_read;
1537
20
        image_reader -> gx_image_reader_input_stride = (UINT)(inmap -> gx_pixelmap_width << 1);
1538
20
        break;
1539
1540
24
    case GX_COLOR_FORMAT_4BIT_GRAY:
1541
24
        if (inmap -> gx_pixelmap_flags & GX_PIXELMAP_TRANSPARENT)
1542
        {
1543
8
            image_reader -> gx_image_reader_pixel_read = _gx_image_reader_4bit_grayscale_transparent_read;
1544
        }
1545
        else
1546
        {
1547
16
            image_reader -> gx_image_reader_pixel_read = _gx_image_reader_4bit_grayscale_pixel_read;
1548
        }
1549
24
        image_reader -> gx_image_reader_input_stride = (UINT)((inmap -> gx_pixelmap_width + 1) >> 1);
1550
24
        break;
1551
1552
25
    case GX_COLOR_FORMAT_MONOCHROME:
1553
25
        if (inmap -> gx_pixelmap_flags & GX_PIXELMAP_TRANSPARENT)
1554
        {
1555
12
            image_reader -> gx_image_reader_pixel_read = _gx_image_reader_1bpp_transparent_read;
1556
12
            image_reader -> gx_image_reader_input_stride = (UINT)((inmap -> gx_pixelmap_width + 3) >> 2);
1557
        }
1558
        else
1559
        {
1560
13
            image_reader -> gx_image_reader_pixel_read = _gx_image_reader_1bpp_pixel_read;
1561
13
            image_reader -> gx_image_reader_input_stride = (UINT)((inmap -> gx_pixelmap_width + 7) >> 3);
1562
        }
1563
25
        break;
1564
1565
1
    default:
1566
1
        return GX_NOT_SUPPORTED;
1567
    }
1568
1569
1175
    image_reader -> gx_image_reader_getdata = (GX_UBYTE *)inmap -> gx_pixelmap_data;
1570
1175
    image_reader -> gx_image_reader_getauxdata = (GX_UBYTE *)inmap -> gx_pixelmap_aux_data;
1571
1572
1175
    return GX_SUCCESS;
1573
}
1574
#endif
1575