Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

reduce casts between "unsinged char *" and "fb_data *". make calculation precise. maintain spaces.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28428 a1c6a512-1295-4272-9138-f99709370657

+536 -570
+19 -26
apps/plugins/imageviewer/png/png.c
··· 31 31 #include "lcd.h" 32 32 #include <lib/pluginlib_bmp.h> 33 33 #include "tinf.h" 34 - #include "png.h" 34 + #include "../imageviewer.h" 35 35 #include "png_decoder.h" 36 36 #include "bmp.h" 37 37 38 38 /* decoder context struct */ 39 39 static LodePNG_Decoder decoder; 40 40 41 - /* my memory pool (from the mp3 buffer) */ 42 - static char print[128]; /* use a common snprintf() buffer */ 41 + static char print[32]; /* use a common snprintf() buffer */ 43 42 44 43 /* decompressed image in the possible sizes (1,2,4,8), wasting the other */ 45 - static fb_data *disp[9]; 46 - static fb_data *disp_buf; 44 + static unsigned char *disp[9]; 45 + static unsigned char *disp_buf; 47 46 48 47 #if defined(HAVE_LCD_COLOR) 49 48 #define resize_bitmap smooth_resize_bitmap ··· 64 63 void draw_image_rect(struct image_info *info, 65 64 int x, int y, int width, int height) 66 65 { 67 - fb_data **pdisp = (fb_data**)info->data; 66 + unsigned char **pdisp = (unsigned char **)info->data; 68 67 69 68 #ifdef HAVE_LCD_COLOR 70 - rb->lcd_bitmap_part(*pdisp, info->x + x, info->y + y, 69 + rb->lcd_bitmap_part((fb_data *)*pdisp, info->x + x, info->y + y, 71 70 STRIDE(SCREEN_MAIN, info->width, info->height), 72 71 x + MAX(0, (LCD_WIDTH-info->width)/2), 73 72 y + MAX(0, (LCD_HEIGHT-info->height)/2), 74 73 width, height); 75 74 #else 76 - mylcd_ub_gray_bitmap_part((const unsigned char*)*pdisp, 75 + mylcd_ub_gray_bitmap_part(*pdisp, 77 76 info->x + x, info->y + y, info->width, 78 77 x + MAX(0, (LCD_WIDTH-info->width)/2), 79 78 y + MAX(0, (LCD_HEIGHT-info->height)/2), ··· 102 101 int w, h; /* used to center output */ 103 102 LodePNG_Decoder *p_decoder = &decoder; 104 103 105 - unsigned char *memory, *memory_max; 106 - static size_t memory_size, file_size; 107 - static unsigned char *image; 104 + unsigned char *memory, *memory_max, *image; 105 + size_t memory_size, file_size; 108 106 109 107 /* cleanup */ 110 108 memset(&disp, 0, sizeof(disp)); ··· 239 237 info->x_size = p_decoder->infoPng.width; 240 238 info->y_size = p_decoder->infoPng.height; 241 239 242 - disp_buf = (fb_data *)(p_decoder->buf + p_decoder->native_img_size); 243 - disp_buf = (fb_data *)ALIGN_UP((uintptr_t)disp_buf,4); 244 - *buf_size = memory_max - (unsigned char*)disp_buf; 240 + p_decoder->native_img_size = (p_decoder->native_img_size + 3) & ~3; 241 + disp_buf = p_decoder->buf + p_decoder->native_img_size; 242 + *buf_size = memory_max - disp_buf; 245 243 246 244 return PLUGIN_OK; 247 245 } 248 246 249 247 int get_image(struct image_info *info, int ds) 250 248 { 251 - fb_data **p_disp = &disp[ds]; /* short cut */ 249 + unsigned char **p_disp = &disp[ds]; /* short cut */ 252 250 LodePNG_Decoder *p_decoder = &decoder; 253 251 254 252 info->width = p_decoder->infoPng.width / ds; ··· 270 268 } 271 269 struct bitmap bmp_src, bmp_dst; 272 270 273 - int size = info->width * info->height; 271 + int size = img_mem(ds); 274 272 275 - if ((unsigned char *)(disp_buf + size) >= p_decoder->buf + p_decoder->buf_size) { 273 + if (disp_buf + size >= p_decoder->buf + p_decoder->buf_size) { 276 274 /* have to discard the current */ 277 275 int i; 278 276 for (i=1; i<=8; i++) 279 277 disp[i] = NULL; /* invalidate all bitmaps */ 280 278 281 279 /* start again from the beginning of the buffer */ 282 - disp_buf = (fb_data *)(p_decoder->buf + p_decoder->native_img_size); 283 - disp_buf = (fb_data *)ALIGN_UP((uintptr_t)disp_buf,4); 280 + disp_buf = p_decoder->buf + p_decoder->native_img_size; 284 281 } 285 282 286 283 *p_disp = disp_buf; 287 - #ifdef USEGSLIB 288 - disp_buf = (fb_data *)((unsigned char *)disp_buf + size); 289 - #else 290 284 disp_buf += size; 291 - #endif 292 285 293 286 bmp_src.width = p_decoder->infoPng.width; 294 287 bmp_src.height = p_decoder->infoPng.height; 295 - bmp_src.data = (unsigned char *)p_decoder->buf; 288 + bmp_src.data = p_decoder->buf; 296 289 297 290 bmp_dst.width = info->width; 298 291 bmp_dst.height = info->height; 299 - bmp_dst.data = (unsigned char *)*p_disp; 292 + bmp_dst.data = *p_disp; 300 293 #ifdef HAVE_ADJUSTABLE_CPU_FREQ 301 294 rb->cpu_boost(true); 302 295 resize_bitmap(&bmp_src, &bmp_dst); ··· 305 298 resize_bitmap(&bmp_src, &bmp_dst); 306 299 #endif /*HAVE_ADJUSTABLE_CPU_FREQ*/ 307 300 } else { 308 - *p_disp = (fb_data *)p_decoder->buf; 301 + *p_disp = p_decoder->buf; 309 302 } 310 303 311 304 return PLUGIN_OK;
-25
apps/plugins/imageviewer/png/png.h
··· 1 - /*************************************************************************** 2 - * __________ __ ___. 3 - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 - * \/ \/ \/ \/ \/ 8 - * $Id$id $ 9 - * 10 - * Copyright (C) 2009 by Christophe Gouiran <bechris13250 -at- gmail -dot- com> 11 - * 12 - * Based on lodepng, a lightweight png decoder/encoder 13 - * (c) 2005-2008 Lode Vandevenne 14 - * 15 - * This program is free software; you can redistribute it and/or 16 - * modify it under the terms of the GNU General Public License 17 - * as published by the Free Software Foundation; either version 2 18 - * of the License, or (at your option) any later version. 19 - * 20 - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 - * KIND, either express or implied. 22 - * 23 - ****************************************************************************/ 24 - 25 - #include "../imageviewer.h"
+515 -517
apps/plugins/imageviewer/png/png_decoder.c
··· 199 199 */ 200 200 if (bit) 201 201 bitstream[(*bitpointer) >> 3] |= (bit << (7 - ((*bitpointer) & 0x7))); 202 - 202 + 203 203 (*bitpointer)++; 204 204 } 205 205 ··· 408 408 #ifdef HAVE_LCD_COLOR 409 409 struct uint8_rgb *line_buf = (struct uint8_rgb *)(out + w * h * FB_DATA_SZ); 410 410 #else 411 - uint8_t *line_buf = (unsigned char *)(out + w * h * FB_DATA_SZ); 411 + uint8_t *line_buf = (unsigned char *)(out + w * h); 412 412 #endif 413 413 414 414 struct bitmap bm = { ··· 428 428 const struct custom_format *cformat = &format_native; 429 429 #endif 430 430 431 - void (*output_row_8)(uint32_t, void*, struct scaler_context*) = cformat->output_row_8; 431 + void (*output_row_8)(uint32_t, void*, struct scaler_context*) = cformat->output_row_8; 432 432 433 433 #ifdef HAVE_LCD_COLOR 434 - struct uint8_rgb *pixel; 434 + struct uint8_rgb *pixel; 435 435 #else 436 - unsigned char *pixel; 436 + unsigned char *pixel; 437 437 #endif 438 438 439 439 #ifdef HAVE_LCD_COLOR 440 - if (infoIn->color.bitDepth == 8) 440 + if (infoIn->color.bitDepth == 8) 441 + { 442 + switch (infoIn->color.colorType) 441 443 { 442 - switch (infoIn->color.colorType) 443 - { 444 - case PNG_COLORTYPE_GREY: /*greyscale color*/ 445 - i = 0; 446 - for (y = 0 ; y < h ; y++) { 447 - /* reset line buf */ 448 - pixel = line_buf; 444 + case PNG_COLORTYPE_GREY: /*greyscale color*/ 445 + i = 0; 446 + for (y = 0 ; y < h ; y++) { 447 + /* reset line buf */ 448 + pixel = line_buf; 449 449 450 - for (x = 0; x < w ; x++) { 451 - value = in[i++]; 452 - if (infoIn->color.key_defined) 453 - if ( (uint8_t)value == (uint8_t)infoIn->color.key_r ) 454 - value = infoIn->background_r; /* full transparent */ 450 + for (x = 0; x < w ; x++) { 451 + value = in[i++]; 452 + if (infoIn->color.key_defined) 453 + if ( (uint8_t)value == (uint8_t)infoIn->color.key_r ) 454 + value = infoIn->background_r; /* full transparent */ 455 455 456 - pixel->red = (uint8_t)value; 457 - pixel->green = (uint8_t)value; 458 - pixel->blue = (uint8_t)value; 459 - pixel++; 460 - } 461 - output_row_8(y,(void *)line_buf,&ctx); 456 + pixel->red = (uint8_t)value; 457 + pixel->green = (uint8_t)value; 458 + pixel->blue = (uint8_t)value; 459 + pixel++; 462 460 } 463 - break; 464 - case PNG_COLORTYPE_RGB: /*RGB color*/ 465 - i = 0; 466 - for (y = 0 ; y < h ; y++) { 467 - pixel = line_buf; 468 - for (x = 0 ; x < w ; x++) { 469 - j = 3*i++; 461 + output_row_8(y,(void *)line_buf,&ctx); 462 + } 463 + break; 464 + case PNG_COLORTYPE_RGB: /*RGB color*/ 465 + i = 0; 466 + for (y = 0 ; y < h ; y++) { 467 + pixel = line_buf; 468 + for (x = 0 ; x < w ; x++) { 469 + j = 3*i++; 470 470 471 - /* tRNs & bKGD */ 472 - if (infoIn->color.key_defined && 473 - in[j] == (uint8_t)infoIn->color.key_r && 474 - in[j + 1] == (uint8_t)infoIn->color.key_g && 475 - in[j + 2] == (uint8_t)infoIn->color.key_b) 476 - { 477 - pixel->red = (uint8_t)infoIn->background_r; 478 - pixel->green = (uint8_t)infoIn->background_g; 479 - pixel->blue = (uint8_t)infoIn->background_b; 480 - } 481 - else 482 - { 483 - pixel->red = in[j]; 484 - pixel->green = in[j + 1]; 485 - pixel->blue = in[j + 2]; 486 - } 487 - pixel++; 471 + /* tRNs & bKGD */ 472 + if (infoIn->color.key_defined && 473 + in[j] == (uint8_t)infoIn->color.key_r && 474 + in[j + 1] == (uint8_t)infoIn->color.key_g && 475 + in[j + 2] == (uint8_t)infoIn->color.key_b) 476 + { 477 + pixel->red = (uint8_t)infoIn->background_r; 478 + pixel->green = (uint8_t)infoIn->background_g; 479 + pixel->blue = (uint8_t)infoIn->background_b; 488 480 } 489 - output_row_8(y,(void *)line_buf,&ctx); 481 + else 482 + { 483 + pixel->red = in[j]; 484 + pixel->green = in[j + 1]; 485 + pixel->blue = in[j + 2]; 486 + } 487 + pixel++; 490 488 } 491 - break; 492 - case PNG_COLORTYPE_PALETTE: /*indexed color (palette)*/ 493 - i = 0; 494 - for (y = 0 ; y < h ; y++) { 495 - /* reset line buf */ 496 - pixel = line_buf; 497 - for (x = 0 ; x < w ; x++) { 498 - if (in[i] >= infoIn->color.palettesize) 499 - { 500 - decoder->error = 46; 501 - return; 502 - } 489 + output_row_8(y,(void *)line_buf,&ctx); 490 + } 491 + break; 492 + case PNG_COLORTYPE_PALETTE: /*indexed color (palette)*/ 493 + i = 0; 494 + for (y = 0 ; y < h ; y++) { 495 + /* reset line buf */ 496 + pixel = line_buf; 497 + for (x = 0 ; x < w ; x++) { 498 + if (in[i] >= infoIn->color.palettesize) 499 + { 500 + decoder->error = 46; 501 + return; 502 + } 503 503 504 - j = in[i++]<<2; 505 - alpha = infoIn->color.palette[j + 3]; 506 - alpha_complement = (256 - alpha); 504 + j = in[i++]<<2; 505 + alpha = infoIn->color.palette[j + 3]; 506 + alpha_complement = (256 - alpha); 507 507 508 - /* tRNS and bKGD */ 509 - pixel->red = (infoIn->color.palette[j] * alpha + 510 - alpha_complement*infoIn->background_r)>>8; 511 - pixel->green = (infoIn->color.palette[j + 1] * alpha + 512 - alpha_complement*infoIn->background_g)>>8; 513 - pixel->blue = (infoIn->color.palette[j + 2] * alpha + 514 - alpha_complement*infoIn->background_b)>>8; 515 - pixel++; 516 - } 517 - output_row_8(y,(void *)(line_buf),&ctx); 508 + /* tRNS and bKGD */ 509 + pixel->red = (infoIn->color.palette[j] * alpha + 510 + alpha_complement*infoIn->background_r)>>8; 511 + pixel->green = (infoIn->color.palette[j + 1] * alpha + 512 + alpha_complement*infoIn->background_g)>>8; 513 + pixel->blue = (infoIn->color.palette[j + 2] * alpha + 514 + alpha_complement*infoIn->background_b)>>8; 515 + pixel++; 518 516 } 519 - break; 520 - case PNG_COLORTYPE_GREYA: /*greyscale with alpha*/ 521 - i = 0; 522 - for (y = 0 ; y < h ; y++) { 523 - pixel = line_buf; 524 - for (x = 0 ; x < w ; x++) { 525 - alpha = in[(i << 1) + 1]; 526 - alpha_complement = (256 - alpha)*infoIn->background_r; 527 - value = (alpha * in[i++ << 1] + alpha_complement)>>8; 528 - pixel->red = (uint8_t)(value); 529 - pixel->green = (uint8_t)value; 530 - pixel->blue = (uint8_t)value; 531 - pixel++; 532 - } 533 - output_row_8(y,(void *)line_buf,&ctx); 517 + output_row_8(y,(void *)(line_buf),&ctx); 518 + } 519 + break; 520 + case PNG_COLORTYPE_GREYA: /*greyscale with alpha*/ 521 + i = 0; 522 + for (y = 0 ; y < h ; y++) { 523 + pixel = line_buf; 524 + for (x = 0 ; x < w ; x++) { 525 + alpha = in[(i << 1) + 1]; 526 + alpha_complement = (256 - alpha)*infoIn->background_r; 527 + value = (alpha * in[i++ << 1] + alpha_complement)>>8; 528 + pixel->red = (uint8_t)(value); 529 + pixel->green = (uint8_t)value; 530 + pixel->blue = (uint8_t)value; 531 + pixel++; 534 532 } 535 - break; 536 - case PNG_COLORTYPE_RGBA: /*RGB with alpha*/ 537 - i = 0; 538 - for (y = 0 ; y < h ; y++) { 539 - pixel = line_buf; 540 - for (x = 0 ; x < w ; x++) { 541 - j = i++ << 2; 542 - alpha = in[j + 3]; 543 - alpha_complement = (256 - alpha); 544 - pixel->red = (in[j] * alpha + 545 - alpha_complement*infoIn->background_r)>>8; 546 - pixel->green = (in[j + 1] * alpha + 547 - alpha_complement*infoIn->background_g)>>8; 548 - pixel->blue = (in[j + 2] * alpha + 549 - alpha_complement*infoIn->background_b)>>8; 550 - pixel++; 551 - } 552 - output_row_8(y,(void *)line_buf,&ctx); 533 + output_row_8(y,(void *)line_buf,&ctx); 534 + } 535 + break; 536 + case PNG_COLORTYPE_RGBA: /*RGB with alpha*/ 537 + i = 0; 538 + for (y = 0 ; y < h ; y++) { 539 + pixel = line_buf; 540 + for (x = 0 ; x < w ; x++) { 541 + j = i++ << 2; 542 + alpha = in[j + 3]; 543 + alpha_complement = (256 - alpha); 544 + pixel->red = (in[j] * alpha + 545 + alpha_complement*infoIn->background_r)>>8; 546 + pixel->green = (in[j + 1] * alpha + 547 + alpha_complement*infoIn->background_g)>>8; 548 + pixel->blue = (in[j + 2] * alpha + 549 + alpha_complement*infoIn->background_b)>>8; 550 + pixel++; 553 551 } 554 - break; 555 - default: 556 - break; 552 + output_row_8(y,(void *)line_buf,&ctx); 557 553 } 554 + break; 555 + default: 556 + break; 558 557 } 559 - else if (infoIn->color.bitDepth == 16) 558 + } 559 + else if (infoIn->color.bitDepth == 16) 560 + { 561 + switch (infoIn->color.colorType) 560 562 { 561 - switch (infoIn->color.colorType) 562 - { 563 - case PNG_COLORTYPE_GREY: /*greyscale color*/ 564 - i = 0; 565 - for (y = 0 ; y < h ; y++) { 566 - pixel = line_buf; 567 - for (x = 0 ; x < w ; x++) { 568 - value = (in[i<<1]<<8)|in[(i << 1) + 1]; 569 - i++; 563 + case PNG_COLORTYPE_GREY: /*greyscale color*/ 564 + i = 0; 565 + for (y = 0 ; y < h ; y++) { 566 + pixel = line_buf; 567 + for (x = 0 ; x < w ; x++) { 568 + value = (in[i<<1]<<8)|in[(i << 1) + 1]; 569 + i++; 570 570 571 - /* tRNS and bKGD */ 572 - if (infoIn->color.key_defined && 573 - value == infoIn->color.key_r) 574 - value = infoIn->background_r<<8; 575 - 576 - pixel->red = 577 - pixel->green = 578 - pixel->blue = (uint8_t)(value>>8); 579 - pixel++; 580 - } 581 - output_row_8(y,(void *)line_buf,&ctx); 571 + /* tRNS and bKGD */ 572 + if (infoIn->color.key_defined && 573 + value == infoIn->color.key_r) 574 + value = infoIn->background_r<<8; 575 + 576 + pixel->red = 577 + pixel->green = 578 + pixel->blue = (uint8_t)(value>>8); 579 + pixel++; 582 580 } 583 - break; 584 - case PNG_COLORTYPE_RGB: /*RGB color*/ 585 - i = 0; 586 - for (y = 0 ; y < h ; y++) { 587 - pixel = line_buf; 588 - for (x = 0 ; x < w ; x++) { 589 - j = 6 * i++; 581 + output_row_8(y,(void *)line_buf,&ctx); 582 + } 583 + break; 584 + case PNG_COLORTYPE_RGB: /*RGB color*/ 585 + i = 0; 586 + for (y = 0 ; y < h ; y++) { 587 + pixel = line_buf; 588 + for (x = 0 ; x < w ; x++) { 589 + j = 6 * i++; 590 590 591 - /* tRNS and bKGD */ 592 - if (infoIn->color.key_defined && 593 - ((uint16_t)(in[j]<<8|in[j + 1]) == 594 - infoIn->color.key_r) && 595 - ((uint16_t)(in[j + 2]<<8|in[j + 3]) == 596 - infoIn->color.key_g) && 597 - ((uint16_t)(in[j + 4]<<8|in[j + 5]) == 598 - infoIn->color.key_b)) 599 - { 600 - pixel->red = (uint8_t)infoIn->background_r; 601 - pixel->green = (uint8_t)infoIn->background_g; 602 - pixel->blue = (uint8_t)infoIn->background_b; 603 - } 604 - else 605 - { 606 - pixel->red = in[j]; 607 - pixel->green = in[j + 2]; 608 - pixel->blue = in[j + 4]; 609 - } 610 - pixel++; 591 + /* tRNS and bKGD */ 592 + if (infoIn->color.key_defined && 593 + ((uint16_t)(in[j]<<8|in[j + 1]) == 594 + infoIn->color.key_r) && 595 + ((uint16_t)(in[j + 2]<<8|in[j + 3]) == 596 + infoIn->color.key_g) && 597 + ((uint16_t)(in[j + 4]<<8|in[j + 5]) == 598 + infoIn->color.key_b)) 599 + { 600 + pixel->red = (uint8_t)infoIn->background_r; 601 + pixel->green = (uint8_t)infoIn->background_g; 602 + pixel->blue = (uint8_t)infoIn->background_b; 603 + } 604 + else 605 + { 606 + pixel->red = in[j]; 607 + pixel->green = in[j + 2]; 608 + pixel->blue = in[j + 4]; 611 609 } 612 - output_row_8(y,(void *)line_buf,&ctx); 610 + pixel++; 613 611 } 614 - break; 615 - case PNG_COLORTYPE_GREYA: /*greyscale with alpha*/ 616 - i = 0; 617 - for (y = 0 ; y < h ; y++) { 618 - pixel = line_buf; 619 - for (x = 0 ; x < w ; x++) { 620 - alpha = in[(i << 2) + 2]; 621 - alpha_complement = (256-alpha)*infoIn->background_r; 622 - value = (in[i++ << 2] * alpha + alpha_complement)>>8; 623 - pixel->red = (uint8_t)value; 624 - pixel->green = (uint8_t)value; 625 - pixel->blue = (uint8_t)value; 626 - pixel++; 627 - } 628 - output_row_8(y,(void *)line_buf,&ctx); 612 + output_row_8(y,(void *)line_buf,&ctx); 613 + } 614 + break; 615 + case PNG_COLORTYPE_GREYA: /*greyscale with alpha*/ 616 + i = 0; 617 + for (y = 0 ; y < h ; y++) { 618 + pixel = line_buf; 619 + for (x = 0 ; x < w ; x++) { 620 + alpha = in[(i << 2) + 2]; 621 + alpha_complement = (256-alpha)*infoIn->background_r; 622 + value = (in[i++ << 2] * alpha + alpha_complement)>>8; 623 + pixel->red = (uint8_t)value; 624 + pixel->green = (uint8_t)value; 625 + pixel->blue = (uint8_t)value; 626 + pixel++; 629 627 } 630 - break; 631 - case PNG_COLORTYPE_RGBA: /*RGB with alpha*/ 632 - i = 0; 633 - for (y = 0 ; y < h ; y++) { 634 - pixel = line_buf; 635 - for (x = 0 ; x < w ; x++) { 636 - j = i++ << 3; 637 - alpha = in[j + 6]; 638 - alpha_complement = (256-alpha); 639 - pixel->red = (in[j] * alpha + 640 - alpha_complement*infoIn->background_r)>>8; 641 - pixel->green = (in[j + 2] * alpha + 642 - alpha_complement*infoIn->background_g)>>8; 643 - pixel->blue = (in[j + 4] * alpha + 644 - alpha_complement*infoIn->background_b)>>8; 645 - pixel++; 646 - } 647 - output_row_8(y,(void *)line_buf,&ctx); 628 + output_row_8(y,(void *)line_buf,&ctx); 629 + } 630 + break; 631 + case PNG_COLORTYPE_RGBA: /*RGB with alpha*/ 632 + i = 0; 633 + for (y = 0 ; y < h ; y++) { 634 + pixel = line_buf; 635 + for (x = 0 ; x < w ; x++) { 636 + j = i++ << 3; 637 + alpha = in[j + 6]; 638 + alpha_complement = (256-alpha); 639 + pixel->red = (in[j] * alpha + 640 + alpha_complement*infoIn->background_r)>>8; 641 + pixel->green = (in[j + 2] * alpha + 642 + alpha_complement*infoIn->background_g)>>8; 643 + pixel->blue = (in[j + 4] * alpha + 644 + alpha_complement*infoIn->background_b)>>8; 645 + pixel++; 648 646 } 649 - break; 650 - default: 651 - break; 647 + output_row_8(y,(void *)line_buf,&ctx); 652 648 } 649 + break; 650 + default: 651 + break; 653 652 } 654 - else /*infoIn->bitDepth is less than 8 bit per channel*/ 653 + } 654 + else /*infoIn->bitDepth is less than 8 bit per channel*/ 655 + { 656 + switch (infoIn->color.colorType) 655 657 { 656 - switch (infoIn->color.colorType) 657 - { 658 - case PNG_COLORTYPE_GREY: /*greyscale color*/ 659 - i = 0; 660 - for (y = 0 ; y < h ; y++) { 661 - pixel = line_buf; 662 - for (x = 0 ; x < w ; x++) { 663 - value = readBitsFromReversedStream(&bp, in, infoIn->color.bitDepth); 664 - 665 - /* tRNS and bKGD */ 666 - if (infoIn->color.key_defined) 667 - if ( value == infoIn->color.key_r ) 668 - value = infoIn->background_r; /* full transparent */ 658 + case PNG_COLORTYPE_GREY: /*greyscale color*/ 659 + i = 0; 660 + for (y = 0 ; y < h ; y++) { 661 + pixel = line_buf; 662 + for (x = 0 ; x < w ; x++) { 663 + value = readBitsFromReversedStream(&bp, in, infoIn->color.bitDepth); 664 + 665 + /* tRNS and bKGD */ 666 + if (infoIn->color.key_defined) 667 + if ( value == infoIn->color.key_r ) 668 + value = infoIn->background_r; /* full transparent */ 669 669 670 - /* scale value from 0 to 255 */ 671 - value = (value * 255) / ((1 << infoIn->color.bitDepth) - 1); 670 + /* scale value from 0 to 255 */ 671 + value = (value * 255) / ((1 << infoIn->color.bitDepth) - 1); 672 672 673 - pixel->red = (uint8_t)value; 674 - pixel->green = (uint8_t)value; 675 - pixel->blue = (uint8_t)value; 676 - pixel++; 677 - } 678 - output_row_8(y,(void *)line_buf,&ctx); 673 + pixel->red = (uint8_t)value; 674 + pixel->green = (uint8_t)value; 675 + pixel->blue = (uint8_t)value; 676 + pixel++; 679 677 } 680 - break; 681 - case PNG_COLORTYPE_PALETTE: /*indexed color (palette)*/ 682 - i = 0; 683 - for (y = 0 ; y < h ; y++) { 684 - pixel = line_buf; 685 - for (x = 0 ; x < w ; x++) { 686 - value = readBitsFromReversedStream(&bp, in, infoIn->color.bitDepth); 687 - if (value >= infoIn->color.palettesize) 688 - { 689 - decoder->error = 47; 690 - return; 691 - } 678 + output_row_8(y,(void *)line_buf,&ctx); 679 + } 680 + break; 681 + case PNG_COLORTYPE_PALETTE: /*indexed color (palette)*/ 682 + i = 0; 683 + for (y = 0 ; y < h ; y++) { 684 + pixel = line_buf; 685 + for (x = 0 ; x < w ; x++) { 686 + value = readBitsFromReversedStream(&bp, in, infoIn->color.bitDepth); 687 + if (value >= infoIn->color.palettesize) 688 + { 689 + decoder->error = 47; 690 + return; 691 + } 692 + 693 + j = value << 2; 692 694 693 - j = value << 2; 694 - 695 - /* tRNS and bKGD */ 696 - alpha = infoIn->color.palette[j + 3]; 697 - alpha_complement = (256 - alpha); 698 - pixel->red = (alpha * infoIn->color.palette[j] + 699 - alpha_complement*infoIn->background_r)>>8; 700 - pixel->green = (alpha * infoIn->color.palette[j + 1] + 701 - alpha_complement*infoIn->background_g)>>8; 702 - pixel->blue = (alpha * infoIn->color.palette[j + 2] + 703 - alpha_complement*infoIn->background_b)>>8; 704 - pixel++; 705 - } 706 - output_row_8(y,(void *)line_buf,&ctx); 695 + /* tRNS and bKGD */ 696 + alpha = infoIn->color.palette[j + 3]; 697 + alpha_complement = (256 - alpha); 698 + pixel->red = (alpha * infoIn->color.palette[j] + 699 + alpha_complement*infoIn->background_r)>>8; 700 + pixel->green = (alpha * infoIn->color.palette[j + 1] + 701 + alpha_complement*infoIn->background_g)>>8; 702 + pixel->blue = (alpha * infoIn->color.palette[j + 2] + 703 + alpha_complement*infoIn->background_b)>>8; 704 + pixel++; 707 705 } 708 - break; 709 - default: 710 - break; 706 + output_row_8(y,(void *)line_buf,&ctx); 711 707 } 708 + break; 709 + default: 710 + break; 712 711 } 712 + } 713 713 #else /* greyscale targets */ 714 - struct uint8_rgb px_rgb; /* for rgb(a) -> greyscale conversion */ 715 - uint8_t background_grey; /* for rgb background -> greyscale background */ 714 + struct uint8_rgb px_rgb; /* for rgb(a) -> greyscale conversion */ 715 + uint8_t background_grey; /* for rgb background -> greyscale background */ 716 716 717 - if (infoIn->color.bitDepth == 8) 717 + if (infoIn->color.bitDepth == 8) 718 + { 719 + switch (infoIn->color.colorType) 718 720 { 719 - switch (infoIn->color.colorType) 720 - { 721 - case PNG_COLORTYPE_GREY: /*greyscale color*/ 722 - i = 0; 723 - for (y = 0 ; y < h ; y++) { 724 - pixel = line_buf; 725 - for (x = 0 ; x < w ; x++ ) { 726 - value = in[i++]; 721 + case PNG_COLORTYPE_GREY: /*greyscale color*/ 722 + i = 0; 723 + for (y = 0 ; y < h ; y++) { 724 + pixel = line_buf; 725 + for (x = 0 ; x < w ; x++ ) { 726 + value = in[i++]; 727 727 728 - /* transparent color defined in tRNS chunk */ 729 - if (infoIn->color.key_defined) 730 - if ( (uint8_t)value == (uint8_t)infoIn->color.key_r ) 731 - value = infoIn->background_r; 728 + /* transparent color defined in tRNS chunk */ 729 + if (infoIn->color.key_defined) 730 + if ( (uint8_t)value == (uint8_t)infoIn->color.key_r ) 731 + value = infoIn->background_r; 732 732 733 - *pixel++ = (uint8_t)value; 734 - } 735 - output_row_8(y,(void *)line_buf,&ctx); 733 + *pixel++ = (uint8_t)value; 736 734 } 737 - break; 738 - case PNG_COLORTYPE_RGB: /*RGB color*/ 739 - /* convert background rgb color to greyscale */ 740 - px_rgb.red = infoIn->background_r; 741 - px_rgb.green = infoIn->background_g; 742 - px_rgb.blue = infoIn->background_b; 743 - background_grey = brightness(px_rgb); 735 + output_row_8(y,(void *)line_buf,&ctx); 736 + } 737 + break; 738 + case PNG_COLORTYPE_RGB: /*RGB color*/ 739 + /* convert background rgb color to greyscale */ 740 + px_rgb.red = infoIn->background_r; 741 + px_rgb.green = infoIn->background_g; 742 + px_rgb.blue = infoIn->background_b; 743 + background_grey = brightness(px_rgb); 744 744 745 - i = 0; 746 - for (y = 0 ; y < h ; y++) { 747 - pixel = line_buf; 748 - for (x = 0 ; x < w ; x++) { 749 - j = 3*i++; 745 + i = 0; 746 + for (y = 0 ; y < h ; y++) { 747 + pixel = line_buf; 748 + for (x = 0 ; x < w ; x++) { 749 + j = 3*i++; 750 750 751 - /* tRNs & bKGD */ 752 - if (infoIn->color.key_defined && 753 - in[j] == (uint8_t)infoIn->color.key_r && 754 - in[j + 1] == (uint8_t)infoIn->color.key_g && 755 - in[j + 2] == (uint8_t)infoIn->color.key_b) 756 - { 757 - *pixel = background_grey; 758 - } 759 - else 760 - { 761 - /* rgb -> greyscale */ 762 - px_rgb.red = in[j]; 763 - px_rgb.green = in[j + 1]; 764 - px_rgb.blue = in[j + 2]; 765 - *pixel = brightness(px_rgb); 766 - } 767 - pixel++; 751 + /* tRNs & bKGD */ 752 + if (infoIn->color.key_defined && 753 + in[j] == (uint8_t)infoIn->color.key_r && 754 + in[j + 1] == (uint8_t)infoIn->color.key_g && 755 + in[j + 2] == (uint8_t)infoIn->color.key_b) 756 + { 757 + *pixel = background_grey; 758 + } 759 + else 760 + { 761 + /* rgb -> greyscale */ 762 + px_rgb.red = in[j]; 763 + px_rgb.green = in[j + 1]; 764 + px_rgb.blue = in[j + 2]; 765 + *pixel = brightness(px_rgb); 766 + } 767 + pixel++; 768 768 769 - } 770 - output_row_8(y,(void *)line_buf,&ctx); 771 769 } 772 - break; 773 - case PNG_COLORTYPE_PALETTE: /*indexed color (palette)*/ 774 - i = 0; 775 - /* calculate grey value of rgb background */ 776 - px_rgb.red = infoIn->background_r; 777 - px_rgb.green = infoIn->background_g; 778 - px_rgb.blue = infoIn->background_b; 779 - background_grey = brightness(px_rgb); 770 + output_row_8(y,(void *)line_buf,&ctx); 771 + } 772 + break; 773 + case PNG_COLORTYPE_PALETTE: /*indexed color (palette)*/ 774 + i = 0; 775 + /* calculate grey value of rgb background */ 776 + px_rgb.red = infoIn->background_r; 777 + px_rgb.green = infoIn->background_g; 778 + px_rgb.blue = infoIn->background_b; 779 + background_grey = brightness(px_rgb); 780 780 781 - for (y = 0 ; y < h ; y++) { 782 - /* reset line buf */ 783 - pixel = line_buf; 784 - for (x = 0 ; x < w ; x++) { 785 - if (in[i] >= infoIn->color.palettesize) 786 - { 787 - decoder->error = 46; 788 - return; 789 - } 781 + for (y = 0 ; y < h ; y++) { 782 + /* reset line buf */ 783 + pixel = line_buf; 784 + for (x = 0 ; x < w ; x++) { 785 + if (in[i] >= infoIn->color.palettesize) 786 + { 787 + decoder->error = 46; 788 + return; 789 + } 790 790 791 - j = in[i++] << 2; 792 - alpha = infoIn->color.palette[j + 3]; 793 - alpha_complement = (256 - alpha); 791 + j = in[i++] << 2; 792 + alpha = infoIn->color.palette[j + 3]; 793 + alpha_complement = (256 - alpha); 794 794 795 - /* tRNS and bKGD */ 796 - px_rgb.red = (alpha * infoIn->color.palette[j] + 797 - alpha_complement*background_grey)>>8; 798 - px_rgb.green = (alpha * infoIn->color.palette[j + 1] + 799 - alpha_complement*background_grey)>>8; 800 - px_rgb.blue = (alpha * infoIn->color.palette[j + 2] + 801 - alpha_complement*background_grey)>>8; 795 + /* tRNS and bKGD */ 796 + px_rgb.red = (alpha * infoIn->color.palette[j] + 797 + alpha_complement*background_grey)>>8; 798 + px_rgb.green = (alpha * infoIn->color.palette[j + 1] + 799 + alpha_complement*background_grey)>>8; 800 + px_rgb.blue = (alpha * infoIn->color.palette[j + 2] + 801 + alpha_complement*background_grey)>>8; 802 802 803 - *pixel++ = brightness(px_rgb); 804 - } 805 - output_row_8(y,(void *)(line_buf),&ctx); 803 + *pixel++ = brightness(px_rgb); 806 804 } 807 - break; 808 - case PNG_COLORTYPE_GREYA: /*greyscale with alpha*/ 809 - i = 0; 810 - for (y = 0 ; y < h ; y++) { 811 - pixel = line_buf; 812 - for (x = 0 ; x < w ; x++) { 813 - alpha = in[(i << 1) + 1]; 814 - alpha_complement = ((256 - alpha)*infoIn->background_r); 815 - *pixel++ = (alpha * in[i++ << 1] + alpha_complement)>>8; 816 - } 817 - output_row_8(y,(void *)line_buf,&ctx); 805 + output_row_8(y,(void *)(line_buf),&ctx); 806 + } 807 + break; 808 + case PNG_COLORTYPE_GREYA: /*greyscale with alpha*/ 809 + i = 0; 810 + for (y = 0 ; y < h ; y++) { 811 + pixel = line_buf; 812 + for (x = 0 ; x < w ; x++) { 813 + alpha = in[(i << 1) + 1]; 814 + alpha_complement = ((256 - alpha)*infoIn->background_r); 815 + *pixel++ = (alpha * in[i++ << 1] + alpha_complement)>>8; 818 816 } 819 - break; 820 - case PNG_COLORTYPE_RGBA: /*RGB with alpha*/ 821 - px_rgb.red = infoIn->background_r; 822 - px_rgb.green = infoIn->background_g; 823 - px_rgb.blue = infoIn->background_b; 824 - background_grey = brightness(px_rgb); 817 + output_row_8(y,(void *)line_buf,&ctx); 818 + } 819 + break; 820 + case PNG_COLORTYPE_RGBA: /*RGB with alpha*/ 821 + px_rgb.red = infoIn->background_r; 822 + px_rgb.green = infoIn->background_g; 823 + px_rgb.blue = infoIn->background_b; 824 + background_grey = brightness(px_rgb); 825 825 826 - i = 0; 827 - for (y = 0 ; y < h ; y++) { 828 - pixel = line_buf; 829 - for (x = 0 ; x < w ; x++) { 830 - j = i++ << 2; 831 - alpha = in[j + 3]; 832 - alpha_complement = ((256 - alpha)*background_grey); 826 + i = 0; 827 + for (y = 0 ; y < h ; y++) { 828 + pixel = line_buf; 829 + for (x = 0 ; x < w ; x++) { 830 + j = i++ << 2; 831 + alpha = in[j + 3]; 832 + alpha_complement = ((256 - alpha)*background_grey); 833 833 834 - px_rgb.red = in[j]; 835 - px_rgb.green = in[j + 1]; 836 - px_rgb.blue = in[j + 2]; 837 - *pixel++ = (alpha * brightness(px_rgb) + 838 - alpha_complement)>>8; 839 - } 840 - output_row_8(y,(void *)line_buf,&ctx); 834 + px_rgb.red = in[j]; 835 + px_rgb.green = in[j + 1]; 836 + px_rgb.blue = in[j + 2]; 837 + *pixel++ = (alpha * brightness(px_rgb) + 838 + alpha_complement)>>8; 841 839 } 842 - break; 843 - default: 844 - break; 840 + output_row_8(y,(void *)line_buf,&ctx); 845 841 } 842 + break; 843 + default: 844 + break; 846 845 } 847 - else if (infoIn->color.bitDepth == 16) 846 + } 847 + else if (infoIn->color.bitDepth == 16) 848 + { 849 + switch (infoIn->color.colorType) 848 850 { 849 - switch (infoIn->color.colorType) 850 - { 851 - case PNG_COLORTYPE_GREY: /*greyscale color*/ 852 - i = 0; 853 - for (y = 0 ; y < h ; y++) { 854 - pixel = line_buf; 855 - for (x = 0 ; x < w ; x++) { 856 - /* specification states that we have to compare 857 - * colors for simple transparency in 16bits 858 - * even if we scale down to 8bits later 859 - */ 860 - value = in[i<<1]<<8|in[(i << 1) + 1]; 861 - i++; 862 - 863 - /* tRNS and bKGD */ 864 - if (infoIn->color.key_defined && 865 - value == infoIn->color.key_r) 866 - value = infoIn->background_r<<8; 851 + case PNG_COLORTYPE_GREY: /*greyscale color*/ 852 + i = 0; 853 + for (y = 0 ; y < h ; y++) { 854 + pixel = line_buf; 855 + for (x = 0 ; x < w ; x++) { 856 + /* specification states that we have to compare 857 + * colors for simple transparency in 16bits 858 + * even if we scale down to 8bits later 859 + */ 860 + value = in[i<<1]<<8|in[(i << 1) + 1]; 861 + i++; 867 862 868 - /* we take upper 8bits */ 869 - *pixel++ = (uint8_t)(value>>8); 870 - } 863 + /* tRNS and bKGD */ 864 + if (infoIn->color.key_defined && 865 + value == infoIn->color.key_r) 866 + value = infoIn->background_r<<8; 871 867 872 - output_row_8(y,(void *)line_buf,&ctx); 868 + /* we take upper 8bits */ 869 + *pixel++ = (uint8_t)(value>>8); 873 870 } 874 - break; 875 - case PNG_COLORTYPE_RGB: /*RGB color*/ 876 - i = 0; 877 - px_rgb.red = infoIn->background_r; 878 - px_rgb.green = infoIn->background_g; 879 - px_rgb.blue = infoIn->background_b; 880 - background_grey = brightness(px_rgb); 881 871 882 - for (y = 0 ; y < h ; y++) { 883 - pixel = line_buf; 884 - for (x = 0 ; x < w ; x++) { 885 - j = 6 * i++; 872 + output_row_8(y,(void *)line_buf,&ctx); 873 + } 874 + break; 875 + case PNG_COLORTYPE_RGB: /*RGB color*/ 876 + i = 0; 877 + px_rgb.red = infoIn->background_r; 878 + px_rgb.green = infoIn->background_g; 879 + px_rgb.blue = infoIn->background_b; 880 + background_grey = brightness(px_rgb); 886 881 887 - /* tRNS and bKGD */ 888 - if (infoIn->color.key_defined && 889 - (uint16_t)(in[j]<<8|in[j + 1]) == 890 - infoIn->color.key_r && 891 - (uint16_t)(in[j + 2]<<8|in[j + 3]) == 892 - infoIn->color.key_g && 893 - (uint16_t)(in[j + 4]<<8|in[j + 5]) == 894 - infoIn->color.key_b) 895 - { 896 - *pixel = background_grey; 897 - } 898 - else 899 - { 900 - /* we take only upper byte of 16bit value */ 901 - px_rgb.red = in[j]; 902 - px_rgb.green = in[j + 2]; 903 - px_rgb.blue = in[j + 4]; 904 - *pixel = brightness(px_rgb); 905 - } 906 - pixel++; 882 + for (y = 0 ; y < h ; y++) { 883 + pixel = line_buf; 884 + for (x = 0 ; x < w ; x++) { 885 + j = 6 * i++; 886 + 887 + /* tRNS and bKGD */ 888 + if (infoIn->color.key_defined && 889 + (uint16_t)(in[j]<<8|in[j + 1]) == 890 + infoIn->color.key_r && 891 + (uint16_t)(in[j + 2]<<8|in[j + 3]) == 892 + infoIn->color.key_g && 893 + (uint16_t)(in[j + 4]<<8|in[j + 5]) == 894 + infoIn->color.key_b) 895 + { 896 + *pixel = background_grey; 907 897 } 908 - output_row_8(y,(void *)line_buf,&ctx); 909 - } 910 - break; 911 - case PNG_COLORTYPE_GREYA: /*greyscale with alpha*/ 912 - i = 0; 913 - for (y = 0 ; y < h ; y++) { 914 - pixel = line_buf; 915 - for (x = 0 ; x < w ; x++) { 916 - alpha = in[(i << 2) + 2]; 917 - alpha_complement = (256 - alpha)*infoIn->background_r; 918 - *pixel++ = (alpha * in[i++ << 2] + alpha_complement)>>8; 919 - } 920 - output_row_8(y,(void *)line_buf,&ctx); 921 - } 922 - break; 923 - case PNG_COLORTYPE_RGBA: /*RGB with alpha*/ 924 - px_rgb.red = infoIn->background_r; 925 - px_rgb.green = infoIn->background_g; 926 - px_rgb.blue = infoIn->background_b; 927 - background_grey = brightness(px_rgb); 928 - 929 - i = 0; 930 - for (y = 0 ; y < h ; y++) { 931 - pixel = line_buf; 932 - for (x = 0 ; x < w ; x++) { 933 - j = i++ << 3; 934 - alpha = in[j + 6]; 935 - alpha_complement = (256 - alpha)*background_grey; 898 + else 899 + { 900 + /* we take only upper byte of 16bit value */ 936 901 px_rgb.red = in[j]; 937 902 px_rgb.green = in[j + 2]; 938 903 px_rgb.blue = in[j + 4]; 939 - *pixel++ = (alpha * brightness(px_rgb) + alpha_complement)>>8; 904 + *pixel = brightness(px_rgb); 940 905 } 941 - output_row_8(y,(void *)line_buf,&ctx); 906 + pixel++; 942 907 } 943 - break; 944 - default: 945 - break; 908 + output_row_8(y,(void *)line_buf,&ctx); 946 909 } 910 + break; 911 + case PNG_COLORTYPE_GREYA: /*greyscale with alpha*/ 912 + i = 0; 913 + for (y = 0 ; y < h ; y++) { 914 + pixel = line_buf; 915 + for (x = 0 ; x < w ; x++) { 916 + alpha = in[(i << 2) + 2]; 917 + alpha_complement = (256 - alpha)*infoIn->background_r; 918 + *pixel++ = (alpha * in[i++ << 2] + alpha_complement)>>8; 919 + } 920 + output_row_8(y,(void *)line_buf,&ctx); 921 + } 922 + break; 923 + case PNG_COLORTYPE_RGBA: /*RGB with alpha*/ 924 + px_rgb.red = infoIn->background_r; 925 + px_rgb.green = infoIn->background_g; 926 + px_rgb.blue = infoIn->background_b; 927 + background_grey = brightness(px_rgb); 928 + 929 + i = 0; 930 + for (y = 0 ; y < h ; y++) { 931 + pixel = line_buf; 932 + for (x = 0 ; x < w ; x++) { 933 + j = i++ << 3; 934 + alpha = in[j + 6]; 935 + alpha_complement = (256 - alpha)*background_grey; 936 + px_rgb.red = in[j]; 937 + px_rgb.green = in[j + 2]; 938 + px_rgb.blue = in[j + 4]; 939 + *pixel++ = (alpha * brightness(px_rgb) + alpha_complement)>>8; 940 + } 941 + output_row_8(y,(void *)line_buf,&ctx); 942 + } 943 + break; 944 + default: 945 + break; 947 946 } 948 - else /*infoIn->bitDepth is less than 8 bit per channel*/ 947 + } 948 + else /*infoIn->bitDepth is less than 8 bit per channel*/ 949 + { 950 + switch (infoIn->color.colorType) 949 951 { 950 - switch (infoIn->color.colorType) 951 - { 952 - case PNG_COLORTYPE_GREY: /*greyscale color*/ 953 - i = 0; 954 - for (y = 0 ; y < h ; y++) { 955 - pixel = line_buf; 956 - for (x = 0 ; x < w ; x++) { 957 - value = readBitsFromReversedStream(&bp, in, infoIn->color.bitDepth); 952 + case PNG_COLORTYPE_GREY: /*greyscale color*/ 953 + i = 0; 954 + for (y = 0 ; y < h ; y++) { 955 + pixel = line_buf; 956 + for (x = 0 ; x < w ; x++) { 957 + value = readBitsFromReversedStream(&bp, in, infoIn->color.bitDepth); 958 + 959 + /* tRNS and bKGD */ 960 + if (infoIn->color.key_defined) 961 + if ( value == infoIn->color.key_r ) 962 + value = infoIn->background_r; /* full transparent */ 958 963 959 - /* tRNS and bKGD */ 960 - if (infoIn->color.key_defined) 961 - if ( value == infoIn->color.key_r ) 962 - value = infoIn->background_r; /* full transparent */ 964 + /*scale value from 0 to 255*/ 965 + value = (value * 255) / ((1 << infoIn->color.bitDepth) - 1); 963 966 964 - /*scale value from 0 to 255*/ 965 - value = (value * 255) / ((1 << infoIn->color.bitDepth) - 1); 966 - 967 - *pixel++ = (unsigned char)value; 968 - } 969 - output_row_8(y,(void *)line_buf,&ctx); 967 + *pixel++ = (unsigned char)value; 970 968 } 971 - break; 972 - case PNG_COLORTYPE_PALETTE: /*indexed color (palette)*/ 973 - i = 0; 974 - px_rgb.red = infoIn->background_r; 975 - px_rgb.green = infoIn->background_g; 976 - px_rgb.blue = infoIn->background_b; 977 - uint8_t background_grey = brightness(px_rgb); 969 + output_row_8(y,(void *)line_buf,&ctx); 970 + } 971 + break; 972 + case PNG_COLORTYPE_PALETTE: /*indexed color (palette)*/ 973 + i = 0; 974 + px_rgb.red = infoIn->background_r; 975 + px_rgb.green = infoIn->background_g; 976 + px_rgb.blue = infoIn->background_b; 977 + uint8_t background_grey = brightness(px_rgb); 978 978 979 - for (y = 0 ; y < h ; y++) { 980 - pixel = line_buf; 981 - for (x = 0 ; x < w ; x++) { 982 - value = readBitsFromReversedStream(&bp, in, infoIn->color.bitDepth); 983 - if (value >= infoIn->color.palettesize) 984 - { 985 - decoder->error = 47; 986 - return; 987 - } 979 + for (y = 0 ; y < h ; y++) { 980 + pixel = line_buf; 981 + for (x = 0 ; x < w ; x++) { 982 + value = readBitsFromReversedStream(&bp, in, infoIn->color.bitDepth); 983 + if (value >= infoIn->color.palettesize) 984 + { 985 + decoder->error = 47; 986 + return; 987 + } 988 988 989 - j = value << 2; 989 + j = value << 2; 990 990 991 - /* tRNS and bKGD */ 992 - alpha = infoIn->color.palette[j + 3]; 993 - alpha_complement = (256 - alpha) * background_grey; 991 + /* tRNS and bKGD */ 992 + alpha = infoIn->color.palette[j + 3]; 993 + alpha_complement = (256 - alpha) * background_grey; 994 994 995 - px_rgb.red = (alpha * infoIn->color.palette[j] + 996 - alpha_complement)>>8; 997 - px_rgb.green = (alpha * infoIn->color.palette[j + 1] + 998 - alpha_complement)>>8; 999 - px_rgb.blue = (alpha * infoIn->color.palette[j + 2] + 1000 - alpha_complement)>>8; 1001 - *pixel++ = brightness(px_rgb); 1002 - } 1003 - output_row_8(y,(void *)line_buf,&ctx); 995 + px_rgb.red = (alpha * infoIn->color.palette[j] + 996 + alpha_complement)>>8; 997 + px_rgb.green = (alpha * infoIn->color.palette[j + 1] + 998 + alpha_complement)>>8; 999 + px_rgb.blue = (alpha * infoIn->color.palette[j + 2] + 1000 + alpha_complement)>>8; 1001 + *pixel++ = brightness(px_rgb); 1004 1002 } 1005 - break; 1006 - default: 1007 - break; 1003 + output_row_8(y,(void *)line_buf,&ctx); 1008 1004 } 1005 + break; 1006 + default: 1007 + break; 1009 1008 } 1009 + } 1010 1010 #endif 1011 1011 } 1012 1012 ··· 1097 1097 * disjoint. 1098 1098 */ 1099 1099 1100 - /* storage space for cached portion of scanline */ 1101 - unsigned char cache[512+16]; 1100 + /* storage space for cached portion of scanline */ 1101 + unsigned char cache[512+16]; 1102 1102 1103 - /* ptr to second element of the cache */ 1104 - unsigned char *cache_1 = cache + bytewidth; 1105 - unsigned char *p_cache = cache + 256 + 8; /* half way */ 1106 - unsigned char *p_cache_1 = p_cache + bytewidth; 1103 + /* ptr to second element of the cache */ 1104 + unsigned char *cache_1 = cache + bytewidth; 1105 + unsigned char *p_cache = cache + 256 + 8; /* half way */ 1106 + unsigned char *p_cache_1 = p_cache + bytewidth; 1107 1107 1108 1108 size_t i; 1109 1109 switch (filterType) ··· 1192 1192 memcpy(recon, cache, length); 1193 1193 } 1194 1194 } 1195 - else 1195 + else 1196 1196 /* for(i = 0; i < length; i++) recon[i] = scanline[i]; */ 1197 1197 memcpy(recon, scanline, length * sizeof(uint8_t)); 1198 1198 break; ··· 1519 1519 /* note that this function assumes the out buffer 1520 1520 * is completely 0, use setBitOfReversedStream 1521 1521 * otherwise*/ 1522 - setBitOfReversedStream0(&obp, out, bit); 1522 + setBitOfReversedStream0(&obp, out, bit); 1523 1523 } 1524 1524 } 1525 1525 } ··· 1832 1832 } 1833 1833 decoder->infoPng.background_r = 1834 1834 decoder->infoPng.color.palette[(data[0]<<2)]; 1835 - 1835 + 1836 1836 decoder->infoPng.background_g = 1837 1837 decoder->infoPng.color.palette[(data[0]<<2) | 1]; 1838 1838 ··· 1880 1880 */ 1881 1881 decoder->error = 69; 1882 1882 break; 1883 - } 1883 + } 1884 1884 unknown = true; 1885 1885 } 1886 1886 ··· 2007 2007 decoder->error = 29; 2008 2008 return; 2009 2009 } 2010 - 2010 + 2011 2011 /* read the values given in the header */ 2012 2012 decoder->infoPng.width = in[16]<<24|in[17]<<16|in[18]<<8|in[19]; 2013 2013 decoder->infoPng.height = in[20]<<24|in[21]<<16|in[22]<<8|in[23]; ··· 2080 2080 /* one line more as temp buffer for conversion */ 2081 2081 #ifdef HAVE_LCD_COLOR 2082 2082 decoder->native_img_size = decoder->infoPng.width * 2083 - (decoder->infoPng.height)*FB_DATA_SZ; 2083 + decoder->infoPng.height * FB_DATA_SZ; 2084 2084 line_buf_size = decoder->infoPng.width * sizeof(struct uint8_rgb); 2085 2085 #else 2086 2086 decoder->native_img_size = decoder->infoPng.width * ··· 2134 2134 { 2135 2135 /* calculate 'corrected' image size */ 2136 2136 #ifdef HAVE_LCD_COLOR 2137 - c_native_img_size = dim_dst.width * 2138 - (dim_dst.height)*FB_DATA_SZ; 2137 + c_native_img_size = dim_dst.width * dim_dst.height * FB_DATA_SZ; 2139 2138 #else 2140 - c_native_img_size = dim_dst.width * 2141 - dim_dst.height; 2139 + c_native_img_size = dim_dst.width * dim_dst.height; 2142 2140 #endif 2143 2141 /* check memory constraints 2144 2142 * do the correction only if there is enough ··· 2165 2163 decoder->infoPng.width = img_dst.width; 2166 2164 decoder->infoPng.height = img_dst.height; 2167 2165 decoder->native_img_size = c_native_img_size; 2168 - 2166 + 2169 2167 /* copy back corrected image to the begining of the buffer */ 2170 2168 memcpy(img_src.data, img_dst.data, decoder->native_img_size); 2171 2169 } 2172 2170 } 2173 - 2174 2171 #endif /* (LCD_PIXEL_ASPECT_HEIGHT != 1 || LCD_PIXEL_ASPECT_WIDTH != 1) */ 2175 - time = *rb->current_tick - time; 2176 - if (pf_progress) pf_progress(100, 100); 2172 + 2173 + time = *rb->current_tick - time; 2174 + if (pf_progress) pf_progress(100, 100); 2177 2175 } 2178 2176 2179 2177 void LodePNG_Decoder_init(LodePNG_Decoder* decoder,
+2 -2
apps/plugins/imageviewer/png/tinflate.c
··· 148 148 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 149 149 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f}, 150 150 }, 151 - 151 + 152 152 .length_bits = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 153 153 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 154 154 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04, ··· 494 494 } 495 495 496 496 if (res != TINF_OK) return TINF_DATA_ERROR; 497 - 497 + 498 498 if (d.source > (unsigned char *)source + sourceLen) 499 499 return TINF_DATA_ERROR; 500 500 } while (!bfinal);