···3131#include "lcd.h"
3232#include <lib/pluginlib_bmp.h>
3333#include "tinf.h"
3434-#include "png.h"
3434+#include "../imageviewer.h"
3535#include "png_decoder.h"
3636#include "bmp.h"
37373838/* decoder context struct */
3939static LodePNG_Decoder decoder;
40404141-/* my memory pool (from the mp3 buffer) */
4242-static char print[128]; /* use a common snprintf() buffer */
4141+static char print[32]; /* use a common snprintf() buffer */
43424443/* decompressed image in the possible sizes (1,2,4,8), wasting the other */
4545-static fb_data *disp[9];
4646-static fb_data *disp_buf;
4444+static unsigned char *disp[9];
4545+static unsigned char *disp_buf;
47464847#if defined(HAVE_LCD_COLOR)
4948#define resize_bitmap smooth_resize_bitmap
···6463void draw_image_rect(struct image_info *info,
6564 int x, int y, int width, int height)
6665{
6767- fb_data **pdisp = (fb_data**)info->data;
6666+ unsigned char **pdisp = (unsigned char **)info->data;
68676968#ifdef HAVE_LCD_COLOR
7070- rb->lcd_bitmap_part(*pdisp, info->x + x, info->y + y,
6969+ rb->lcd_bitmap_part((fb_data *)*pdisp, info->x + x, info->y + y,
7170 STRIDE(SCREEN_MAIN, info->width, info->height),
7271 x + MAX(0, (LCD_WIDTH-info->width)/2),
7372 y + MAX(0, (LCD_HEIGHT-info->height)/2),
7473 width, height);
7574#else
7676- mylcd_ub_gray_bitmap_part((const unsigned char*)*pdisp,
7575+ mylcd_ub_gray_bitmap_part(*pdisp,
7776 info->x + x, info->y + y, info->width,
7877 x + MAX(0, (LCD_WIDTH-info->width)/2),
7978 y + MAX(0, (LCD_HEIGHT-info->height)/2),
···102101 int w, h; /* used to center output */
103102 LodePNG_Decoder *p_decoder = &decoder;
104103105105- unsigned char *memory, *memory_max;
106106- static size_t memory_size, file_size;
107107- static unsigned char *image;
104104+ unsigned char *memory, *memory_max, *image;
105105+ size_t memory_size, file_size;
108106109107 /* cleanup */
110108 memset(&disp, 0, sizeof(disp));
···239237 info->x_size = p_decoder->infoPng.width;
240238 info->y_size = p_decoder->infoPng.height;
241239242242- disp_buf = (fb_data *)(p_decoder->buf + p_decoder->native_img_size);
243243- disp_buf = (fb_data *)ALIGN_UP((uintptr_t)disp_buf,4);
244244- *buf_size = memory_max - (unsigned char*)disp_buf;
240240+ p_decoder->native_img_size = (p_decoder->native_img_size + 3) & ~3;
241241+ disp_buf = p_decoder->buf + p_decoder->native_img_size;
242242+ *buf_size = memory_max - disp_buf;
245243246244 return PLUGIN_OK;
247245}
248246249247int get_image(struct image_info *info, int ds)
250248{
251251- fb_data **p_disp = &disp[ds]; /* short cut */
249249+ unsigned char **p_disp = &disp[ds]; /* short cut */
252250 LodePNG_Decoder *p_decoder = &decoder;
253251254252 info->width = p_decoder->infoPng.width / ds;
···270268 }
271269 struct bitmap bmp_src, bmp_dst;
272270273273- int size = info->width * info->height;
271271+ int size = img_mem(ds);
274272275275- if ((unsigned char *)(disp_buf + size) >= p_decoder->buf + p_decoder->buf_size) {
273273+ if (disp_buf + size >= p_decoder->buf + p_decoder->buf_size) {
276274 /* have to discard the current */
277275 int i;
278276 for (i=1; i<=8; i++)
279277 disp[i] = NULL; /* invalidate all bitmaps */
280278281279 /* start again from the beginning of the buffer */
282282- disp_buf = (fb_data *)(p_decoder->buf + p_decoder->native_img_size);
283283- disp_buf = (fb_data *)ALIGN_UP((uintptr_t)disp_buf,4);
280280+ disp_buf = p_decoder->buf + p_decoder->native_img_size;
284281 }
285282286283 *p_disp = disp_buf;
287287-#ifdef USEGSLIB
288288- disp_buf = (fb_data *)((unsigned char *)disp_buf + size);
289289-#else
290284 disp_buf += size;
291291-#endif
292285293286 bmp_src.width = p_decoder->infoPng.width;
294287 bmp_src.height = p_decoder->infoPng.height;
295295- bmp_src.data = (unsigned char *)p_decoder->buf;
288288+ bmp_src.data = p_decoder->buf;
296289297290 bmp_dst.width = info->width;
298291 bmp_dst.height = info->height;
299299- bmp_dst.data = (unsigned char *)*p_disp;
292292+ bmp_dst.data = *p_disp;
300293#ifdef HAVE_ADJUSTABLE_CPU_FREQ
301294 rb->cpu_boost(true);
302295 resize_bitmap(&bmp_src, &bmp_dst);
···305298 resize_bitmap(&bmp_src, &bmp_dst);
306299#endif /*HAVE_ADJUSTABLE_CPU_FREQ*/
307300 } else {
308308- *p_disp = (fb_data *)p_decoder->buf;
301301+ *p_disp = p_decoder->buf;
309302 }
310303311304 return PLUGIN_OK;
-25
apps/plugins/imageviewer/png/png.h
···11-/***************************************************************************
22- * __________ __ ___.
33- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
44- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77- * \/ \/ \/ \/ \/
88- * $Id$id $
99- *
1010- * Copyright (C) 2009 by Christophe Gouiran <bechris13250 -at- gmail -dot- com>
1111- *
1212- * Based on lodepng, a lightweight png decoder/encoder
1313- * (c) 2005-2008 Lode Vandevenne
1414- *
1515- * This program is free software; you can redistribute it and/or
1616- * modify it under the terms of the GNU General Public License
1717- * as published by the Free Software Foundation; either version 2
1818- * of the License, or (at your option) any later version.
1919- *
2020- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
2121- * KIND, either express or implied.
2222- *
2323- ****************************************************************************/
2424-2525-#include "../imageviewer.h"
+515-517
apps/plugins/imageviewer/png/png_decoder.c
···199199 */
200200 if (bit)
201201 bitstream[(*bitpointer) >> 3] |= (bit << (7 - ((*bitpointer) & 0x7)));
202202-202202+203203 (*bitpointer)++;
204204}
205205···408408#ifdef HAVE_LCD_COLOR
409409 struct uint8_rgb *line_buf = (struct uint8_rgb *)(out + w * h * FB_DATA_SZ);
410410#else
411411- uint8_t *line_buf = (unsigned char *)(out + w * h * FB_DATA_SZ);
411411+ uint8_t *line_buf = (unsigned char *)(out + w * h);
412412#endif
413413414414 struct bitmap bm = {
···428428 const struct custom_format *cformat = &format_native;
429429#endif
430430431431-void (*output_row_8)(uint32_t, void*, struct scaler_context*) = cformat->output_row_8;
431431+ void (*output_row_8)(uint32_t, void*, struct scaler_context*) = cformat->output_row_8;
432432433433#ifdef HAVE_LCD_COLOR
434434-struct uint8_rgb *pixel;
434434+ struct uint8_rgb *pixel;
435435#else
436436-unsigned char *pixel;
436436+ unsigned char *pixel;
437437#endif
438438439439#ifdef HAVE_LCD_COLOR
440440- if (infoIn->color.bitDepth == 8)
440440+ if (infoIn->color.bitDepth == 8)
441441+ {
442442+ switch (infoIn->color.colorType)
441443 {
442442- switch (infoIn->color.colorType)
443443- {
444444- case PNG_COLORTYPE_GREY: /*greyscale color*/
445445- i = 0;
446446- for (y = 0 ; y < h ; y++) {
447447- /* reset line buf */
448448- pixel = line_buf;
444444+ case PNG_COLORTYPE_GREY: /*greyscale color*/
445445+ i = 0;
446446+ for (y = 0 ; y < h ; y++) {
447447+ /* reset line buf */
448448+ pixel = line_buf;
449449450450- for (x = 0; x < w ; x++) {
451451- value = in[i++];
452452- if (infoIn->color.key_defined)
453453- if ( (uint8_t)value == (uint8_t)infoIn->color.key_r )
454454- value = infoIn->background_r; /* full transparent */
450450+ for (x = 0; x < w ; x++) {
451451+ value = in[i++];
452452+ if (infoIn->color.key_defined)
453453+ if ( (uint8_t)value == (uint8_t)infoIn->color.key_r )
454454+ value = infoIn->background_r; /* full transparent */
455455456456- pixel->red = (uint8_t)value;
457457- pixel->green = (uint8_t)value;
458458- pixel->blue = (uint8_t)value;
459459- pixel++;
460460- }
461461- output_row_8(y,(void *)line_buf,&ctx);
456456+ pixel->red = (uint8_t)value;
457457+ pixel->green = (uint8_t)value;
458458+ pixel->blue = (uint8_t)value;
459459+ pixel++;
462460 }
463463- break;
464464- case PNG_COLORTYPE_RGB: /*RGB color*/
465465- i = 0;
466466- for (y = 0 ; y < h ; y++) {
467467- pixel = line_buf;
468468- for (x = 0 ; x < w ; x++) {
469469- j = 3*i++;
461461+ output_row_8(y,(void *)line_buf,&ctx);
462462+ }
463463+ break;
464464+ case PNG_COLORTYPE_RGB: /*RGB color*/
465465+ i = 0;
466466+ for (y = 0 ; y < h ; y++) {
467467+ pixel = line_buf;
468468+ for (x = 0 ; x < w ; x++) {
469469+ j = 3*i++;
470470471471- /* tRNs & bKGD */
472472- if (infoIn->color.key_defined &&
473473- in[j] == (uint8_t)infoIn->color.key_r &&
474474- in[j + 1] == (uint8_t)infoIn->color.key_g &&
475475- in[j + 2] == (uint8_t)infoIn->color.key_b)
476476- {
477477- pixel->red = (uint8_t)infoIn->background_r;
478478- pixel->green = (uint8_t)infoIn->background_g;
479479- pixel->blue = (uint8_t)infoIn->background_b;
480480- }
481481- else
482482- {
483483- pixel->red = in[j];
484484- pixel->green = in[j + 1];
485485- pixel->blue = in[j + 2];
486486- }
487487- pixel++;
471471+ /* tRNs & bKGD */
472472+ if (infoIn->color.key_defined &&
473473+ in[j] == (uint8_t)infoIn->color.key_r &&
474474+ in[j + 1] == (uint8_t)infoIn->color.key_g &&
475475+ in[j + 2] == (uint8_t)infoIn->color.key_b)
476476+ {
477477+ pixel->red = (uint8_t)infoIn->background_r;
478478+ pixel->green = (uint8_t)infoIn->background_g;
479479+ pixel->blue = (uint8_t)infoIn->background_b;
488480 }
489489- output_row_8(y,(void *)line_buf,&ctx);
481481+ else
482482+ {
483483+ pixel->red = in[j];
484484+ pixel->green = in[j + 1];
485485+ pixel->blue = in[j + 2];
486486+ }
487487+ pixel++;
490488 }
491491- break;
492492- case PNG_COLORTYPE_PALETTE: /*indexed color (palette)*/
493493- i = 0;
494494- for (y = 0 ; y < h ; y++) {
495495- /* reset line buf */
496496- pixel = line_buf;
497497- for (x = 0 ; x < w ; x++) {
498498- if (in[i] >= infoIn->color.palettesize)
499499- {
500500- decoder->error = 46;
501501- return;
502502- }
489489+ output_row_8(y,(void *)line_buf,&ctx);
490490+ }
491491+ break;
492492+ case PNG_COLORTYPE_PALETTE: /*indexed color (palette)*/
493493+ i = 0;
494494+ for (y = 0 ; y < h ; y++) {
495495+ /* reset line buf */
496496+ pixel = line_buf;
497497+ for (x = 0 ; x < w ; x++) {
498498+ if (in[i] >= infoIn->color.palettesize)
499499+ {
500500+ decoder->error = 46;
501501+ return;
502502+ }
503503504504- j = in[i++]<<2;
505505- alpha = infoIn->color.palette[j + 3];
506506- alpha_complement = (256 - alpha);
504504+ j = in[i++]<<2;
505505+ alpha = infoIn->color.palette[j + 3];
506506+ alpha_complement = (256 - alpha);
507507508508- /* tRNS and bKGD */
509509- pixel->red = (infoIn->color.palette[j] * alpha +
510510- alpha_complement*infoIn->background_r)>>8;
511511- pixel->green = (infoIn->color.palette[j + 1] * alpha +
512512- alpha_complement*infoIn->background_g)>>8;
513513- pixel->blue = (infoIn->color.palette[j + 2] * alpha +
514514- alpha_complement*infoIn->background_b)>>8;
515515- pixel++;
516516- }
517517- output_row_8(y,(void *)(line_buf),&ctx);
508508+ /* tRNS and bKGD */
509509+ pixel->red = (infoIn->color.palette[j] * alpha +
510510+ alpha_complement*infoIn->background_r)>>8;
511511+ pixel->green = (infoIn->color.palette[j + 1] * alpha +
512512+ alpha_complement*infoIn->background_g)>>8;
513513+ pixel->blue = (infoIn->color.palette[j + 2] * alpha +
514514+ alpha_complement*infoIn->background_b)>>8;
515515+ pixel++;
518516 }
519519- break;
520520- case PNG_COLORTYPE_GREYA: /*greyscale with alpha*/
521521- i = 0;
522522- for (y = 0 ; y < h ; y++) {
523523- pixel = line_buf;
524524- for (x = 0 ; x < w ; x++) {
525525- alpha = in[(i << 1) + 1];
526526- alpha_complement = (256 - alpha)*infoIn->background_r;
527527- value = (alpha * in[i++ << 1] + alpha_complement)>>8;
528528- pixel->red = (uint8_t)(value);
529529- pixel->green = (uint8_t)value;
530530- pixel->blue = (uint8_t)value;
531531- pixel++;
532532- }
533533- output_row_8(y,(void *)line_buf,&ctx);
517517+ output_row_8(y,(void *)(line_buf),&ctx);
518518+ }
519519+ break;
520520+ case PNG_COLORTYPE_GREYA: /*greyscale with alpha*/
521521+ i = 0;
522522+ for (y = 0 ; y < h ; y++) {
523523+ pixel = line_buf;
524524+ for (x = 0 ; x < w ; x++) {
525525+ alpha = in[(i << 1) + 1];
526526+ alpha_complement = (256 - alpha)*infoIn->background_r;
527527+ value = (alpha * in[i++ << 1] + alpha_complement)>>8;
528528+ pixel->red = (uint8_t)(value);
529529+ pixel->green = (uint8_t)value;
530530+ pixel->blue = (uint8_t)value;
531531+ pixel++;
534532 }
535535- break;
536536- case PNG_COLORTYPE_RGBA: /*RGB with alpha*/
537537- i = 0;
538538- for (y = 0 ; y < h ; y++) {
539539- pixel = line_buf;
540540- for (x = 0 ; x < w ; x++) {
541541- j = i++ << 2;
542542- alpha = in[j + 3];
543543- alpha_complement = (256 - alpha);
544544- pixel->red = (in[j] * alpha +
545545- alpha_complement*infoIn->background_r)>>8;
546546- pixel->green = (in[j + 1] * alpha +
547547- alpha_complement*infoIn->background_g)>>8;
548548- pixel->blue = (in[j + 2] * alpha +
549549- alpha_complement*infoIn->background_b)>>8;
550550- pixel++;
551551- }
552552- output_row_8(y,(void *)line_buf,&ctx);
533533+ output_row_8(y,(void *)line_buf,&ctx);
534534+ }
535535+ break;
536536+ case PNG_COLORTYPE_RGBA: /*RGB with alpha*/
537537+ i = 0;
538538+ for (y = 0 ; y < h ; y++) {
539539+ pixel = line_buf;
540540+ for (x = 0 ; x < w ; x++) {
541541+ j = i++ << 2;
542542+ alpha = in[j + 3];
543543+ alpha_complement = (256 - alpha);
544544+ pixel->red = (in[j] * alpha +
545545+ alpha_complement*infoIn->background_r)>>8;
546546+ pixel->green = (in[j + 1] * alpha +
547547+ alpha_complement*infoIn->background_g)>>8;
548548+ pixel->blue = (in[j + 2] * alpha +
549549+ alpha_complement*infoIn->background_b)>>8;
550550+ pixel++;
553551 }
554554- break;
555555- default:
556556- break;
552552+ output_row_8(y,(void *)line_buf,&ctx);
557553 }
554554+ break;
555555+ default:
556556+ break;
558557 }
559559- else if (infoIn->color.bitDepth == 16)
558558+ }
559559+ else if (infoIn->color.bitDepth == 16)
560560+ {
561561+ switch (infoIn->color.colorType)
560562 {
561561- switch (infoIn->color.colorType)
562562- {
563563- case PNG_COLORTYPE_GREY: /*greyscale color*/
564564- i = 0;
565565- for (y = 0 ; y < h ; y++) {
566566- pixel = line_buf;
567567- for (x = 0 ; x < w ; x++) {
568568- value = (in[i<<1]<<8)|in[(i << 1) + 1];
569569- i++;
563563+ case PNG_COLORTYPE_GREY: /*greyscale color*/
564564+ i = 0;
565565+ for (y = 0 ; y < h ; y++) {
566566+ pixel = line_buf;
567567+ for (x = 0 ; x < w ; x++) {
568568+ value = (in[i<<1]<<8)|in[(i << 1) + 1];
569569+ i++;
570570571571- /* tRNS and bKGD */
572572- if (infoIn->color.key_defined &&
573573- value == infoIn->color.key_r)
574574- value = infoIn->background_r<<8;
575575-576576- pixel->red =
577577- pixel->green =
578578- pixel->blue = (uint8_t)(value>>8);
579579- pixel++;
580580- }
581581- output_row_8(y,(void *)line_buf,&ctx);
571571+ /* tRNS and bKGD */
572572+ if (infoIn->color.key_defined &&
573573+ value == infoIn->color.key_r)
574574+ value = infoIn->background_r<<8;
575575+576576+ pixel->red =
577577+ pixel->green =
578578+ pixel->blue = (uint8_t)(value>>8);
579579+ pixel++;
582580 }
583583- break;
584584- case PNG_COLORTYPE_RGB: /*RGB color*/
585585- i = 0;
586586- for (y = 0 ; y < h ; y++) {
587587- pixel = line_buf;
588588- for (x = 0 ; x < w ; x++) {
589589- j = 6 * i++;
581581+ output_row_8(y,(void *)line_buf,&ctx);
582582+ }
583583+ break;
584584+ case PNG_COLORTYPE_RGB: /*RGB color*/
585585+ i = 0;
586586+ for (y = 0 ; y < h ; y++) {
587587+ pixel = line_buf;
588588+ for (x = 0 ; x < w ; x++) {
589589+ j = 6 * i++;
590590591591- /* tRNS and bKGD */
592592- if (infoIn->color.key_defined &&
593593- ((uint16_t)(in[j]<<8|in[j + 1]) ==
594594- infoIn->color.key_r) &&
595595- ((uint16_t)(in[j + 2]<<8|in[j + 3]) ==
596596- infoIn->color.key_g) &&
597597- ((uint16_t)(in[j + 4]<<8|in[j + 5]) ==
598598- infoIn->color.key_b))
599599- {
600600- pixel->red = (uint8_t)infoIn->background_r;
601601- pixel->green = (uint8_t)infoIn->background_g;
602602- pixel->blue = (uint8_t)infoIn->background_b;
603603- }
604604- else
605605- {
606606- pixel->red = in[j];
607607- pixel->green = in[j + 2];
608608- pixel->blue = in[j + 4];
609609- }
610610- pixel++;
591591+ /* tRNS and bKGD */
592592+ if (infoIn->color.key_defined &&
593593+ ((uint16_t)(in[j]<<8|in[j + 1]) ==
594594+ infoIn->color.key_r) &&
595595+ ((uint16_t)(in[j + 2]<<8|in[j + 3]) ==
596596+ infoIn->color.key_g) &&
597597+ ((uint16_t)(in[j + 4]<<8|in[j + 5]) ==
598598+ infoIn->color.key_b))
599599+ {
600600+ pixel->red = (uint8_t)infoIn->background_r;
601601+ pixel->green = (uint8_t)infoIn->background_g;
602602+ pixel->blue = (uint8_t)infoIn->background_b;
603603+ }
604604+ else
605605+ {
606606+ pixel->red = in[j];
607607+ pixel->green = in[j + 2];
608608+ pixel->blue = in[j + 4];
611609 }
612612- output_row_8(y,(void *)line_buf,&ctx);
610610+ pixel++;
613611 }
614614- break;
615615- case PNG_COLORTYPE_GREYA: /*greyscale with alpha*/
616616- i = 0;
617617- for (y = 0 ; y < h ; y++) {
618618- pixel = line_buf;
619619- for (x = 0 ; x < w ; x++) {
620620- alpha = in[(i << 2) + 2];
621621- alpha_complement = (256-alpha)*infoIn->background_r;
622622- value = (in[i++ << 2] * alpha + alpha_complement)>>8;
623623- pixel->red = (uint8_t)value;
624624- pixel->green = (uint8_t)value;
625625- pixel->blue = (uint8_t)value;
626626- pixel++;
627627- }
628628- output_row_8(y,(void *)line_buf,&ctx);
612612+ output_row_8(y,(void *)line_buf,&ctx);
613613+ }
614614+ break;
615615+ case PNG_COLORTYPE_GREYA: /*greyscale with alpha*/
616616+ i = 0;
617617+ for (y = 0 ; y < h ; y++) {
618618+ pixel = line_buf;
619619+ for (x = 0 ; x < w ; x++) {
620620+ alpha = in[(i << 2) + 2];
621621+ alpha_complement = (256-alpha)*infoIn->background_r;
622622+ value = (in[i++ << 2] * alpha + alpha_complement)>>8;
623623+ pixel->red = (uint8_t)value;
624624+ pixel->green = (uint8_t)value;
625625+ pixel->blue = (uint8_t)value;
626626+ pixel++;
629627 }
630630- break;
631631- case PNG_COLORTYPE_RGBA: /*RGB with alpha*/
632632- i = 0;
633633- for (y = 0 ; y < h ; y++) {
634634- pixel = line_buf;
635635- for (x = 0 ; x < w ; x++) {
636636- j = i++ << 3;
637637- alpha = in[j + 6];
638638- alpha_complement = (256-alpha);
639639- pixel->red = (in[j] * alpha +
640640- alpha_complement*infoIn->background_r)>>8;
641641- pixel->green = (in[j + 2] * alpha +
642642- alpha_complement*infoIn->background_g)>>8;
643643- pixel->blue = (in[j + 4] * alpha +
644644- alpha_complement*infoIn->background_b)>>8;
645645- pixel++;
646646- }
647647- output_row_8(y,(void *)line_buf,&ctx);
628628+ output_row_8(y,(void *)line_buf,&ctx);
629629+ }
630630+ break;
631631+ case PNG_COLORTYPE_RGBA: /*RGB with alpha*/
632632+ i = 0;
633633+ for (y = 0 ; y < h ; y++) {
634634+ pixel = line_buf;
635635+ for (x = 0 ; x < w ; x++) {
636636+ j = i++ << 3;
637637+ alpha = in[j + 6];
638638+ alpha_complement = (256-alpha);
639639+ pixel->red = (in[j] * alpha +
640640+ alpha_complement*infoIn->background_r)>>8;
641641+ pixel->green = (in[j + 2] * alpha +
642642+ alpha_complement*infoIn->background_g)>>8;
643643+ pixel->blue = (in[j + 4] * alpha +
644644+ alpha_complement*infoIn->background_b)>>8;
645645+ pixel++;
648646 }
649649- break;
650650- default:
651651- break;
647647+ output_row_8(y,(void *)line_buf,&ctx);
652648 }
649649+ break;
650650+ default:
651651+ break;
653652 }
654654- else /*infoIn->bitDepth is less than 8 bit per channel*/
653653+ }
654654+ else /*infoIn->bitDepth is less than 8 bit per channel*/
655655+ {
656656+ switch (infoIn->color.colorType)
655657 {
656656- switch (infoIn->color.colorType)
657657- {
658658- case PNG_COLORTYPE_GREY: /*greyscale color*/
659659- i = 0;
660660- for (y = 0 ; y < h ; y++) {
661661- pixel = line_buf;
662662- for (x = 0 ; x < w ; x++) {
663663- value = readBitsFromReversedStream(&bp, in, infoIn->color.bitDepth);
664664-665665- /* tRNS and bKGD */
666666- if (infoIn->color.key_defined)
667667- if ( value == infoIn->color.key_r )
668668- value = infoIn->background_r; /* full transparent */
658658+ case PNG_COLORTYPE_GREY: /*greyscale color*/
659659+ i = 0;
660660+ for (y = 0 ; y < h ; y++) {
661661+ pixel = line_buf;
662662+ for (x = 0 ; x < w ; x++) {
663663+ value = readBitsFromReversedStream(&bp, in, infoIn->color.bitDepth);
664664+665665+ /* tRNS and bKGD */
666666+ if (infoIn->color.key_defined)
667667+ if ( value == infoIn->color.key_r )
668668+ value = infoIn->background_r; /* full transparent */
669669670670- /* scale value from 0 to 255 */
671671- value = (value * 255) / ((1 << infoIn->color.bitDepth) - 1);
670670+ /* scale value from 0 to 255 */
671671+ value = (value * 255) / ((1 << infoIn->color.bitDepth) - 1);
672672673673- pixel->red = (uint8_t)value;
674674- pixel->green = (uint8_t)value;
675675- pixel->blue = (uint8_t)value;
676676- pixel++;
677677- }
678678- output_row_8(y,(void *)line_buf,&ctx);
673673+ pixel->red = (uint8_t)value;
674674+ pixel->green = (uint8_t)value;
675675+ pixel->blue = (uint8_t)value;
676676+ pixel++;
679677 }
680680- break;
681681- case PNG_COLORTYPE_PALETTE: /*indexed color (palette)*/
682682- i = 0;
683683- for (y = 0 ; y < h ; y++) {
684684- pixel = line_buf;
685685- for (x = 0 ; x < w ; x++) {
686686- value = readBitsFromReversedStream(&bp, in, infoIn->color.bitDepth);
687687- if (value >= infoIn->color.palettesize)
688688- {
689689- decoder->error = 47;
690690- return;
691691- }
678678+ output_row_8(y,(void *)line_buf,&ctx);
679679+ }
680680+ break;
681681+ case PNG_COLORTYPE_PALETTE: /*indexed color (palette)*/
682682+ i = 0;
683683+ for (y = 0 ; y < h ; y++) {
684684+ pixel = line_buf;
685685+ for (x = 0 ; x < w ; x++) {
686686+ value = readBitsFromReversedStream(&bp, in, infoIn->color.bitDepth);
687687+ if (value >= infoIn->color.palettesize)
688688+ {
689689+ decoder->error = 47;
690690+ return;
691691+ }
692692+693693+ j = value << 2;
692694693693- j = value << 2;
694694-695695- /* tRNS and bKGD */
696696- alpha = infoIn->color.palette[j + 3];
697697- alpha_complement = (256 - alpha);
698698- pixel->red = (alpha * infoIn->color.palette[j] +
699699- alpha_complement*infoIn->background_r)>>8;
700700- pixel->green = (alpha * infoIn->color.palette[j + 1] +
701701- alpha_complement*infoIn->background_g)>>8;
702702- pixel->blue = (alpha * infoIn->color.palette[j + 2] +
703703- alpha_complement*infoIn->background_b)>>8;
704704- pixel++;
705705- }
706706- output_row_8(y,(void *)line_buf,&ctx);
695695+ /* tRNS and bKGD */
696696+ alpha = infoIn->color.palette[j + 3];
697697+ alpha_complement = (256 - alpha);
698698+ pixel->red = (alpha * infoIn->color.palette[j] +
699699+ alpha_complement*infoIn->background_r)>>8;
700700+ pixel->green = (alpha * infoIn->color.palette[j + 1] +
701701+ alpha_complement*infoIn->background_g)>>8;
702702+ pixel->blue = (alpha * infoIn->color.palette[j + 2] +
703703+ alpha_complement*infoIn->background_b)>>8;
704704+ pixel++;
707705 }
708708- break;
709709- default:
710710- break;
706706+ output_row_8(y,(void *)line_buf,&ctx);
711707 }
708708+ break;
709709+ default:
710710+ break;
712711 }
712712+ }
713713#else /* greyscale targets */
714714-struct uint8_rgb px_rgb; /* for rgb(a) -> greyscale conversion */
715715-uint8_t background_grey; /* for rgb background -> greyscale background */
714714+ struct uint8_rgb px_rgb; /* for rgb(a) -> greyscale conversion */
715715+ uint8_t background_grey; /* for rgb background -> greyscale background */
716716717717- if (infoIn->color.bitDepth == 8)
717717+ if (infoIn->color.bitDepth == 8)
718718+ {
719719+ switch (infoIn->color.colorType)
718720 {
719719- switch (infoIn->color.colorType)
720720- {
721721- case PNG_COLORTYPE_GREY: /*greyscale color*/
722722- i = 0;
723723- for (y = 0 ; y < h ; y++) {
724724- pixel = line_buf;
725725- for (x = 0 ; x < w ; x++ ) {
726726- value = in[i++];
721721+ case PNG_COLORTYPE_GREY: /*greyscale color*/
722722+ i = 0;
723723+ for (y = 0 ; y < h ; y++) {
724724+ pixel = line_buf;
725725+ for (x = 0 ; x < w ; x++ ) {
726726+ value = in[i++];
727727728728- /* transparent color defined in tRNS chunk */
729729- if (infoIn->color.key_defined)
730730- if ( (uint8_t)value == (uint8_t)infoIn->color.key_r )
731731- value = infoIn->background_r;
728728+ /* transparent color defined in tRNS chunk */
729729+ if (infoIn->color.key_defined)
730730+ if ( (uint8_t)value == (uint8_t)infoIn->color.key_r )
731731+ value = infoIn->background_r;
732732733733- *pixel++ = (uint8_t)value;
734734- }
735735- output_row_8(y,(void *)line_buf,&ctx);
733733+ *pixel++ = (uint8_t)value;
736734 }
737737- break;
738738- case PNG_COLORTYPE_RGB: /*RGB color*/
739739- /* convert background rgb color to greyscale */
740740- px_rgb.red = infoIn->background_r;
741741- px_rgb.green = infoIn->background_g;
742742- px_rgb.blue = infoIn->background_b;
743743- background_grey = brightness(px_rgb);
735735+ output_row_8(y,(void *)line_buf,&ctx);
736736+ }
737737+ break;
738738+ case PNG_COLORTYPE_RGB: /*RGB color*/
739739+ /* convert background rgb color to greyscale */
740740+ px_rgb.red = infoIn->background_r;
741741+ px_rgb.green = infoIn->background_g;
742742+ px_rgb.blue = infoIn->background_b;
743743+ background_grey = brightness(px_rgb);
744744745745- i = 0;
746746- for (y = 0 ; y < h ; y++) {
747747- pixel = line_buf;
748748- for (x = 0 ; x < w ; x++) {
749749- j = 3*i++;
745745+ i = 0;
746746+ for (y = 0 ; y < h ; y++) {
747747+ pixel = line_buf;
748748+ for (x = 0 ; x < w ; x++) {
749749+ j = 3*i++;
750750751751- /* tRNs & bKGD */
752752- if (infoIn->color.key_defined &&
753753- in[j] == (uint8_t)infoIn->color.key_r &&
754754- in[j + 1] == (uint8_t)infoIn->color.key_g &&
755755- in[j + 2] == (uint8_t)infoIn->color.key_b)
756756- {
757757- *pixel = background_grey;
758758- }
759759- else
760760- {
761761- /* rgb -> greyscale */
762762- px_rgb.red = in[j];
763763- px_rgb.green = in[j + 1];
764764- px_rgb.blue = in[j + 2];
765765- *pixel = brightness(px_rgb);
766766- }
767767- pixel++;
751751+ /* tRNs & bKGD */
752752+ if (infoIn->color.key_defined &&
753753+ in[j] == (uint8_t)infoIn->color.key_r &&
754754+ in[j + 1] == (uint8_t)infoIn->color.key_g &&
755755+ in[j + 2] == (uint8_t)infoIn->color.key_b)
756756+ {
757757+ *pixel = background_grey;
758758+ }
759759+ else
760760+ {
761761+ /* rgb -> greyscale */
762762+ px_rgb.red = in[j];
763763+ px_rgb.green = in[j + 1];
764764+ px_rgb.blue = in[j + 2];
765765+ *pixel = brightness(px_rgb);
766766+ }
767767+ pixel++;
768768769769- }
770770- output_row_8(y,(void *)line_buf,&ctx);
771769 }
772772- break;
773773- case PNG_COLORTYPE_PALETTE: /*indexed color (palette)*/
774774- i = 0;
775775- /* calculate grey value of rgb background */
776776- px_rgb.red = infoIn->background_r;
777777- px_rgb.green = infoIn->background_g;
778778- px_rgb.blue = infoIn->background_b;
779779- background_grey = brightness(px_rgb);
770770+ output_row_8(y,(void *)line_buf,&ctx);
771771+ }
772772+ break;
773773+ case PNG_COLORTYPE_PALETTE: /*indexed color (palette)*/
774774+ i = 0;
775775+ /* calculate grey value of rgb background */
776776+ px_rgb.red = infoIn->background_r;
777777+ px_rgb.green = infoIn->background_g;
778778+ px_rgb.blue = infoIn->background_b;
779779+ background_grey = brightness(px_rgb);
780780781781- for (y = 0 ; y < h ; y++) {
782782- /* reset line buf */
783783- pixel = line_buf;
784784- for (x = 0 ; x < w ; x++) {
785785- if (in[i] >= infoIn->color.palettesize)
786786- {
787787- decoder->error = 46;
788788- return;
789789- }
781781+ for (y = 0 ; y < h ; y++) {
782782+ /* reset line buf */
783783+ pixel = line_buf;
784784+ for (x = 0 ; x < w ; x++) {
785785+ if (in[i] >= infoIn->color.palettesize)
786786+ {
787787+ decoder->error = 46;
788788+ return;
789789+ }
790790791791- j = in[i++] << 2;
792792- alpha = infoIn->color.palette[j + 3];
793793- alpha_complement = (256 - alpha);
791791+ j = in[i++] << 2;
792792+ alpha = infoIn->color.palette[j + 3];
793793+ alpha_complement = (256 - alpha);
794794795795- /* tRNS and bKGD */
796796- px_rgb.red = (alpha * infoIn->color.palette[j] +
797797- alpha_complement*background_grey)>>8;
798798- px_rgb.green = (alpha * infoIn->color.palette[j + 1] +
799799- alpha_complement*background_grey)>>8;
800800- px_rgb.blue = (alpha * infoIn->color.palette[j + 2] +
801801- alpha_complement*background_grey)>>8;
795795+ /* tRNS and bKGD */
796796+ px_rgb.red = (alpha * infoIn->color.palette[j] +
797797+ alpha_complement*background_grey)>>8;
798798+ px_rgb.green = (alpha * infoIn->color.palette[j + 1] +
799799+ alpha_complement*background_grey)>>8;
800800+ px_rgb.blue = (alpha * infoIn->color.palette[j + 2] +
801801+ alpha_complement*background_grey)>>8;
802802803803- *pixel++ = brightness(px_rgb);
804804- }
805805- output_row_8(y,(void *)(line_buf),&ctx);
803803+ *pixel++ = brightness(px_rgb);
806804 }
807807- break;
808808- case PNG_COLORTYPE_GREYA: /*greyscale with alpha*/
809809- i = 0;
810810- for (y = 0 ; y < h ; y++) {
811811- pixel = line_buf;
812812- for (x = 0 ; x < w ; x++) {
813813- alpha = in[(i << 1) + 1];
814814- alpha_complement = ((256 - alpha)*infoIn->background_r);
815815- *pixel++ = (alpha * in[i++ << 1] + alpha_complement)>>8;
816816- }
817817- output_row_8(y,(void *)line_buf,&ctx);
805805+ output_row_8(y,(void *)(line_buf),&ctx);
806806+ }
807807+ break;
808808+ case PNG_COLORTYPE_GREYA: /*greyscale with alpha*/
809809+ i = 0;
810810+ for (y = 0 ; y < h ; y++) {
811811+ pixel = line_buf;
812812+ for (x = 0 ; x < w ; x++) {
813813+ alpha = in[(i << 1) + 1];
814814+ alpha_complement = ((256 - alpha)*infoIn->background_r);
815815+ *pixel++ = (alpha * in[i++ << 1] + alpha_complement)>>8;
818816 }
819819- break;
820820- case PNG_COLORTYPE_RGBA: /*RGB with alpha*/
821821- px_rgb.red = infoIn->background_r;
822822- px_rgb.green = infoIn->background_g;
823823- px_rgb.blue = infoIn->background_b;
824824- background_grey = brightness(px_rgb);
817817+ output_row_8(y,(void *)line_buf,&ctx);
818818+ }
819819+ break;
820820+ case PNG_COLORTYPE_RGBA: /*RGB with alpha*/
821821+ px_rgb.red = infoIn->background_r;
822822+ px_rgb.green = infoIn->background_g;
823823+ px_rgb.blue = infoIn->background_b;
824824+ background_grey = brightness(px_rgb);
825825826826- i = 0;
827827- for (y = 0 ; y < h ; y++) {
828828- pixel = line_buf;
829829- for (x = 0 ; x < w ; x++) {
830830- j = i++ << 2;
831831- alpha = in[j + 3];
832832- alpha_complement = ((256 - alpha)*background_grey);
826826+ i = 0;
827827+ for (y = 0 ; y < h ; y++) {
828828+ pixel = line_buf;
829829+ for (x = 0 ; x < w ; x++) {
830830+ j = i++ << 2;
831831+ alpha = in[j + 3];
832832+ alpha_complement = ((256 - alpha)*background_grey);
833833834834- px_rgb.red = in[j];
835835- px_rgb.green = in[j + 1];
836836- px_rgb.blue = in[j + 2];
837837- *pixel++ = (alpha * brightness(px_rgb) +
838838- alpha_complement)>>8;
839839- }
840840- output_row_8(y,(void *)line_buf,&ctx);
834834+ px_rgb.red = in[j];
835835+ px_rgb.green = in[j + 1];
836836+ px_rgb.blue = in[j + 2];
837837+ *pixel++ = (alpha * brightness(px_rgb) +
838838+ alpha_complement)>>8;
841839 }
842842- break;
843843- default:
844844- break;
840840+ output_row_8(y,(void *)line_buf,&ctx);
845841 }
842842+ break;
843843+ default:
844844+ break;
846845 }
847847- else if (infoIn->color.bitDepth == 16)
846846+ }
847847+ else if (infoIn->color.bitDepth == 16)
848848+ {
849849+ switch (infoIn->color.colorType)
848850 {
849849- switch (infoIn->color.colorType)
850850- {
851851- case PNG_COLORTYPE_GREY: /*greyscale color*/
852852- i = 0;
853853- for (y = 0 ; y < h ; y++) {
854854- pixel = line_buf;
855855- for (x = 0 ; x < w ; x++) {
856856- /* specification states that we have to compare
857857- * colors for simple transparency in 16bits
858858- * even if we scale down to 8bits later
859859- */
860860- value = in[i<<1]<<8|in[(i << 1) + 1];
861861- i++;
862862-863863- /* tRNS and bKGD */
864864- if (infoIn->color.key_defined &&
865865- value == infoIn->color.key_r)
866866- value = infoIn->background_r<<8;
851851+ case PNG_COLORTYPE_GREY: /*greyscale color*/
852852+ i = 0;
853853+ for (y = 0 ; y < h ; y++) {
854854+ pixel = line_buf;
855855+ for (x = 0 ; x < w ; x++) {
856856+ /* specification states that we have to compare
857857+ * colors for simple transparency in 16bits
858858+ * even if we scale down to 8bits later
859859+ */
860860+ value = in[i<<1]<<8|in[(i << 1) + 1];
861861+ i++;
867862868868- /* we take upper 8bits */
869869- *pixel++ = (uint8_t)(value>>8);
870870- }
863863+ /* tRNS and bKGD */
864864+ if (infoIn->color.key_defined &&
865865+ value == infoIn->color.key_r)
866866+ value = infoIn->background_r<<8;
871867872872- output_row_8(y,(void *)line_buf,&ctx);
868868+ /* we take upper 8bits */
869869+ *pixel++ = (uint8_t)(value>>8);
873870 }
874874- break;
875875- case PNG_COLORTYPE_RGB: /*RGB color*/
876876- i = 0;
877877- px_rgb.red = infoIn->background_r;
878878- px_rgb.green = infoIn->background_g;
879879- px_rgb.blue = infoIn->background_b;
880880- background_grey = brightness(px_rgb);
881871882882- for (y = 0 ; y < h ; y++) {
883883- pixel = line_buf;
884884- for (x = 0 ; x < w ; x++) {
885885- j = 6 * i++;
872872+ output_row_8(y,(void *)line_buf,&ctx);
873873+ }
874874+ break;
875875+ case PNG_COLORTYPE_RGB: /*RGB color*/
876876+ i = 0;
877877+ px_rgb.red = infoIn->background_r;
878878+ px_rgb.green = infoIn->background_g;
879879+ px_rgb.blue = infoIn->background_b;
880880+ background_grey = brightness(px_rgb);
886881887887- /* tRNS and bKGD */
888888- if (infoIn->color.key_defined &&
889889- (uint16_t)(in[j]<<8|in[j + 1]) ==
890890- infoIn->color.key_r &&
891891- (uint16_t)(in[j + 2]<<8|in[j + 3]) ==
892892- infoIn->color.key_g &&
893893- (uint16_t)(in[j + 4]<<8|in[j + 5]) ==
894894- infoIn->color.key_b)
895895- {
896896- *pixel = background_grey;
897897- }
898898- else
899899- {
900900- /* we take only upper byte of 16bit value */
901901- px_rgb.red = in[j];
902902- px_rgb.green = in[j + 2];
903903- px_rgb.blue = in[j + 4];
904904- *pixel = brightness(px_rgb);
905905- }
906906- pixel++;
882882+ for (y = 0 ; y < h ; y++) {
883883+ pixel = line_buf;
884884+ for (x = 0 ; x < w ; x++) {
885885+ j = 6 * i++;
886886+887887+ /* tRNS and bKGD */
888888+ if (infoIn->color.key_defined &&
889889+ (uint16_t)(in[j]<<8|in[j + 1]) ==
890890+ infoIn->color.key_r &&
891891+ (uint16_t)(in[j + 2]<<8|in[j + 3]) ==
892892+ infoIn->color.key_g &&
893893+ (uint16_t)(in[j + 4]<<8|in[j + 5]) ==
894894+ infoIn->color.key_b)
895895+ {
896896+ *pixel = background_grey;
907897 }
908908- output_row_8(y,(void *)line_buf,&ctx);
909909- }
910910- break;
911911- case PNG_COLORTYPE_GREYA: /*greyscale with alpha*/
912912- i = 0;
913913- for (y = 0 ; y < h ; y++) {
914914- pixel = line_buf;
915915- for (x = 0 ; x < w ; x++) {
916916- alpha = in[(i << 2) + 2];
917917- alpha_complement = (256 - alpha)*infoIn->background_r;
918918- *pixel++ = (alpha * in[i++ << 2] + alpha_complement)>>8;
919919- }
920920- output_row_8(y,(void *)line_buf,&ctx);
921921- }
922922- break;
923923- case PNG_COLORTYPE_RGBA: /*RGB with alpha*/
924924- px_rgb.red = infoIn->background_r;
925925- px_rgb.green = infoIn->background_g;
926926- px_rgb.blue = infoIn->background_b;
927927- background_grey = brightness(px_rgb);
928928-929929- i = 0;
930930- for (y = 0 ; y < h ; y++) {
931931- pixel = line_buf;
932932- for (x = 0 ; x < w ; x++) {
933933- j = i++ << 3;
934934- alpha = in[j + 6];
935935- alpha_complement = (256 - alpha)*background_grey;
898898+ else
899899+ {
900900+ /* we take only upper byte of 16bit value */
936901 px_rgb.red = in[j];
937902 px_rgb.green = in[j + 2];
938903 px_rgb.blue = in[j + 4];
939939- *pixel++ = (alpha * brightness(px_rgb) + alpha_complement)>>8;
904904+ *pixel = brightness(px_rgb);
940905 }
941941- output_row_8(y,(void *)line_buf,&ctx);
906906+ pixel++;
942907 }
943943- break;
944944- default:
945945- break;
908908+ output_row_8(y,(void *)line_buf,&ctx);
946909 }
910910+ break;
911911+ case PNG_COLORTYPE_GREYA: /*greyscale with alpha*/
912912+ i = 0;
913913+ for (y = 0 ; y < h ; y++) {
914914+ pixel = line_buf;
915915+ for (x = 0 ; x < w ; x++) {
916916+ alpha = in[(i << 2) + 2];
917917+ alpha_complement = (256 - alpha)*infoIn->background_r;
918918+ *pixel++ = (alpha * in[i++ << 2] + alpha_complement)>>8;
919919+ }
920920+ output_row_8(y,(void *)line_buf,&ctx);
921921+ }
922922+ break;
923923+ case PNG_COLORTYPE_RGBA: /*RGB with alpha*/
924924+ px_rgb.red = infoIn->background_r;
925925+ px_rgb.green = infoIn->background_g;
926926+ px_rgb.blue = infoIn->background_b;
927927+ background_grey = brightness(px_rgb);
928928+929929+ i = 0;
930930+ for (y = 0 ; y < h ; y++) {
931931+ pixel = line_buf;
932932+ for (x = 0 ; x < w ; x++) {
933933+ j = i++ << 3;
934934+ alpha = in[j + 6];
935935+ alpha_complement = (256 - alpha)*background_grey;
936936+ px_rgb.red = in[j];
937937+ px_rgb.green = in[j + 2];
938938+ px_rgb.blue = in[j + 4];
939939+ *pixel++ = (alpha * brightness(px_rgb) + alpha_complement)>>8;
940940+ }
941941+ output_row_8(y,(void *)line_buf,&ctx);
942942+ }
943943+ break;
944944+ default:
945945+ break;
947946 }
948948- else /*infoIn->bitDepth is less than 8 bit per channel*/
947947+ }
948948+ else /*infoIn->bitDepth is less than 8 bit per channel*/
949949+ {
950950+ switch (infoIn->color.colorType)
949951 {
950950- switch (infoIn->color.colorType)
951951- {
952952- case PNG_COLORTYPE_GREY: /*greyscale color*/
953953- i = 0;
954954- for (y = 0 ; y < h ; y++) {
955955- pixel = line_buf;
956956- for (x = 0 ; x < w ; x++) {
957957- value = readBitsFromReversedStream(&bp, in, infoIn->color.bitDepth);
952952+ case PNG_COLORTYPE_GREY: /*greyscale color*/
953953+ i = 0;
954954+ for (y = 0 ; y < h ; y++) {
955955+ pixel = line_buf;
956956+ for (x = 0 ; x < w ; x++) {
957957+ value = readBitsFromReversedStream(&bp, in, infoIn->color.bitDepth);
958958+959959+ /* tRNS and bKGD */
960960+ if (infoIn->color.key_defined)
961961+ if ( value == infoIn->color.key_r )
962962+ value = infoIn->background_r; /* full transparent */
958963959959- /* tRNS and bKGD */
960960- if (infoIn->color.key_defined)
961961- if ( value == infoIn->color.key_r )
962962- value = infoIn->background_r; /* full transparent */
964964+ /*scale value from 0 to 255*/
965965+ value = (value * 255) / ((1 << infoIn->color.bitDepth) - 1);
963966964964- /*scale value from 0 to 255*/
965965- value = (value * 255) / ((1 << infoIn->color.bitDepth) - 1);
966966-967967- *pixel++ = (unsigned char)value;
968968- }
969969- output_row_8(y,(void *)line_buf,&ctx);
967967+ *pixel++ = (unsigned char)value;
970968 }
971971- break;
972972- case PNG_COLORTYPE_PALETTE: /*indexed color (palette)*/
973973- i = 0;
974974- px_rgb.red = infoIn->background_r;
975975- px_rgb.green = infoIn->background_g;
976976- px_rgb.blue = infoIn->background_b;
977977- uint8_t background_grey = brightness(px_rgb);
969969+ output_row_8(y,(void *)line_buf,&ctx);
970970+ }
971971+ break;
972972+ case PNG_COLORTYPE_PALETTE: /*indexed color (palette)*/
973973+ i = 0;
974974+ px_rgb.red = infoIn->background_r;
975975+ px_rgb.green = infoIn->background_g;
976976+ px_rgb.blue = infoIn->background_b;
977977+ uint8_t background_grey = brightness(px_rgb);
978978979979- for (y = 0 ; y < h ; y++) {
980980- pixel = line_buf;
981981- for (x = 0 ; x < w ; x++) {
982982- value = readBitsFromReversedStream(&bp, in, infoIn->color.bitDepth);
983983- if (value >= infoIn->color.palettesize)
984984- {
985985- decoder->error = 47;
986986- return;
987987- }
979979+ for (y = 0 ; y < h ; y++) {
980980+ pixel = line_buf;
981981+ for (x = 0 ; x < w ; x++) {
982982+ value = readBitsFromReversedStream(&bp, in, infoIn->color.bitDepth);
983983+ if (value >= infoIn->color.palettesize)
984984+ {
985985+ decoder->error = 47;
986986+ return;
987987+ }
988988989989- j = value << 2;
989989+ j = value << 2;
990990991991- /* tRNS and bKGD */
992992- alpha = infoIn->color.palette[j + 3];
993993- alpha_complement = (256 - alpha) * background_grey;
991991+ /* tRNS and bKGD */
992992+ alpha = infoIn->color.palette[j + 3];
993993+ alpha_complement = (256 - alpha) * background_grey;
994994995995- px_rgb.red = (alpha * infoIn->color.palette[j] +
996996- alpha_complement)>>8;
997997- px_rgb.green = (alpha * infoIn->color.palette[j + 1] +
998998- alpha_complement)>>8;
999999- px_rgb.blue = (alpha * infoIn->color.palette[j + 2] +
10001000- alpha_complement)>>8;
10011001- *pixel++ = brightness(px_rgb);
10021002- }
10031003- output_row_8(y,(void *)line_buf,&ctx);
995995+ px_rgb.red = (alpha * infoIn->color.palette[j] +
996996+ alpha_complement)>>8;
997997+ px_rgb.green = (alpha * infoIn->color.palette[j + 1] +
998998+ alpha_complement)>>8;
999999+ px_rgb.blue = (alpha * infoIn->color.palette[j + 2] +
10001000+ alpha_complement)>>8;
10011001+ *pixel++ = brightness(px_rgb);
10041002 }
10051005- break;
10061006- default:
10071007- break;
10031003+ output_row_8(y,(void *)line_buf,&ctx);
10081004 }
10051005+ break;
10061006+ default:
10071007+ break;
10091008 }
10091009+ }
10101010#endif
10111011}
10121012···10971097 * disjoint.
10981098 */
1099109911001100-/* storage space for cached portion of scanline */
11011101-unsigned char cache[512+16];
11001100+ /* storage space for cached portion of scanline */
11011101+ unsigned char cache[512+16];
1102110211031103-/* ptr to second element of the cache */
11041104-unsigned char *cache_1 = cache + bytewidth;
11051105-unsigned char *p_cache = cache + 256 + 8; /* half way */
11061106-unsigned char *p_cache_1 = p_cache + bytewidth;
11031103+ /* ptr to second element of the cache */
11041104+ unsigned char *cache_1 = cache + bytewidth;
11051105+ unsigned char *p_cache = cache + 256 + 8; /* half way */
11061106+ unsigned char *p_cache_1 = p_cache + bytewidth;
1107110711081108 size_t i;
11091109 switch (filterType)
···11921192 memcpy(recon, cache, length);
11931193 }
11941194 }
11951195- else
11951195+ else
11961196 /* for(i = 0; i < length; i++) recon[i] = scanline[i]; */
11971197 memcpy(recon, scanline, length * sizeof(uint8_t));
11981198 break;
···15191519 /* note that this function assumes the out buffer
15201520 * is completely 0, use setBitOfReversedStream
15211521 * otherwise*/
15221522- setBitOfReversedStream0(&obp, out, bit);
15221522+ setBitOfReversedStream0(&obp, out, bit);
15231523 }
15241524 }
15251525 }
···18321832 }
18331833 decoder->infoPng.background_r =
18341834 decoder->infoPng.color.palette[(data[0]<<2)];
18351835-18351835+18361836 decoder->infoPng.background_g =
18371837 decoder->infoPng.color.palette[(data[0]<<2) | 1];
18381838···18801880 */
18811881 decoder->error = 69;
18821882 break;
18831883- }
18831883+ }
18841884 unknown = true;
18851885 }
18861886···20072007 decoder->error = 29;
20082008 return;
20092009 }
20102010-20102010+20112011 /* read the values given in the header */
20122012 decoder->infoPng.width = in[16]<<24|in[17]<<16|in[18]<<8|in[19];
20132013 decoder->infoPng.height = in[20]<<24|in[21]<<16|in[22]<<8|in[23];
···20802080 /* one line more as temp buffer for conversion */
20812081#ifdef HAVE_LCD_COLOR
20822082 decoder->native_img_size = decoder->infoPng.width *
20832083- (decoder->infoPng.height)*FB_DATA_SZ;
20832083+ decoder->infoPng.height * FB_DATA_SZ;
20842084 line_buf_size = decoder->infoPng.width * sizeof(struct uint8_rgb);
20852085#else
20862086 decoder->native_img_size = decoder->infoPng.width *
···21342134 {
21352135 /* calculate 'corrected' image size */
21362136#ifdef HAVE_LCD_COLOR
21372137- c_native_img_size = dim_dst.width *
21382138- (dim_dst.height)*FB_DATA_SZ;
21372137+ c_native_img_size = dim_dst.width * dim_dst.height * FB_DATA_SZ;
21392138#else
21402140- c_native_img_size = dim_dst.width *
21412141- dim_dst.height;
21392139+ c_native_img_size = dim_dst.width * dim_dst.height;
21422140#endif
21432141 /* check memory constraints
21442142 * do the correction only if there is enough
···21652163 decoder->infoPng.width = img_dst.width;
21662164 decoder->infoPng.height = img_dst.height;
21672165 decoder->native_img_size = c_native_img_size;
21682168-21662166+21692167 /* copy back corrected image to the begining of the buffer */
21702168 memcpy(img_src.data, img_dst.data, decoder->native_img_size);
21712169 }
21722170 }
21732173-21742171#endif /* (LCD_PIXEL_ASPECT_HEIGHT != 1 || LCD_PIXEL_ASPECT_WIDTH != 1) */
21752175-time = *rb->current_tick - time;
21762176-if (pf_progress) pf_progress(100, 100);
21722172+21732173+ time = *rb->current_tick - time;
21742174+ if (pf_progress) pf_progress(100, 100);
21772175}
2178217621792177void LodePNG_Decoder_init(LodePNG_Decoder* decoder,