Browse Source

engine: common: imagelib: img_png.c: unroll loops.

pull/2/head
Andrey Akhmichin 2 years ago committed by Alibek Omarov
parent
commit
d237114962
  1. 31
      engine/common/imagelib/img_png.c

31
engine/common/imagelib/img_png.c

@ -41,10 +41,10 @@ qboolean Image_LoadPNG( const char *name, const byte *buffer, fs_offset_t filesi
{ {
int ret; int ret;
short p, a, b, c, pa, pb, pc; short p, a, b, c, pa, pb, pc;
byte *buf_p, *pixbuf, *raw, *prior, *idat_buf = NULL, *uncompressed_buffer = NULL, *rowend; byte *buf_p, *pixbuf, *raw, *prior, *idat_buf = NULL, *uncompressed_buffer = NULL;
byte *pallete = NULL, *trns = NULL; byte *pallete = NULL, *trns = NULL;
uint chunk_len, trns_len, crc32, crc32_check, oldsize = 0, newsize = 0, rowsize; uint chunk_len, trns_len, crc32, crc32_check, oldsize = 0, newsize = 0, rowsize;
uint uncompressed_size, pixel_size, i, y, filter_type, chunk_sign, r_alpha, g_alpha, b_alpha; uint uncompressed_size, pixel_size, pixel_count, i, y, filter_type, chunk_sign, r_alpha, g_alpha, b_alpha;
qboolean has_iend_chunk = false; qboolean has_iend_chunk = false;
z_stream stream = {0}; z_stream stream = {0};
png_t png_hdr; png_t png_hdr;
@ -262,7 +262,8 @@ qboolean Image_LoadPNG( const char *name, const byte *buffer, fs_offset_t filesi
image.type = PF_RGBA_32; // always exctracted to 32-bit buffer image.type = PF_RGBA_32; // always exctracted to 32-bit buffer
image.width = png_hdr.ihdr_chunk.width; image.width = png_hdr.ihdr_chunk.width;
image.height = png_hdr.ihdr_chunk.height; image.height = png_hdr.ihdr_chunk.height;
image.size = image.height * image.width * 4; pixel_count = image.height * image.width;
image.size = pixel_count * 4;
if( png_hdr.ihdr_chunk.colortype & PNG_CT_RGB ) if( png_hdr.ihdr_chunk.colortype & PNG_CT_RGB )
image.flags |= IMAGE_HAS_COLOR; image.flags |= IMAGE_HAS_COLOR;
@ -424,10 +425,7 @@ qboolean Image_LoadPNG( const char *name, const byte *buffer, fs_offset_t filesi
b_alpha = trns[4] << 8 | trns[5]; b_alpha = trns[4] << 8 | trns[5];
} }
for( y = 0; y < image.height; y++ ) for( y = 0; y < pixel_count; y++, raw += pixel_size )
{
rowend = raw + rowsize;
for( ; raw < rowend; raw += pixel_size )
{ {
*pixbuf++ = raw[0]; *pixbuf++ = raw[0];
*pixbuf++ = raw[1]; *pixbuf++ = raw[1];
@ -440,16 +438,12 @@ qboolean Image_LoadPNG( const char *name, const byte *buffer, fs_offset_t filesi
else else
*pixbuf++ = 0xFF; *pixbuf++ = 0xFF;
} }
}
break; break;
case PNG_CT_GREY: case PNG_CT_GREY:
if( trns ) if( trns )
r_alpha = trns[0] << 8 | trns[1]; r_alpha = trns[0] << 8 | trns[1];
for( y = 0; y < image.height; y++ ) for( y = 0; y < pixel_count; y++, raw += pixel_size )
{
rowend = raw + rowsize;
for( ; raw < rowend; raw += pixel_size )
{ {
*pixbuf++ = raw[0]; *pixbuf++ = raw[0];
*pixbuf++ = raw[0]; *pixbuf++ = raw[0];
@ -460,26 +454,18 @@ qboolean Image_LoadPNG( const char *name, const byte *buffer, fs_offset_t filesi
else else
*pixbuf++ = 0xFF; *pixbuf++ = 0xFF;
} }
}
break; break;
case PNG_CT_ALPHA: case PNG_CT_ALPHA:
for( y = 0; y < image.height; y++ ) for( y = 0; y < pixel_count; y++, raw += pixel_size )
{
rowend = raw + rowsize;
for( ; raw < rowend; raw += pixel_size )
{ {
*pixbuf++ = raw[0]; *pixbuf++ = raw[0];
*pixbuf++ = raw[0]; *pixbuf++ = raw[0];
*pixbuf++ = raw[0]; *pixbuf++ = raw[0];
*pixbuf++ = raw[1]; *pixbuf++ = raw[1];
} }
}
break; break;
case PNG_CT_PALLETE: case PNG_CT_PALLETE:
for( y = 0; y < image.height; y++ ) for( y = 0; y < pixel_count; y++, raw += pixel_size )
{
rowend = raw + rowsize;
for( ; raw < rowend; raw += pixel_size )
{ {
*pixbuf++ = pallete[raw[0] + 2]; *pixbuf++ = pallete[raw[0] + 2];
*pixbuf++ = pallete[raw[0] + 1]; *pixbuf++ = pallete[raw[0] + 1];
@ -490,7 +476,6 @@ qboolean Image_LoadPNG( const char *name, const byte *buffer, fs_offset_t filesi
else else
*pixbuf++ = 0xFF; *pixbuf++ = 0xFF;
} }
}
break; break;
default: default:
break; break;

Loading…
Cancel
Save