mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
Imported from libpng-1.0.5-pre1.tar
This commit is contained in:
174
pngvcrd.c
174
pngvcrd.c
@@ -2,7 +2,7 @@
|
||||
*
|
||||
* For Intel x86 CPU and Microsoft Visual C++ compiler
|
||||
*
|
||||
* libpng 1.0.4f - October 12, 1999
|
||||
* libpng 1.0.5 - October 5, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1998, Intel Corporation
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
@@ -26,6 +26,7 @@ png_read_filter_row_c(png_structp png_ptr, png_row_infop row_info,
|
||||
static int mmxsupport()
|
||||
{
|
||||
int mmx_supported_local = 0;
|
||||
|
||||
_asm {
|
||||
pushfd //Save Eflag to stack
|
||||
pop eax //Get Eflag from stack into eax
|
||||
@@ -90,19 +91,19 @@ NOT_SUPPORTED:
|
||||
void
|
||||
png_combine_row(png_structp png_ptr, png_bytep row, int mask)
|
||||
{
|
||||
#ifdef DISABLE_PNGVCRD_COMBINE
|
||||
#ifndef MMX_BUG_IS_FIXED
|
||||
int save_mmx_supported = mmx_supported;
|
||||
#endif
|
||||
|
||||
png_debug(1,"in png_combine_row_asm\n");
|
||||
|
||||
#ifdef DISABLE_PNGVCRD_COMBINE
|
||||
#ifndef MMX_BUG_IS_FIXED
|
||||
if ((png_ptr->transformations & PNG_INTERLACE) && png_ptr->pass != 6)
|
||||
mmx_supported = 0;
|
||||
else
|
||||
#endif
|
||||
if (mmx_supported == 2)
|
||||
mmx_supported = mmxsupport();
|
||||
if (mmx_supported == 2)
|
||||
mmx_supported = mmxsupport();
|
||||
|
||||
if (mask == 0xff)
|
||||
{
|
||||
@@ -947,7 +948,7 @@ end48:
|
||||
} /* end switch (png_ptr->row_info.pixel_depth) */
|
||||
} /* end if (non-trivial mask) */
|
||||
|
||||
#ifdef DISABLE_PNGVCRD_COMBINE
|
||||
#ifndef MMX_BUG_IS_FIXED
|
||||
mmx_supported = save_mmx_supported;
|
||||
#endif
|
||||
|
||||
@@ -960,27 +961,18 @@ void
|
||||
png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
||||
png_uint_32 transformations)
|
||||
{
|
||||
#ifdef DISABLE_PNGVCRD_INTERLACE
|
||||
#ifndef MMX_BUG_IS_FIXED
|
||||
int save_mmx_supported = mmx_supported;
|
||||
#endif
|
||||
|
||||
png_debug(1,"in png_do_read_interlace\n");
|
||||
|
||||
#ifdef DISABLE_PNGVCRD_INTERLACE
|
||||
/* In libpng versions 1.0.3a through 1.0.4d,
|
||||
* a sign error in the post-MMX cleanup code for each pixel_depth resulted
|
||||
* in bad pixels at the beginning of some rows of some images, and also
|
||||
* (due to out-of-range memory reads and writes) caused heap corruption
|
||||
* when compiled with MSVC 6.0. The error was fixed in version 1.0.4e,
|
||||
* and the code appears to work completely correctly, so it is enabled
|
||||
* by default.
|
||||
*/
|
||||
if (1) /* all passes caused a heap problem in the old code */
|
||||
mmx_supported = 0;
|
||||
else
|
||||
#ifndef MMX_BUG_IS_FIXED
|
||||
mmx_supported = 0;
|
||||
#else
|
||||
if (mmx_supported == 2)
|
||||
mmx_supported = mmxsupport();
|
||||
#endif
|
||||
if (mmx_supported == 2)
|
||||
mmx_supported = mmxsupport();
|
||||
|
||||
if (row != NULL && row_info != NULL)
|
||||
{
|
||||
@@ -1163,20 +1155,21 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
||||
default: // This is the place where the routine is modified
|
||||
{
|
||||
__int64 const4 = 0x0000000000FFFFFF;
|
||||
// __int64 const5 = 0x000000FFFFFF0000; // unused...
|
||||
__int64 const5 = 0x000000FFFFFF0000;
|
||||
__int64 const6 = 0x00000000000000FF;
|
||||
//int mmx_supported = 1;
|
||||
|
||||
png_bytep sptr, dp;
|
||||
png_uint_32 i;
|
||||
png_size_t pixel_bytes;
|
||||
|
||||
int width = row_info->width;
|
||||
|
||||
pixel_bytes = (row_info->pixel_depth >> 3);
|
||||
|
||||
sptr = row + (width - 1) * pixel_bytes;
|
||||
sptr = row + (row_info->width - 1) * pixel_bytes;
|
||||
dp = row + (final_width - 1) * pixel_bytes;
|
||||
// New code by Nirav Chhatrapati - Intel Corporation
|
||||
// sign fix by GRR
|
||||
// NOTE: there is NO MMX code for 48-bit and 64-bit images
|
||||
|
||||
if (mmx_supported) // use MMX routine if machine supports it
|
||||
{
|
||||
@@ -1343,29 +1336,16 @@ loop1_pass0:
|
||||
dp -= width_mmx*8;
|
||||
for (i = width; i; i--)
|
||||
{
|
||||
png_byte v[8];
|
||||
int j;
|
||||
|
||||
/* I simplified this part in version 1.0.4e
|
||||
* here and in several other instances where
|
||||
* pixel_bytes == 1 -- GR-P
|
||||
*
|
||||
* Original code:
|
||||
*
|
||||
* png_byte v[8];
|
||||
* png_memcpy(v, sptr, pixel_bytes);
|
||||
* for (j = 0; j < png_pass_inc[pass]; j++)
|
||||
* {
|
||||
* png_memcpy(dp, v, pixel_bytes);
|
||||
* dp -= pixel_bytes;
|
||||
* }
|
||||
* sptr -= pixel_bytes;
|
||||
*
|
||||
* Replacement code is in the next three lines:
|
||||
*/
|
||||
|
||||
png_memcpy(v, sptr, pixel_bytes);
|
||||
for (j = 0; j < png_pass_inc[pass]; j++)
|
||||
*dp-- = *sptr;
|
||||
sptr--;
|
||||
{
|
||||
png_memcpy(dp, v, pixel_bytes);
|
||||
dp -= pixel_bytes;
|
||||
}
|
||||
sptr -= pixel_bytes;
|
||||
}
|
||||
}
|
||||
else if ((pass == 2) || (pass == 3))
|
||||
@@ -1401,13 +1381,16 @@ loop1_pass2:
|
||||
dp -= width_mmx*4;
|
||||
for (i = width; i; i--)
|
||||
{
|
||||
png_byte v[8];
|
||||
int j;
|
||||
|
||||
png_memcpy(v, sptr, pixel_bytes);
|
||||
for (j = 0; j < png_pass_inc[pass]; j++)
|
||||
{
|
||||
*dp-- = *sptr;
|
||||
png_memcpy(dp, v, pixel_bytes);
|
||||
dp -= pixel_bytes;
|
||||
}
|
||||
sptr --;
|
||||
sptr -= pixel_bytes;
|
||||
}
|
||||
}
|
||||
else //if ((pass == 4) || (pass == 5))
|
||||
@@ -1444,13 +1427,16 @@ loop1_pass4:
|
||||
dp -= width_mmx*2;
|
||||
for (i = width; i; i--)
|
||||
{
|
||||
png_byte v[8];
|
||||
int j;
|
||||
|
||||
png_memcpy(v, sptr, pixel_bytes);
|
||||
for (j = 0; j < png_pass_inc[pass]; j++)
|
||||
{
|
||||
*dp-- = *sptr;
|
||||
png_memcpy(dp, v, pixel_bytes);
|
||||
dp -= pixel_bytes;
|
||||
}
|
||||
sptr --;
|
||||
sptr -= pixel_bytes;
|
||||
}
|
||||
}
|
||||
} /* end of pixel_bytes == 1 */
|
||||
@@ -1488,8 +1474,8 @@ loop2_pass0:
|
||||
}
|
||||
}
|
||||
|
||||
sptr -= (width_mmx*2 - 2); // sign fixed
|
||||
dp -= (width_mmx*16 - 2); // sign fixed
|
||||
sptr -= (width_mmx*2 + 2);
|
||||
dp -= (width_mmx*16 + 2);
|
||||
for (i = width; i; i--)
|
||||
{
|
||||
png_byte v[8];
|
||||
@@ -1500,7 +1486,9 @@ loop2_pass0:
|
||||
{
|
||||
dp -= pixel_bytes;
|
||||
png_memcpy(dp, v, pixel_bytes);
|
||||
//dp -= pixel_bytes;
|
||||
}
|
||||
//sptr -= pixel_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1534,8 +1522,8 @@ loop2_pass2:
|
||||
}
|
||||
}
|
||||
|
||||
sptr -= (width_mmx*2 - 2); // sign fixed
|
||||
dp -= (width_mmx*8 - 2); // sign fixed
|
||||
sptr -= (width_mmx*2 + 2);
|
||||
dp -= (width_mmx*8 + 2);
|
||||
for (i = width; i; i--)
|
||||
{
|
||||
png_byte v[8];
|
||||
@@ -1546,7 +1534,9 @@ loop2_pass2:
|
||||
{
|
||||
dp -= pixel_bytes;
|
||||
png_memcpy(dp, v, pixel_bytes);
|
||||
//dp -= pixel_bytes;
|
||||
}
|
||||
//sptr -= pixel_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1575,8 +1565,8 @@ loop2_pass4:
|
||||
}
|
||||
}
|
||||
|
||||
sptr -= (width_mmx*2 - 2); // sign fixed
|
||||
dp -= (width_mmx*4 - 2); // sign fixed
|
||||
sptr -= (width_mmx*2 + 2);
|
||||
dp -= (width_mmx*4 + 2);
|
||||
for (i = width; i; i--)
|
||||
{
|
||||
png_byte v[8];
|
||||
@@ -1587,7 +1577,9 @@ loop2_pass4:
|
||||
{
|
||||
dp -= pixel_bytes;
|
||||
png_memcpy(dp, v, pixel_bytes);
|
||||
//dp -= pixel_bytes;
|
||||
}
|
||||
//sptr -= pixel_bytes;
|
||||
}
|
||||
}
|
||||
} /* end of pixel_bytes == 2 */
|
||||
@@ -1628,8 +1620,8 @@ loop4_pass0:
|
||||
}
|
||||
}
|
||||
|
||||
sptr -= (width_mmx*4 - 4); // sign fixed
|
||||
dp -= (width_mmx*32 - 4); // sign fixed
|
||||
sptr -= (width_mmx*4 + 4);
|
||||
dp -= (width_mmx*32 + 4);
|
||||
for (i = width; i; i--)
|
||||
{
|
||||
png_byte v[8];
|
||||
@@ -1640,7 +1632,9 @@ loop4_pass0:
|
||||
{
|
||||
dp -= pixel_bytes;
|
||||
png_memcpy(dp, v, pixel_bytes);
|
||||
//dp -= pixel_bytes;
|
||||
}
|
||||
//sptr -= pixel_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1674,8 +1668,8 @@ loop4_pass2:
|
||||
}
|
||||
}
|
||||
|
||||
sptr -= (width_mmx*4 - 4); // sign fixed
|
||||
dp -= (width_mmx*16 - 4); // sign fixed
|
||||
sptr -= (width_mmx*4 + 4);
|
||||
dp -= (width_mmx*16 + 4);
|
||||
for (i = width; i; i--)
|
||||
{
|
||||
png_byte v[8];
|
||||
@@ -1686,7 +1680,9 @@ loop4_pass2:
|
||||
{
|
||||
dp -= pixel_bytes;
|
||||
png_memcpy(dp, v, pixel_bytes);
|
||||
//dp -= pixel_bytes;
|
||||
}
|
||||
//sptr -= pixel_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1718,8 +1714,8 @@ loop4_pass4:
|
||||
}
|
||||
}
|
||||
|
||||
sptr -= (width_mmx*4 - 4); // sign fixed
|
||||
dp -= (width_mmx*8 - 4); // sign fixed
|
||||
sptr -= (width_mmx*4 + 4);
|
||||
dp -= (width_mmx*8 + 4);
|
||||
for (i = width; i; i--)
|
||||
{
|
||||
png_byte v[8];
|
||||
@@ -1730,7 +1726,9 @@ loop4_pass4:
|
||||
{
|
||||
dp -= pixel_bytes;
|
||||
png_memcpy(dp, v, pixel_bytes);
|
||||
//dp -= pixel_bytes;
|
||||
}
|
||||
//sptr -= pixel_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1738,7 +1736,7 @@ loop4_pass4:
|
||||
|
||||
else if (pixel_bytes == 6)
|
||||
{
|
||||
for (i = width; i; i--)
|
||||
for (i = row_info->width; i; i--)
|
||||
{
|
||||
png_byte v[8];
|
||||
int j;
|
||||
@@ -1754,7 +1752,7 @@ loop4_pass4:
|
||||
|
||||
else
|
||||
{
|
||||
for (i = width; i; i--)
|
||||
for (i = row_info->width; i; i--)
|
||||
{
|
||||
png_byte v[8];
|
||||
int j;
|
||||
@@ -1774,17 +1772,23 @@ loop4_pass4:
|
||||
{
|
||||
if (pixel_bytes == 1)
|
||||
{
|
||||
for (i = width; i; i--)
|
||||
for (i = row_info->width; i; i--)
|
||||
{
|
||||
png_byte v[8];
|
||||
int j;
|
||||
|
||||
png_memcpy(v, sptr, pixel_bytes);
|
||||
for (j = 0; j < png_pass_inc[pass]; j++)
|
||||
*dp-- = *sptr;
|
||||
sptr--;
|
||||
{
|
||||
png_memcpy(dp, v, pixel_bytes);
|
||||
dp -= pixel_bytes;
|
||||
}
|
||||
sptr -= pixel_bytes;
|
||||
}
|
||||
}
|
||||
else if (pixel_bytes == 3)
|
||||
{
|
||||
for (i = width; i; i--)
|
||||
for (i = row_info->width; i; i--)
|
||||
{
|
||||
png_byte v[8];
|
||||
int j;
|
||||
@@ -1799,7 +1803,7 @@ loop4_pass4:
|
||||
}
|
||||
else if (pixel_bytes == 2)
|
||||
{
|
||||
for (i = width; i; i--)
|
||||
for (i = row_info->width; i; i--)
|
||||
{
|
||||
png_byte v[8];
|
||||
int j;
|
||||
@@ -1814,7 +1818,7 @@ loop4_pass4:
|
||||
}
|
||||
else if (pixel_bytes == 4)
|
||||
{
|
||||
for (i = width; i; i--)
|
||||
for (i = row_info->width; i; i--)
|
||||
{
|
||||
png_byte v[8];
|
||||
int j;
|
||||
@@ -1829,7 +1833,7 @@ loop4_pass4:
|
||||
}
|
||||
else if (pixel_bytes == 6)
|
||||
{
|
||||
for (i = width; i; i--)
|
||||
for (i = row_info->width; i; i--)
|
||||
{
|
||||
png_byte v[8];
|
||||
int j;
|
||||
@@ -1844,7 +1848,7 @@ loop4_pass4:
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = width; i; i--)
|
||||
for (i = row_info->width; i; i--)
|
||||
{
|
||||
png_byte v[8];
|
||||
int j;
|
||||
@@ -1868,7 +1872,7 @@ loop4_pass4:
|
||||
(png_uint_32)row_info->pixel_depth + 7) >> 3);
|
||||
}
|
||||
|
||||
#ifdef DISABLE_PNGVCRD_INTERLACE
|
||||
#ifndef MMX_BUG_IS_FIXED
|
||||
mmx_supported = save_mmx_supported;
|
||||
#endif
|
||||
}
|
||||
@@ -3643,7 +3647,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
|
||||
#ifdef PNG_DEBUG
|
||||
char filnm[6];
|
||||
#endif
|
||||
#define UseMMX 1
|
||||
#define UseMMX (1)
|
||||
|
||||
if (mmx_supported == 2)
|
||||
mmx_supported = mmxsupport();
|
||||
@@ -3656,11 +3660,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
|
||||
|
||||
#ifdef PNG_DEBUG
|
||||
png_debug(1, "in png_read_filter_row\n");
|
||||
#if (UseMMX == 1)
|
||||
png_debug1(0,"%s, ", "MMX");
|
||||
#else
|
||||
png_debug1(0,"%s, ", "x86");
|
||||
#endif
|
||||
png_debug1(0,"%s, ", (UseMMX?"MMX":"x86"));
|
||||
switch (filter)
|
||||
{
|
||||
case 0: sprintf(filnm, "None ");
|
||||
@@ -3688,14 +3688,12 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
|
||||
break;
|
||||
case PNG_FILTER_VALUE_SUB:
|
||||
{
|
||||
#if (UseMMX == 1)
|
||||
if ((row_info->pixel_depth > 8) &&
|
||||
if ( UseMMX && (row_info->pixel_depth > 8) &&
|
||||
(row_info->rowbytes >= 128) )
|
||||
{
|
||||
png_read_filter_row_mmx_sub(row_info, row);
|
||||
}
|
||||
} //end if UseMMX
|
||||
else
|
||||
#endif
|
||||
{
|
||||
png_uint_32 i;
|
||||
png_uint_32 istop = row_info->rowbytes;
|
||||
@@ -3713,14 +3711,12 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
|
||||
}
|
||||
case PNG_FILTER_VALUE_UP:
|
||||
{
|
||||
#if (UseMMX == 1)
|
||||
if ((row_info->pixel_depth > 8) &&
|
||||
if ( UseMMX && (row_info->pixel_depth > 8) &&
|
||||
(row_info->rowbytes >= 128) )
|
||||
{
|
||||
png_read_filter_row_mmx_up(row_info, row, prev_row);
|
||||
} //end if UseMMX
|
||||
else
|
||||
#endif
|
||||
{
|
||||
png_bytep rp;
|
||||
png_bytep pp;
|
||||
@@ -3735,14 +3731,12 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
|
||||
}
|
||||
case PNG_FILTER_VALUE_AVG:
|
||||
{
|
||||
#if (UseMMX == 1)
|
||||
if ((row_info->pixel_depth > 8) &&
|
||||
if ( UseMMX && (row_info->pixel_depth > 8) &&
|
||||
(row_info->rowbytes >= 128) )
|
||||
{
|
||||
png_read_filter_row_mmx_avg(row_info, row, prev_row);
|
||||
} //end if UseMMX
|
||||
else
|
||||
#endif
|
||||
{
|
||||
png_uint_32 i;
|
||||
png_bytep rp = row;
|
||||
@@ -3769,14 +3763,12 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
|
||||
}
|
||||
case PNG_FILTER_VALUE_PAETH:
|
||||
{
|
||||
#if (UseMMX == 1)
|
||||
if ((row_info->pixel_depth > 8) &&
|
||||
if ( UseMMX && (row_info->pixel_depth > 8) &&
|
||||
(row_info->rowbytes >= 128) )
|
||||
{
|
||||
png_read_filter_row_mmx_paeth(row_info, row, prev_row);
|
||||
} //end if UseMMX
|
||||
else
|
||||
#endif
|
||||
{
|
||||
png_uint_32 i;
|
||||
png_bytep rp = row;
|
||||
|
||||
Reference in New Issue
Block a user