Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: third_party/libpng/pngrtran.c

Issue 2771903002: libpng: Optimize RGBA png_do_expand_palette
Patch Set: Correct potentially uninitialized loop variable Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/libpng/pngpriv.h ('k') | third_party/libpng/pngstruct.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* pngrtran.c - transforms the data in a row for PNG readers 2 /* pngrtran.c - transforms the data in a row for PNG readers
3 * 3 *
4 * Last changed in libpng 1.6.22 [May 26, 2016] 4 * Last changed in libpng 1.6.22 [May 26, 2016]
5 * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson 5 * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) 7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8 * 8 *
9 * This code is released under the libpng license. 9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer 10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h 11 * and license in png.h
12 * 12 *
13 * This file contains functions optionally called by an application 13 * This file contains functions optionally called by an application
14 * in order to tell libpng how to handle data when reading a PNG. 14 * in order to tell libpng how to handle data when reading a PNG.
15 * Transformations that are used in both reading and writing are 15 * Transformations that are used in both reading and writing are
16 * in pngtrans.c. 16 * in pngtrans.c.
17 */ 17 */
18 18
19 #include "pngpriv.h" 19 #include "pngpriv.h"
20 20
21 #ifdef PNG_ARM_NEON_IMPLEMENTATION
22 #if PNG_ARM_NEON_IMPLEMENTATION == 1
23 #define PNG_ARM_NEON_INTRINSICS_AVAILABLE
24 #include <arm_neon.h>
25 #endif
26 #endif
27
21 #ifdef PNG_READ_SUPPORTED 28 #ifdef PNG_READ_SUPPORTED
22 29
23 /* Set the action on getting a CRC error for an ancillary or critical chunk. */ 30 /* Set the action on getting a CRC error for an ancillary or critical chunk. */
24 void PNGAPI 31 void PNGAPI
25 png_set_crc_action(png_structrp png_ptr, int crit_action, int ancil_action) 32 png_set_crc_action(png_structrp png_ptr, int crit_action, int ancil_action)
26 { 33 {
27 png_debug(1, "in png_set_crc_action"); 34 png_debug(1, "in png_set_crc_action");
28 35
29 if (png_ptr == NULL) 36 if (png_ptr == NULL)
30 return; 37 return;
(...skipping 4156 matching lines...) Expand 10 before | Expand all | Expand 10 after
4187 */ 4194 */
4188 png_warning(png_ptr, "png_do_encode_alpha: unexpected call"); 4195 png_warning(png_ptr, "png_do_encode_alpha: unexpected call");
4189 } 4196 }
4190 #endif 4197 #endif
4191 4198
4192 #ifdef PNG_READ_EXPAND_SUPPORTED 4199 #ifdef PNG_READ_EXPAND_SUPPORTED
4193 /* Expands a palette row to an RGB or RGBA row depending 4200 /* Expands a palette row to an RGB or RGBA row depending
4194 * upon whether you supply trans and num_trans. 4201 * upon whether you supply trans and num_trans.
4195 */ 4202 */
4196 static void 4203 static void
4197 png_do_expand_palette(png_row_infop row_info, png_bytep row, 4204 png_do_expand_palette(png_structrp png_ptr, png_row_infop row_info,
4198 png_const_colorp palette, png_const_bytep trans_alpha, int num_trans) 4205 png_bytep row, png_const_colorp palette, png_const_bytep trans_alpha,
4206 int num_trans)
4199 { 4207 {
4200 int shift, value; 4208 int shift, value;
4201 png_bytep sp, dp; 4209 png_bytep sp, dp;
4202 png_uint_32 i; 4210 png_uint_32 i;
4203 png_uint_32 row_width=row_info->width; 4211 png_uint_32 row_width=row_info->width;
4204 4212
4205 png_debug(1, "in png_do_expand_palette"); 4213 png_debug(1, "in png_do_expand_palette");
4206 4214
4207 if (row_info->color_type == PNG_COLOR_TYPE_PALETTE) 4215 if (row_info->color_type == PNG_COLOR_TYPE_PALETTE)
4208 { 4216 {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
4292 } 4300 }
4293 4301
4294 if (row_info->bit_depth == 8) 4302 if (row_info->bit_depth == 8)
4295 { 4303 {
4296 { 4304 {
4297 if (num_trans > 0) 4305 if (num_trans > 0)
4298 { 4306 {
4299 sp = row + (png_size_t)row_width - 1; 4307 sp = row + (png_size_t)row_width - 1;
4300 dp = row + (png_size_t)(row_width << 2) - 1; 4308 dp = row + (png_size_t)(row_width << 2) - 1;
4301 4309
4302 for (i = 0; i < row_width; i++) 4310 i = 0;
4311 #ifdef PNG_ARM_NEON_INTRINSICS_AVAILABLE
4312 i = png_do_expand_palette_neon(png_ptr, row_info, row, &sp, &dp);
4313 #endif
4314
4315 for (; i < row_width; i++)
4303 { 4316 {
4304 if ((int)(*sp) >= num_trans) 4317 if ((int)(*sp) >= num_trans)
4305 *dp-- = 0xff; 4318 *dp-- = 0xff;
4306
4307 else 4319 else
4308 *dp-- = trans_alpha[*sp]; 4320 *dp-- = trans_alpha[*sp];
4309
4310 *dp-- = palette[*sp].blue; 4321 *dp-- = palette[*sp].blue;
4311 *dp-- = palette[*sp].green; 4322 *dp-- = palette[*sp].green;
4312 *dp-- = palette[*sp].red; 4323 *dp-- = palette[*sp].red;
4313 sp--; 4324 sp--;
4314 } 4325 }
4315 row_info->bit_depth = 8; 4326 row_info->bit_depth = 8;
4316 row_info->pixel_depth = 32; 4327 row_info->pixel_depth = 32;
4317 row_info->rowbytes = row_width * 4; 4328 row_info->rowbytes = row_width * 4;
4318 row_info->color_type = 6; 4329 row_info->color_type = 6;
4319 row_info->channels = 4; 4330 row_info->channels = 4;
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
4731 * This check added to libpng-1.2.19 (but not enabled until 1.5.4). 4742 * This check added to libpng-1.2.19 (but not enabled until 1.5.4).
4732 */ 4743 */
4733 png_error(png_ptr, "Uninitialized row"); 4744 png_error(png_ptr, "Uninitialized row");
4734 } 4745 }
4735 4746
4736 #ifdef PNG_READ_EXPAND_SUPPORTED 4747 #ifdef PNG_READ_EXPAND_SUPPORTED
4737 if ((png_ptr->transformations & PNG_EXPAND) != 0) 4748 if ((png_ptr->transformations & PNG_EXPAND) != 0)
4738 { 4749 {
4739 if (row_info->color_type == PNG_COLOR_TYPE_PALETTE) 4750 if (row_info->color_type == PNG_COLOR_TYPE_PALETTE)
4740 { 4751 {
4741 png_do_expand_palette(row_info, png_ptr->row_buf + 1, 4752 #ifdef PNG_ARM_NEON_INTRINSICS_AVAILABLE
4742 png_ptr->palette, png_ptr->trans_alpha, png_ptr->num_trans); 4753 /* Allocate space for the decompressed full palette. */
4754 if (png_ptr->row_tmp_palette == NULL) {
4755 png_ptr->row_tmp_palette = png_calloc(png_ptr, 256*4);
4756 if (png_ptr->row_tmp_palette == NULL) {
4757 png_error(png_ptr, "NULL row buffer");
4758 }
4759 /* Build the RGBA palette. */
4760 png_riffle_palette(png_ptr, row_info);
4761 }
4762 #endif
4763 png_do_expand_palette(png_ptr, row_info, png_ptr->row_buf + 1,
4764 png_ptr->palette, png_ptr->trans_alpha, png_ptr->num_trans);
4743 } 4765 }
4744 4766
4745 else 4767 else
4746 { 4768 {
4747 if (png_ptr->num_trans != 0 && 4769 if (png_ptr->num_trans != 0 &&
4748 (png_ptr->transformations & PNG_EXPAND_tRNS) != 0) 4770 (png_ptr->transformations & PNG_EXPAND_tRNS) != 0)
4749 png_do_expand(row_info, png_ptr->row_buf + 1, 4771 png_do_expand(row_info, png_ptr->row_buf + 1,
4750 &(png_ptr->trans_color)); 4772 &(png_ptr->trans_color));
4751 4773
4752 else 4774 else
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
4991 row_info->pixel_depth = (png_byte)(row_info->bit_depth * 5013 row_info->pixel_depth = (png_byte)(row_info->bit_depth *
4992 row_info->channels); 5014 row_info->channels);
4993 5015
4994 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_info->width); 5016 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_info->width);
4995 } 5017 }
4996 #endif 5018 #endif
4997 } 5019 }
4998 5020
4999 #endif /* READ_TRANSFORMS */ 5021 #endif /* READ_TRANSFORMS */
5000 #endif /* READ */ 5022 #endif /* READ */
OLDNEW
« no previous file with comments | « third_party/libpng/pngpriv.h ('k') | third_party/libpng/pngstruct.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698