repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | readpng2_init | int readpng2_init(mainprog_info *mainprog_ptr)
{
png_structp png_ptr; /* note: temporary variables! */
png_infop info_ptr;
/* could also replace libpng warning-handler (final NULL), but no need: */
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr,
readpng2_error_handler, NULL);
if (!png_ptr)
return 4; /* out of memory */
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_read_struct(&png_ptr, NULL, NULL);
return 4; /* out of memory */
}
/* we could create a second info struct here (end_info), but it's only
* useful if we want to keep pre- and post-IDAT chunk info separated
* (mainly for PNG-aware image editors and converters) */
/* setjmp() must be called in every function that calls a PNG-reading
* libpng function, unless an alternate error handler was installed--
* but compatible error handlers must either use longjmp() themselves
* (as in this program) or exit immediately, so here we are: */
if (setjmp(mainprog_ptr->jmpbuf)) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return 2;
}
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
/* prepare the reader to ignore all recognized chunks whose data won't be
* used, i.e., all chunks recognized by libpng except for IHDR, PLTE, IDAT,
* IEND, tRNS, bKGD, gAMA, and sRGB (small performance improvement) */
{
/* These byte strings were copied from png.h. If a future version
* of readpng2.c recognizes more chunks, add them to this list.
*/
static PNG_CONST png_byte chunks_to_process[] = {
98, 75, 71, 68, '\0', /* bKGD */
103, 65, 77, 65, '\0', /* gAMA */
115, 82, 71, 66, '\0', /* sRGB */
};
/* Ignore all chunks except for IHDR, PLTE, tRNS, IDAT, and IEND */
png_set_keep_unknown_chunks(png_ptr, -1 /* PNG_HANDLE_CHUNK_NEVER */,
NULL, -1);
/* But do not ignore chunks in the "chunks_to_process" list */
png_set_keep_unknown_chunks(png_ptr,
0 /* PNG_HANDLE_CHUNK_AS_DEFAULT */, chunks_to_process,
sizeof(chunks_to_process)/5);
}
#endif /* PNG_HANDLE_AS_UNKNOWN_SUPPORTED */
/* instead of doing png_init_io() here, now we set up our callback
* functions for progressive decoding */
png_set_progressive_read_fn(png_ptr, mainprog_ptr,
readpng2_info_callback, readpng2_row_callback, readpng2_end_callback);
/* make sure we save our pointers for use in readpng2_decode_data() */
mainprog_ptr->png_ptr = png_ptr;
mainprog_ptr->info_ptr = info_ptr;
/* and that's all there is to initialization */
return 0;
} | /* returns 0 for success, 2 for libpng problem, 4 for out of memory */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/gregbook/readpng2.c#L98-L176 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | readpng2_decode_data | int readpng2_decode_data(mainprog_info *mainprog_ptr, uch *rawbuf, ulg length)
{
png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
/* setjmp() must be called in every function that calls a PNG-reading
* libpng function */
if (setjmp(mainprog_ptr->jmpbuf)) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
mainprog_ptr->png_ptr = NULL;
mainprog_ptr->info_ptr = NULL;
return 2;
}
/* hand off the next chunk of input data to libpng for decoding */
png_process_data(png_ptr, info_ptr, rawbuf, length);
return 0;
} | /* returns 0 for success, 2 for libpng (longjmp) problem */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/gregbook/readpng2.c#L183-L205 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | readpng_init | int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight)
{
static uch ppmline[256];
int maxval;
saved_infile = infile;
fgets(ppmline, 256, infile);
if (ppmline[0] != 'P' || ppmline[1] != '6') {
fprintf(stderr, "ERROR: not a PPM file\n");
return 1;
}
/* possible color types: P5 = grayscale (0), P6 = RGB (2), P8 = RGBA (6) */
if (ppmline[1] == '6') {
color_type = 2;
channels = 3;
} else if (ppmline[1] == '8') {
color_type = 6;
channels = 4;
} else /* if (ppmline[1] == '5') */ {
color_type = 0;
channels = 1;
}
do {
fgets(ppmline, 256, infile);
} while (ppmline[0] == '#');
sscanf(ppmline, "%lu %lu", &width, &height);
do {
fgets(ppmline, 256, infile);
} while (ppmline[0] == '#');
sscanf(ppmline, "%d", &maxval);
if (maxval != 255) {
fprintf(stderr, "ERROR: maxval = %d\n", maxval);
return 2;
}
bit_depth = 8;
*pWidth = width;
*pHeight = height;
return 0;
} | /* return value = 0 for success, 1 for bad sig, 2 for bad IHDR, 4 for no mem */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/gregbook/readppm.c#L81-L125 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | readpng_get_bgcolor | int readpng_get_bgcolor(uch *red, uch *green, uch *blue)
{
return 1;
} | /* returns 0 if succeeds, 1 if fails due to no bKGD chunk, 2 if libpng error;
* scales values to 8-bit if necessary */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/gregbook/readppm.c#L133-L136 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | rpng2_win_init | static void rpng2_win_init()
{
ulg i;
ulg rowbytes = rpng2_info.rowbytes;
Trace((stderr, "beginning rpng2_win_init()\n"))
Trace((stderr, " rowbytes = %d\n", rpng2_info.rowbytes))
Trace((stderr, " width = %ld\n", rpng2_info.width))
Trace((stderr, " height = %ld\n", rpng2_info.height))
rpng2_info.image_data = (uch *)malloc(rowbytes * rpng2_info.height);
if (!rpng2_info.image_data) {
readpng2_cleanup(&rpng2_info);
return;
}
rpng2_info.row_pointers = (uch **)malloc(rpng2_info.height * sizeof(uch *));
if (!rpng2_info.row_pointers) {
free(rpng2_info.image_data);
rpng2_info.image_data = NULL;
readpng2_cleanup(&rpng2_info);
return;
}
for (i = 0; i < rpng2_info.height; ++i)
rpng2_info.row_pointers[i] = rpng2_info.image_data + i*rowbytes;
/*---------------------------------------------------------------------------
Do the basic Windows initialization stuff, make the window, and fill it
with the user-specified, file-specified or default background color.
---------------------------------------------------------------------------*/
if (rpng2_win_create_window()) {
readpng2_cleanup(&rpng2_info);
return;
}
rpng2_info.state = kWindowInit;
} | /* this function is called by readpng2_info_callback() in readpng2.c, which
* in turn is called by libpng after all of the pre-IDAT chunks have been
* read and processed--i.e., we now have enough info to finish initializing */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/gregbook/rpng2-win.c#L641-L679 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | rpng2_win_load_bg_image | static int rpng2_win_load_bg_image()
{
uch *src, *dest;
uch r1, r2, g1, g2, b1, b2;
uch r1_inv, r2_inv, g1_inv, g2_inv, b1_inv, b2_inv;
int k, hmax, max;
int xidx, yidx, yidx_max = (bgscale-1);
int even_odd_vert, even_odd_horiz, even_odd;
int invert_gradient2 = (bg[pat].type & 0x08);
int invert_column;
ulg i, row;
/*---------------------------------------------------------------------------
Allocate buffer for fake background image to be used with transparent
images; if this fails, revert to plain background color.
---------------------------------------------------------------------------*/
bg_rowbytes = 3 * rpng2_info.width;
bg_data = (uch *)malloc(bg_rowbytes * rpng2_info.height);
if (!bg_data) {
fprintf(stderr, PROGNAME
": unable to allocate memory for background image\n");
bg_image = 0;
return 1;
}
/*---------------------------------------------------------------------------
Vertical gradients (ramps) in NxN squares, alternating direction and
colors (N == bgscale).
---------------------------------------------------------------------------*/
if ((bg[pat].type & 0x07) == 0) {
uch r1_min = rgb[bg[pat].rgb1_min].r;
uch g1_min = rgb[bg[pat].rgb1_min].g;
uch b1_min = rgb[bg[pat].rgb1_min].b;
uch r2_min = rgb[bg[pat].rgb2_min].r;
uch g2_min = rgb[bg[pat].rgb2_min].g;
uch b2_min = rgb[bg[pat].rgb2_min].b;
int r1_diff = rgb[bg[pat].rgb1_max].r - r1_min;
int g1_diff = rgb[bg[pat].rgb1_max].g - g1_min;
int b1_diff = rgb[bg[pat].rgb1_max].b - b1_min;
int r2_diff = rgb[bg[pat].rgb2_max].r - r2_min;
int g2_diff = rgb[bg[pat].rgb2_max].g - g2_min;
int b2_diff = rgb[bg[pat].rgb2_max].b - b2_min;
for (row = 0; row < rpng2_info.height; ++row) {
yidx = row % bgscale;
even_odd_vert = (row / bgscale) & 1;
r1 = r1_min + (r1_diff * yidx) / yidx_max;
g1 = g1_min + (g1_diff * yidx) / yidx_max;
b1 = b1_min + (b1_diff * yidx) / yidx_max;
r1_inv = r1_min + (r1_diff * (yidx_max-yidx)) / yidx_max;
g1_inv = g1_min + (g1_diff * (yidx_max-yidx)) / yidx_max;
b1_inv = b1_min + (b1_diff * (yidx_max-yidx)) / yidx_max;
r2 = r2_min + (r2_diff * yidx) / yidx_max;
g2 = g2_min + (g2_diff * yidx) / yidx_max;
b2 = b2_min + (b2_diff * yidx) / yidx_max;
r2_inv = r2_min + (r2_diff * (yidx_max-yidx)) / yidx_max;
g2_inv = g2_min + (g2_diff * (yidx_max-yidx)) / yidx_max;
b2_inv = b2_min + (b2_diff * (yidx_max-yidx)) / yidx_max;
dest = bg_data + row*bg_rowbytes;
for (i = 0; i < rpng2_info.width; ++i) {
even_odd_horiz = (i / bgscale) & 1;
even_odd = even_odd_vert ^ even_odd_horiz;
invert_column =
(even_odd_horiz && (bg[pat].type & 0x10));
if (even_odd == 0) { /* gradient #1 */
if (invert_column) {
*dest++ = r1_inv;
*dest++ = g1_inv;
*dest++ = b1_inv;
} else {
*dest++ = r1;
*dest++ = g1;
*dest++ = b1;
}
} else { /* gradient #2 */
if ((invert_column && invert_gradient2) ||
(!invert_column && !invert_gradient2))
{
*dest++ = r2; /* not inverted or */
*dest++ = g2; /* doubly inverted */
*dest++ = b2;
} else {
*dest++ = r2_inv;
*dest++ = g2_inv; /* singly inverted */
*dest++ = b2_inv;
}
}
}
}
/*---------------------------------------------------------------------------
Soft gradient-diamonds with scale = bgscale. Code contributed by Adam
M. Costello.
---------------------------------------------------------------------------*/
} else if ((bg[pat].type & 0x07) == 1) {
hmax = (bgscale-1)/2; /* half the max weight of a color */
max = 2*hmax; /* the max weight of a color */
r1 = rgb[bg[pat].rgb1_max].r;
g1 = rgb[bg[pat].rgb1_max].g;
b1 = rgb[bg[pat].rgb1_max].b;
r2 = rgb[bg[pat].rgb2_max].r;
g2 = rgb[bg[pat].rgb2_max].g;
b2 = rgb[bg[pat].rgb2_max].b;
for (row = 0; row < rpng2_info.height; ++row) {
yidx = row % bgscale;
if (yidx > hmax)
yidx = bgscale-1 - yidx;
dest = bg_data + row*bg_rowbytes;
for (i = 0; i < rpng2_info.width; ++i) {
xidx = i % bgscale;
if (xidx > hmax)
xidx = bgscale-1 - xidx;
k = xidx + yidx;
*dest++ = (k*r1 + (max-k)*r2) / max;
*dest++ = (k*g1 + (max-k)*g2) / max;
*dest++ = (k*b1 + (max-k)*b2) / max;
}
}
/*---------------------------------------------------------------------------
Radial "starburst" with azimuthal sinusoids; [eventually number of sinu-
soids will equal bgscale?]. This one is slow but very cool. Code con-
tributed by Pieter S. van der Meulen (originally in Smalltalk).
---------------------------------------------------------------------------*/
} else if ((bg[pat].type & 0x07) == 2) {
uch ch;
int ii, x, y, hw, hh, grayspot;
double freq, rotate, saturate, gray, intensity;
double angle=0.0, aoffset=0.0, maxDist, dist;
double red=0.0, green=0.0, blue=0.0, hue, s, v, f, p, q, t;
fprintf(stderr, "%s: computing radial background...",
PROGNAME);
fflush(stderr);
hh = rpng2_info.height / 2;
hw = rpng2_info.width / 2;
/* variables for radial waves:
* aoffset: number of degrees to rotate hue [CURRENTLY NOT USED]
* freq: number of color beams originating from the center
* grayspot: size of the graying center area (anti-alias)
* rotate: rotation of the beams as a function of radius
* saturate: saturation of beams' shape azimuthally
*/
angle = CLIP(angle, 0.0, 360.0);
grayspot = CLIP(bg[pat].bg_gray, 1, (hh + hw));
freq = MAX((double)bg[pat].bg_freq, 0.0);
saturate = (double)bg[pat].bg_bsat * 0.1;
rotate = (double)bg[pat].bg_brot * 0.1;
gray = 0.0;
intensity = 0.0;
maxDist = (double)((hw*hw) + (hh*hh));
for (row = 0; row < rpng2_info.height; ++row) {
y = row - hh;
dest = bg_data + row*bg_rowbytes;
for (i = 0; i < rpng2_info.width; ++i) {
x = i - hw;
angle = (x == 0)? PI_2 : atan((double)y / (double)x);
gray = (double)MAX(ABS(y), ABS(x)) / grayspot;
gray = MIN(1.0, gray);
dist = (double)((x*x) + (y*y)) / maxDist;
intensity = cos((angle+(rotate*dist*PI)) * freq) *
gray * saturate;
intensity = (MAX(MIN(intensity,1.0),-1.0) + 1.0) * 0.5;
hue = (angle + PI) * INV_PI_360 + aoffset;
s = gray * ((double)(ABS(x)+ABS(y)) / (double)(hw + hh));
s = MIN(MAX(s,0.0), 1.0);
v = MIN(MAX(intensity,0.0), 1.0);
if (s == 0.0) {
ch = (uch)(v * 255.0);
*dest++ = ch;
*dest++ = ch;
*dest++ = ch;
} else {
if ((hue < 0.0) || (hue >= 360.0))
hue -= (((int)(hue / 360.0)) * 360.0);
hue /= 60.0;
ii = (int)hue;
f = hue - (double)ii;
p = (1.0 - s) * v;
q = (1.0 - (s * f)) * v;
t = (1.0 - (s * (1.0 - f))) * v;
if (ii == 0) { red = v; green = t; blue = p; }
else if (ii == 1) { red = q; green = v; blue = p; }
else if (ii == 2) { red = p; green = v; blue = t; }
else if (ii == 3) { red = p; green = q; blue = v; }
else if (ii == 4) { red = t; green = p; blue = v; }
else if (ii == 5) { red = v; green = p; blue = q; }
*dest++ = (uch)(red * 255.0);
*dest++ = (uch)(green * 255.0);
*dest++ = (uch)(blue * 255.0);
}
}
}
fprintf(stderr, "done.\n");
fflush(stderr);
}
/*---------------------------------------------------------------------------
Blast background image to display buffer before beginning PNG decode;
calling function will handle invalidation and UpdateWindow() call.
---------------------------------------------------------------------------*/
for (row = 0; row < rpng2_info.height; ++row) {
src = bg_data + row*bg_rowbytes;
dest = wimage_data + row*wimage_rowbytes;
for (i = rpng2_info.width; i > 0; --i) {
r1 = *src++;
g1 = *src++;
b1 = *src++;
*dest++ = b1;
*dest++ = g1; /* note reverse order */
*dest++ = r1;
}
}
return 0;
} | /* end function rpng2_win_create_window() */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/gregbook/rpng2-win.c | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | main | int main(int argc, char **argv)
{
#ifndef DOS_OS2_W32
FILE *keybd;
#endif
#ifdef sgi
FILE *tmpfile; /* or we could just use keybd, since no overlap */
char tmpline[80];
#endif
char *inname = NULL, outname[256];
char *p, pnmchar, pnmline[256];
char *bgstr, *textbuf = NULL;
ulg rowbytes;
int rc, len = 0;
int error = 0;
int text = FALSE;
int maxval;
double LUT_exponent; /* just the lookup table */
double CRT_exponent = 2.2; /* just the monitor */
double default_display_exponent; /* whole display system */
double default_gamma = 0.0;
wpng_info.infile = NULL;
wpng_info.outfile = NULL;
wpng_info.image_data = NULL;
wpng_info.row_pointers = NULL;
wpng_info.filter = FALSE;
wpng_info.interlaced = FALSE;
wpng_info.have_bg = FALSE;
wpng_info.have_time = FALSE;
wpng_info.have_text = 0;
wpng_info.gamma = 0.0;
/* First get the default value for our display-system exponent, i.e.,
* the product of the CRT exponent and the exponent corresponding to
* the frame-buffer's lookup table (LUT), if any. If the PNM image
* looks correct on the user's display system, its file gamma is the
* inverse of this value. (Note that this is not an exhaustive list
* of LUT values--e.g., OpenStep has a lot of weird ones--but it should
* cover 99% of the current possibilities. This section must ensure
* that default_display_exponent is positive.) */
#if defined(NeXT)
/* third-party utilities can modify the default LUT exponent */
LUT_exponent = 1.0 / 2.2;
/*
if (some_next_function_that_returns_gamma(&next_gamma))
LUT_exponent = 1.0 / next_gamma;
*/
#elif defined(sgi)
LUT_exponent = 1.0 / 1.7;
/* there doesn't seem to be any documented function to
* get the "gamma" value, so we do it the hard way */
tmpfile = fopen("/etc/config/system.glGammaVal", "r");
if (tmpfile) {
double sgi_gamma;
fgets(tmpline, 80, tmpfile);
fclose(tmpfile);
sgi_gamma = atof(tmpline);
if (sgi_gamma > 0.0)
LUT_exponent = 1.0 / sgi_gamma;
}
#elif defined(Macintosh)
LUT_exponent = 1.8 / 2.61;
/*
if (some_mac_function_that_returns_gamma(&mac_gamma))
LUT_exponent = mac_gamma / 2.61;
*/
#else
LUT_exponent = 1.0; /* assume no LUT: most PCs */
#endif
/* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */
default_display_exponent = LUT_exponent * CRT_exponent;
/* If the user has set the SCREEN_GAMMA environment variable as suggested
* (somewhat imprecisely) in the libpng documentation, use that; otherwise
* use the default value we just calculated. Either way, the user may
* override this via a command-line option. */
if ((p = getenv("SCREEN_GAMMA")) != NULL) {
double exponent = atof(p);
if (exponent > 0.0)
default_gamma = 1.0 / exponent;
}
if (default_gamma == 0.0)
default_gamma = 1.0 / default_display_exponent;
/* Now parse the command line for options and the PNM filename. */
while (*++argv && !error) {
if (!strncmp(*argv, "-i", 2)) {
wpng_info.interlaced = TRUE;
} else if (!strncmp(*argv, "-time", 3)) {
wpng_info.modtime = time(NULL);
wpng_info.have_time = TRUE;
} else if (!strncmp(*argv, "-text", 3)) {
text = TRUE;
} else if (!strncmp(*argv, "-gamma", 2)) {
if (!*++argv)
++error;
else {
wpng_info.gamma = atof(*argv);
if (wpng_info.gamma <= 0.0)
++error;
else if (wpng_info.gamma > 1.01)
fprintf(stderr, PROGNAME
" warning: file gammas are usually less than 1.0\n");
}
} else if (!strncmp(*argv, "-bgcolor", 4)) {
if (!*++argv)
++error;
else {
bgstr = *argv;
if (strlen(bgstr) != 7 || bgstr[0] != '#')
++error;
else {
unsigned r, g, b; /* this way quiets compiler warnings */
sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b);
wpng_info.bg_red = (uch)r;
wpng_info.bg_green = (uch)g;
wpng_info.bg_blue = (uch)b;
wpng_info.have_bg = TRUE;
}
}
} else {
if (**argv != '-') {
inname = *argv;
if (argv[1]) /* shouldn't be any more args after filename */
++error;
} else
++error; /* not expecting any other options */
}
}
/* open the input and output files, or register an error and abort */
if (!inname) {
if (isatty(0)) {
fprintf(stderr, PROGNAME
": must give input filename or provide image data via stdin\n");
++error;
} else {
#ifdef DOS_OS2_W32
/* some buggy C libraries require BOTH setmode() and fdopen(bin) */
setmode(fileno(stdin), O_BINARY);
setmode(fileno(stdout), O_BINARY);
#endif
if ((wpng_info.infile = fdopen(fileno(stdin), "rb")) == NULL) {
fprintf(stderr, PROGNAME
": unable to reopen stdin in binary mode\n");
++error;
} else
if ((wpng_info.outfile = fdopen(fileno(stdout), "wb")) == NULL) {
fprintf(stderr, PROGNAME
": unable to reopen stdout in binary mode\n");
fclose(wpng_info.infile);
++error;
} else
wpng_info.filter = TRUE;
}
} else if ((len = strlen(inname)) > 250) {
fprintf(stderr, PROGNAME ": input filename is too long [%d chars]\n",
len);
++error;
} else if (!(wpng_info.infile = fopen(inname, "rb"))) {
fprintf(stderr, PROGNAME ": can't open input file [%s]\n", inname);
++error;
}
if (!error) {
fgets(pnmline, 256, wpng_info.infile);
if (pnmline[0] != 'P' || ((pnmchar = pnmline[1]) != '5' &&
pnmchar != '6' && pnmchar != '8'))
{
fprintf(stderr, PROGNAME
": input file [%s] is not a binary PGM, PPM or PAM file\n",
inname);
++error;
} else {
wpng_info.pnmtype = (int)(pnmchar - '0');
if (wpng_info.pnmtype != 8)
wpng_info.have_bg = FALSE; /* no need for bg if opaque */
do {
fgets(pnmline, 256, wpng_info.infile); /* lose any comments */
} while (pnmline[0] == '#');
sscanf(pnmline, "%ld %ld", &wpng_info.width, &wpng_info.height);
do {
fgets(pnmline, 256, wpng_info.infile); /* more comment lines */
} while (pnmline[0] == '#');
sscanf(pnmline, "%d", &maxval);
if (wpng_info.width <= 0L || wpng_info.height <= 0L ||
maxval != 255)
{
fprintf(stderr, PROGNAME
": only positive width/height, maxval == 255 allowed \n");
++error;
}
wpng_info.sample_depth = 8; /* <==> maxval 255 */
if (!wpng_info.filter) {
/* make outname from inname */
if ((p = strrchr(inname, '.')) == NULL ||
(p - inname) != (len - 4))
{
strcpy(outname, inname);
strcpy(outname+len, ".png");
} else {
len -= 4;
strncpy(outname, inname, len);
strcpy(outname+len, ".png");
}
/* check if outname already exists; if not, open */
if ((wpng_info.outfile = fopen(outname, "rb")) != NULL) {
fprintf(stderr, PROGNAME ": output file exists [%s]\n",
outname);
fclose(wpng_info.outfile);
++error;
} else if (!(wpng_info.outfile = fopen(outname, "wb"))) {
fprintf(stderr, PROGNAME ": can't open output file [%s]\n",
outname);
++error;
}
}
}
if (error) {
fclose(wpng_info.infile);
wpng_info.infile = NULL;
if (wpng_info.filter) {
fclose(wpng_info.outfile);
wpng_info.outfile = NULL;
}
}
}
/* if we had any errors, print usage and die horrible death...arrr! */
if (error) {
fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, APPNAME);
writepng_version_info();
fprintf(stderr, "\n"
"Usage: %s [-gamma exp] [-bgcolor bg] [-text] [-time] [-interlace] pnmfile\n"
"or: ... | %s [-gamma exp] [-bgcolor bg] [-text] [-time] [-interlace] | ...\n"
" exp \ttransfer-function exponent (``gamma'') of the image in\n"
"\t\t floating-point format (e.g., ``%.5f''); if image looks\n"
"\t\t correct on given display system, image gamma is equal to\n"
"\t\t inverse of display-system exponent, i.e., 1 / (LUT * CRT)\n"
"\t\t (where LUT = lookup-table exponent and CRT = CRT exponent;\n"
"\t\t first varies, second is usually 2.2, all are positive)\n"
" bg \tdesired background color for alpha-channel images, in\n"
"\t\t 7-character hex RGB format (e.g., ``#ff7700'' for orange:\n"
"\t\t same as HTML colors)\n"
" -text\tprompt interactively for text info (tEXt chunks)\n"
" -time\tinclude a tIME chunk (last modification time)\n"
" -interlace\twrite interlaced PNG image\n"
"\n"
"pnmfile or stdin must be a binary PGM (`P5'), PPM (`P6') or (extremely\n"
"unofficial and unsupported!) PAM (`P8') file. Currently it is required\n"
"to have maxval == 255 (i.e., no scaling). If pnmfile is specified, it\n"
"is converted to the corresponding PNG file with the same base name but a\n"
"``.png'' extension; files read from stdin are converted and sent to stdout.\n"
"The conversion is progressive (low memory usage) unless interlacing is\n"
"requested; in that case the whole image will be buffered in memory and\n"
"written in one call.\n"
"\n", PROGNAME, PROGNAME, default_gamma);
exit(1);
}
/* prepare the text buffers for libpng's use; note that even though
* PNG's png_text struct includes a length field, we don't have to fill
* it out */
if (text &&
#ifndef DOS_OS2_W32
(keybd = fdopen(fileno(stderr), "r")) != NULL &&
#endif
(textbuf = (char *)malloc((5 + 9)*75)) != NULL)
{
int i, valid, result;
fprintf(stderr,
"Enter text info (no more than 72 characters per line);\n");
fprintf(stderr, "to skip a field, hit the <Enter> key.\n");
/* note: just <Enter> leaves len == 1 */
do {
valid = TRUE;
p = textbuf + TEXT_TITLE_OFFSET;
fprintf(stderr, " Title: ");
fflush(stderr);
if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {
if (p[len-1] == '\n')
p[--len] = '\0';
wpng_info.title = p;
wpng_info.have_text |= TEXT_TITLE;
if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
fprintf(stderr, " " PROGNAME " warning: character code"
" %u is %sdiscouraged by the PNG\n specification "
"[first occurrence was at character position #%d]\n",
(unsigned)p[result], (p[result] == 27)? "strongly " : "",
result+1);
fflush(stderr);
#ifdef FORBID_LATIN1_CTRL
wpng_info.have_text &= ~TEXT_TITLE;
valid = FALSE;
#else
if (p[result] == 27) { /* escape character */
wpng_info.have_text &= ~TEXT_TITLE;
valid = FALSE;
}
#endif
}
}
} while (!valid);
do {
valid = TRUE;
p = textbuf + TEXT_AUTHOR_OFFSET;
fprintf(stderr, " Author: ");
fflush(stderr);
if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {
if (p[len-1] == '\n')
p[--len] = '\0';
wpng_info.author = p;
wpng_info.have_text |= TEXT_AUTHOR;
if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
fprintf(stderr, " " PROGNAME " warning: character code"
" %u is %sdiscouraged by the PNG\n specification "
"[first occurrence was at character position #%d]\n",
(unsigned)p[result], (p[result] == 27)? "strongly " : "",
result+1);
fflush(stderr);
#ifdef FORBID_LATIN1_CTRL
wpng_info.have_text &= ~TEXT_AUTHOR;
valid = FALSE;
#else
if (p[result] == 27) { /* escape character */
wpng_info.have_text &= ~TEXT_AUTHOR;
valid = FALSE;
}
#endif
}
}
} while (!valid);
do {
valid = TRUE;
p = textbuf + TEXT_DESC_OFFSET;
fprintf(stderr, " Description (up to 9 lines):\n");
for (i = 1; i < 10; ++i) {
fprintf(stderr, " [%d] ", i);
fflush(stderr);
if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1)
p += len; /* now points at NULL; char before is newline */
else
break;
}
if ((len = p - (textbuf + TEXT_DESC_OFFSET)) > 1) {
if (p[-1] == '\n') {
p[-1] = '\0';
--len;
}
wpng_info.desc = textbuf + TEXT_DESC_OFFSET;
wpng_info.have_text |= TEXT_DESC;
p = textbuf + TEXT_DESC_OFFSET;
if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
fprintf(stderr, " " PROGNAME " warning: character code"
" %u is %sdiscouraged by the PNG\n specification "
"[first occurrence was at character position #%d]\n",
(unsigned)p[result], (p[result] == 27)? "strongly " : "",
result+1);
fflush(stderr);
#ifdef FORBID_LATIN1_CTRL
wpng_info.have_text &= ~TEXT_DESC;
valid = FALSE;
#else
if (p[result] == 27) { /* escape character */
wpng_info.have_text &= ~TEXT_DESC;
valid = FALSE;
}
#endif
}
}
} while (!valid);
do {
valid = TRUE;
p = textbuf + TEXT_COPY_OFFSET;
fprintf(stderr, " Copyright: ");
fflush(stderr);
if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {
if (p[len-1] == '\n')
p[--len] = '\0';
wpng_info.copyright = p;
wpng_info.have_text |= TEXT_COPY;
if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
fprintf(stderr, " " PROGNAME " warning: character code"
" %u is %sdiscouraged by the PNG\n specification "
"[first occurrence was at character position #%d]\n",
(unsigned)p[result], (p[result] == 27)? "strongly " : "",
result+1);
fflush(stderr);
#ifdef FORBID_LATIN1_CTRL
wpng_info.have_text &= ~TEXT_COPY;
valid = FALSE;
#else
if (p[result] == 27) { /* escape character */
wpng_info.have_text &= ~TEXT_COPY;
valid = FALSE;
}
#endif
}
}
} while (!valid);
do {
valid = TRUE;
p = textbuf + TEXT_EMAIL_OFFSET;
fprintf(stderr, " E-mail: ");
fflush(stderr);
if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {
if (p[len-1] == '\n')
p[--len] = '\0';
wpng_info.email = p;
wpng_info.have_text |= TEXT_EMAIL;
if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
fprintf(stderr, " " PROGNAME " warning: character code"
" %u is %sdiscouraged by the PNG\n specification "
"[first occurrence was at character position #%d]\n",
(unsigned)p[result], (p[result] == 27)? "strongly " : "",
result+1);
fflush(stderr);
#ifdef FORBID_LATIN1_CTRL
wpng_info.have_text &= ~TEXT_EMAIL;
valid = FALSE;
#else
if (p[result] == 27) { /* escape character */
wpng_info.have_text &= ~TEXT_EMAIL;
valid = FALSE;
}
#endif
}
}
} while (!valid);
do {
valid = TRUE;
p = textbuf + TEXT_URL_OFFSET;
fprintf(stderr, " URL: ");
fflush(stderr);
if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {
if (p[len-1] == '\n')
p[--len] = '\0';
wpng_info.url = p;
wpng_info.have_text |= TEXT_URL;
if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
fprintf(stderr, " " PROGNAME " warning: character code"
" %u is %sdiscouraged by the PNG\n specification "
"[first occurrence was at character position #%d]\n",
(unsigned)p[result], (p[result] == 27)? "strongly " : "",
result+1);
fflush(stderr);
#ifdef FORBID_LATIN1_CTRL
wpng_info.have_text &= ~TEXT_URL;
valid = FALSE;
#else
if (p[result] == 27) { /* escape character */
wpng_info.have_text &= ~TEXT_URL;
valid = FALSE;
}
#endif
}
}
} while (!valid);
#ifndef DOS_OS2_W32
fclose(keybd);
#endif
} else if (text) {
fprintf(stderr, PROGNAME ": unable to allocate memory for text\n");
text = FALSE;
wpng_info.have_text = 0;
}
/* allocate libpng stuff, initialize transformations, write pre-IDAT data */
if ((rc = writepng_init(&wpng_info)) != 0) {
switch (rc) {
case 2:
fprintf(stderr, PROGNAME
": libpng initialization problem (longjmp)\n");
break;
case 4:
fprintf(stderr, PROGNAME ": insufficient memory\n");
break;
case 11:
fprintf(stderr, PROGNAME
": internal logic error (unexpected PNM type)\n");
break;
default:
fprintf(stderr, PROGNAME
": unknown writepng_init() error\n");
break;
}
exit(rc);
}
/* free textbuf, since it's a completely local variable and all text info
* has just been written to the PNG file */
if (text && textbuf) {
free(textbuf);
textbuf = NULL;
}
/* calculate rowbytes on basis of image type; note that this becomes much
* more complicated if we choose to support PBM type, ASCII PNM types, or
* 16-bit-per-sample binary data [currently not an official NetPBM type] */
if (wpng_info.pnmtype == 5)
rowbytes = wpng_info.width;
else if (wpng_info.pnmtype == 6)
rowbytes = wpng_info.width * 3;
else /* if (wpng_info.pnmtype == 8) */
rowbytes = wpng_info.width * 4;
/* read and write the image, either in its entirety (if writing interlaced
* PNG) or row by row (if non-interlaced) */
fprintf(stderr, "Encoding image data...\n");
fflush(stderr);
if (wpng_info.interlaced) {
long i;
ulg bytes;
ulg image_bytes = rowbytes * wpng_info.height; /* overflow? */
wpng_info.image_data = (uch *)malloc(image_bytes);
wpng_info.row_pointers = (uch **)malloc(wpng_info.height*sizeof(uch *));
if (wpng_info.image_data == NULL || wpng_info.row_pointers == NULL) {
fprintf(stderr, PROGNAME ": insufficient memory for image data\n");
writepng_cleanup(&wpng_info);
wpng_cleanup();
exit(5);
}
for (i = 0; i < wpng_info.height; ++i)
wpng_info.row_pointers[i] = wpng_info.image_data + i*rowbytes;
bytes = fread(wpng_info.image_data, 1, image_bytes, wpng_info.infile);
if (bytes != image_bytes) {
fprintf(stderr, PROGNAME ": expected %lu bytes, got %lu bytes\n",
image_bytes, bytes);
fprintf(stderr, " (continuing anyway)\n");
}
if (writepng_encode_image(&wpng_info) != 0) {
fprintf(stderr, PROGNAME
": libpng problem (longjmp) while writing image data\n");
writepng_cleanup(&wpng_info);
wpng_cleanup();
exit(2);
}
} else /* not interlaced: write progressively (row by row) */ {
long j;
ulg bytes;
wpng_info.image_data = (uch *)malloc(rowbytes);
if (wpng_info.image_data == NULL) {
fprintf(stderr, PROGNAME ": insufficient memory for row data\n");
writepng_cleanup(&wpng_info);
wpng_cleanup();
exit(5);
}
error = 0;
for (j = wpng_info.height; j > 0L; --j) {
bytes = fread(wpng_info.image_data, 1, rowbytes, wpng_info.infile);
if (bytes != rowbytes) {
fprintf(stderr, PROGNAME
": expected %lu bytes, got %lu bytes (row %ld)\n", rowbytes,
bytes, wpng_info.height-j);
++error;
break;
}
if (writepng_encode_row(&wpng_info) != 0) {
fprintf(stderr, PROGNAME
": libpng problem (longjmp) while writing row %ld\n",
wpng_info.height-j);
++error;
break;
}
}
if (error) {
writepng_cleanup(&wpng_info);
wpng_cleanup();
exit(2);
}
if (writepng_encode_finish(&wpng_info) != 0) {
fprintf(stderr, PROGNAME ": error on final libpng call\n");
writepng_cleanup(&wpng_info);
wpng_cleanup();
exit(2);
}
}
/* OK, we're done (successfully): clean up all resources and quit */
fprintf(stderr, "Done.\n");
fflush(stderr);
writepng_cleanup(&wpng_info);
wpng_cleanup();
return 0;
} | /* lone global */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/gregbook/wpng.c#L154-L783 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | writepng_init | int writepng_init(mainprog_info *mainprog_ptr)
{
png_structp png_ptr; /* note: temporary variables! */
png_infop info_ptr;
int color_type, interlace_type;
/* could also replace libpng warning-handler (final NULL), but no need: */
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr,
writepng_error_handler, NULL);
if (!png_ptr)
return 4; /* out of memory */
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_write_struct(&png_ptr, NULL);
return 4; /* out of memory */
}
/* setjmp() must be called in every function that calls a PNG-writing
* libpng function, unless an alternate error handler was installed--
* but compatible error handlers must either use longjmp() themselves
* (as in this program) or some other method to return control to
* application code, so here we go: */
if (setjmp(mainprog_ptr->jmpbuf)) {
png_destroy_write_struct(&png_ptr, &info_ptr);
return 2;
}
/* make sure outfile is (re)opened in BINARY mode */
png_init_io(png_ptr, mainprog_ptr->outfile);
/* set the compression levels--in general, always want to leave filtering
* turned on (except for palette images) and allow all of the filters,
* which is the default; want 32K zlib window, unless entire image buffer
* is 16K or smaller (unknown here)--also the default; usually want max
* compression (NOT the default); and remaining compression flags should
* be left alone */
png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
/*
>> this is default for no filtering; Z_FILTERED is default otherwise:
png_set_compression_strategy(png_ptr, Z_DEFAULT_STRATEGY);
>> these are all defaults:
png_set_compression_mem_level(png_ptr, 8);
png_set_compression_window_bits(png_ptr, 15);
png_set_compression_method(png_ptr, 8);
*/
/* set the image parameters appropriately */
if (mainprog_ptr->pnmtype == 5)
color_type = PNG_COLOR_TYPE_GRAY;
else if (mainprog_ptr->pnmtype == 6)
color_type = PNG_COLOR_TYPE_RGB;
else if (mainprog_ptr->pnmtype == 8)
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
else {
png_destroy_write_struct(&png_ptr, &info_ptr);
return 11;
}
interlace_type = mainprog_ptr->interlaced? PNG_INTERLACE_ADAM7 :
PNG_INTERLACE_NONE;
png_set_IHDR(png_ptr, info_ptr, mainprog_ptr->width, mainprog_ptr->height,
mainprog_ptr->sample_depth, color_type, interlace_type,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
if (mainprog_ptr->gamma > 0.0)
png_set_gAMA(png_ptr, info_ptr, mainprog_ptr->gamma);
if (mainprog_ptr->have_bg) { /* we know it's RGBA, not gray+alpha */
png_color_16 background;
background.red = mainprog_ptr->bg_red;
background.green = mainprog_ptr->bg_green;
background.blue = mainprog_ptr->bg_blue;
png_set_bKGD(png_ptr, info_ptr, &background);
}
if (mainprog_ptr->have_time) {
png_time modtime;
png_convert_from_time_t(&modtime, mainprog_ptr->modtime);
png_set_tIME(png_ptr, info_ptr, &modtime);
}
if (mainprog_ptr->have_text) {
png_text text[6];
int num_text = 0;
if (mainprog_ptr->have_text & TEXT_TITLE) {
text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
text[num_text].key = "Title";
text[num_text].text = mainprog_ptr->title;
++num_text;
}
if (mainprog_ptr->have_text & TEXT_AUTHOR) {
text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
text[num_text].key = "Author";
text[num_text].text = mainprog_ptr->author;
++num_text;
}
if (mainprog_ptr->have_text & TEXT_DESC) {
text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
text[num_text].key = "Description";
text[num_text].text = mainprog_ptr->desc;
++num_text;
}
if (mainprog_ptr->have_text & TEXT_COPY) {
text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
text[num_text].key = "Copyright";
text[num_text].text = mainprog_ptr->copyright;
++num_text;
}
if (mainprog_ptr->have_text & TEXT_EMAIL) {
text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
text[num_text].key = "E-mail";
text[num_text].text = mainprog_ptr->email;
++num_text;
}
if (mainprog_ptr->have_text & TEXT_URL) {
text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
text[num_text].key = "URL";
text[num_text].text = mainprog_ptr->url;
++num_text;
}
png_set_text(png_ptr, info_ptr, text, num_text);
}
/* write all chunks up to (but not including) first IDAT */
png_write_info(png_ptr, info_ptr);
/* if we wanted to write any more text info *after* the image data, we
* would set up text struct(s) here and call png_set_text() again, with
* just the new data; png_set_tIME() could also go here, but it would
* have no effect since we already called it above (only one tIME chunk
* allowed) */
/* set up the transformations: for now, just pack low-bit-depth pixels
* into bytes (one, two or four pixels per byte) */
png_set_packing(png_ptr);
/* png_set_shift(png_ptr, &sig_bit); to scale low-bit-depth values */
/* make sure we save our pointers for use in writepng_encode_image() */
mainprog_ptr->png_ptr = png_ptr;
mainprog_ptr->info_ptr = info_ptr;
/* OK, that's all we need to do for now; return happy */
return 0;
} | /* returns 0 for success, 2 for libpng problem, 4 for out of memory, 11 for
* unexpected pnmtype; note that outfile might be stdout */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/gregbook/writepng.c#L84-L251 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | writepng_encode_image | int writepng_encode_image(mainprog_info *mainprog_ptr)
{
png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
/* as always, setjmp() must be called in every function that calls a
* PNG-writing libpng function */
if (setjmp(mainprog_ptr->jmpbuf)) {
png_destroy_write_struct(&png_ptr, &info_ptr);
mainprog_ptr->png_ptr = NULL;
mainprog_ptr->info_ptr = NULL;
return 2;
}
/* and now we just write the whole image; libpng takes care of interlacing
* for us */
png_write_image(png_ptr, mainprog_ptr->row_pointers);
/* since that's it, we also close out the end of the PNG file now--if we
* had any text or time info to write after the IDATs, second argument
* would be info_ptr, but we optimize slightly by sending NULL pointer: */
png_write_end(png_ptr, NULL);
return 0;
} | /* returns 0 for success, 2 for libpng (longjmp) problem */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/gregbook/writepng.c#L259-L289 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | writepng_encode_row | int writepng_encode_row(mainprog_info *mainprog_ptr) /* NON-interlaced only! */
{
png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
/* as always, setjmp() must be called in every function that calls a
* PNG-writing libpng function */
if (setjmp(mainprog_ptr->jmpbuf)) {
png_destroy_write_struct(&png_ptr, &info_ptr);
mainprog_ptr->png_ptr = NULL;
mainprog_ptr->info_ptr = NULL;
return 2;
}
/* image_data points at our one row of image data */
png_write_row(png_ptr, mainprog_ptr->image_data);
return 0;
} | /* returns 0 if succeeds, 2 if libpng problem */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/gregbook/writepng.c#L297-L319 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | writepng_encode_finish | int writepng_encode_finish(mainprog_info *mainprog_ptr) /* NON-interlaced! */
{
png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
/* as always, setjmp() must be called in every function that calls a
* PNG-writing libpng function */
if (setjmp(mainprog_ptr->jmpbuf)) {
png_destroy_write_struct(&png_ptr, &info_ptr);
mainprog_ptr->png_ptr = NULL;
mainprog_ptr->info_ptr = NULL;
return 2;
}
/* close out PNG file; if we had any text or time info to write after
* the IDATs, second argument would be info_ptr: */
png_write_end(png_ptr, NULL);
return 0;
} | /* returns 0 if succeeds, 2 if libpng problem */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/gregbook/writepng.c#L327-L350 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | parse_color | static void
parse_color(char *arg, unsigned int *colors)
{
unsigned int ncolors = 0;
while (*arg && ncolors < 4)
{
char *ep = arg;
unsigned long ul = strtoul(arg, &ep, 0);
if (ul > 65535)
{
fprintf(stderr, "makepng --color=...'%s': too big\n", arg);
exit(1);
}
if (ep == arg)
{
fprintf(stderr, "makepng --color=...'%s': not a valid color\n", arg);
exit(1);
}
if (*ep) ++ep; /* skip a separator */
arg = ep;
colors[++ncolors] = (unsigned int)ul; /* checked above */
}
if (*arg)
{
fprintf(stderr, "makepng --color=...'%s': too many values\n", arg);
exit(1);
}
*colors = ncolors;
} | /* This is a not-very-good parser for a sequence of numbers (including 0). It
* doesn't accept some apparently valid things, but it accepts all the sensible
* combinations.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/makepng.c#L1238-L1274 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | make_random_bytes | static void
make_random_bytes(png_uint_32* seed, void* pv, size_t size)
{
png_uint_32 u0 = seed[0], u1 = seed[1];
png_bytep bytes = voidcast(png_bytep, pv);
/* There are thirty three bits, the next bit in the sequence is bit-33 XOR
* bit-20. The top 1 bit is in u1, the bottom 32 are in u0.
*/
size_t i;
for (i=0; i<size; ++i)
{
/* First generate 8 new bits then shift them in at the end. */
png_uint_32 u = ((u0 >> (20-8)) ^ ((u1 << 7) | (u0 >> (32-7)))) & 0xff;
u1 <<= 8;
u1 |= u0 >> 24;
u0 <<= 8;
u0 |= u;
*bytes++ = (png_byte)u;
}
seed[0] = u0;
seed[1] = u1;
} | /* Generate random bytes. This uses a boring repeatable algorithm and it
* is implemented here so that it gives the same set of numbers on every
* architecture. It's a linear congruential generator (Knuth or Sedgewick
* "Algorithms") but it comes from the 'feedback taps' table in Horowitz and
* Hill, "The Art of Electronics".
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L77-L100 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | closestinteger | static double
closestinteger(double x)
{
return floor(x + .5);
} | /* Math support - neither Cygwin nor Visual Studio have C99 support and we need
* a predictable rounding function, so make one here:
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L112-L116 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | u8d | static png_byte
u8d(double d)
{
d = closestinteger(d);
return (png_byte)d;
} | /* Cast support: remove GCC whines. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L119-L124 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | unpremultiply | static png_byte
unpremultiply(int component, int alpha)
{
if (alpha <= component)
return 255; /* Arbitrary, but consistent with the libpng code */
else if (alpha >= 65535)
return isRGB(component);
else
return sRGB((double)component / alpha);
} | /* not used */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L168-L179 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | power_law_error8 | static int
power_law_error8(int value)
{
if (value > 0 && value < 255)
{
double vd = value / 255.;
double e = fabs(
pow(sRGB_to_d[value], 1/2.2) - sRGB_from_linear(pow(vd, 2.2)));
/* Always allow an extra 1 here for rounding errors */
e = 1+floor(255 * e);
return (int)e;
}
return 0;
} | /* The error that results from using a 2.2 power law in place of the correct
* sRGB transform, given an 8-bit value which might be either sRGB or power-law.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L221-L236 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | power_law_error16 | static int
power_law_error16(int value)
{
if (value > 0 && value < 65535)
{
/* Round trip the value through an 8-bit representation but using
* non-matching to/from conversions.
*/
double vd = value / 65535.;
double e = fabs(
pow(sRGB_from_linear(vd), 2.2) - linear_from_sRGB(pow(vd, 1/2.2)));
/* Always allow an extra 1 here for rounding errors */
e = error_in_sRGB_roundtrip+floor(65535 * e);
return (int)e;
}
return 0;
} | /* by experiment */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L239-L257 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | formatof | static png_uint_32
formatof(const char *arg)
{
char *ep;
unsigned long format = strtoul(arg, &ep, 0);
if (ep > arg && *ep == 0 && format < FORMAT_COUNT)
return (png_uint_32)format;
else for (format=0; format < FORMAT_COUNT; ++format)
{
if (strcmp(format_names[format], arg) == 0)
return (png_uint_32)format;
}
fprintf(stderr, "pngstest: format name '%s' invalid\n", arg);
return FORMAT_COUNT;
} | /* Decode an argument to a format number. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L426-L443 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | format_clear | static void format_clear(format_list *pf)
{
int i;
for (i=0; i<FORMAT_SET_COUNT; ++i)
pf->bits[i] = 0;
} | /* currently unused */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L461-L466 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | format_unset | static int format_unset(format_list *pf, png_uint_32 format)
{
if (format < FORMAT_COUNT)
return pf->bits[format >> 5] &= ~((png_uint_32)1) << (format & 31);
return 0;
} | /* currently unused */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L488-L494 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | newimage | static void
newimage(Image *image)
{
memset(image, 0, sizeof *image);
} | /* Initializer: also sets the permitted error limit for 16-bit operations. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L558-L562 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | resetimage | static void
resetimage(Image *image)
{
if (image->input_file != NULL)
rewind(image->input_file);
} | /* Reset the image to be read again - only needs to rewind the FILE* at present.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L566-L571 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | freebuffer | static void
freebuffer(Image *image)
{
if (image->buffer) free(image->buffer);
image->buffer = NULL;
image->bufsize = 0;
image->allocsize = 0;
} | /* Free the image buffer; the buffer is re-used on a re-read, this is just for
* cleanup.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L576-L583 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | freeimage | static void
freeimage(Image *image)
{
freebuffer(image);
png_image_free(&image->image);
if (image->input_file != NULL)
{
fclose(image->input_file);
image->input_file = NULL;
}
if (image->input_memory != NULL)
{
free(image->input_memory);
image->input_memory = NULL;
image->input_memory_size = 0;
}
if (image->tmpfile_name[0] != 0 && (image->opts & KEEP_TMPFILES) == 0)
{
remove(image->tmpfile_name);
image->tmpfile_name[0] = 0;
}
} | /* Delete function; cleans out all the allocated data and the temporary file in
* the image.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L588-L612 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | initimage | static void initimage(Image *image, png_uint_32 opts, const char *file_name,
int stride_extra)
{
freeimage(image);
memset(&image->image, 0, sizeof image->image);
image->opts = opts;
image->file_name = file_name;
image->stride_extra = stride_extra;
} | /* This is actually a re-initializer; allows an image structure to be re-used by
* freeing everything that relates to an old image.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L617-L625 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | check16 | static int
check16(png_const_bytep bp, int b)
{
int i = 16;
do
if (*bp != b) return 1;
while (--i);
return 0;
} | /* Make sure 16 bytes match the given byte. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L657-L667 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | checkbuffer | static void
checkbuffer(Image *image, const char *arg)
{
if (check16(image->buffer, 95))
{
fflush(stdout);
fprintf(stderr, "%s: overwrite at start of image buffer\n", arg);
exit(1);
}
if (check16(image->buffer+16+image->allocsize, 95))
{
fflush(stdout);
fprintf(stderr, "%s: overwrite at end of image buffer\n", arg);
exit(1);
}
} | /* Check for overwrite in the image buffer. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L670-L686 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | logerror | static int
logerror(Image *image, const char *a1, const char *a2, const char *a3)
{
fflush(stdout);
if (image->image.warning_or_error)
fprintf(stderr, "%s%s%s: %s\n", a1, a2, a3, image->image.message);
else
fprintf(stderr, "%s%s%s\n", a1, a2, a3);
if (image->image.opaque != NULL)
{
fprintf(stderr, "%s: image opaque pointer non-NULL on error\n",
image->file_name);
png_image_free(&image->image);
}
return 0;
} | /* ERROR HANDLING */
/* Log a terminal error, also frees the libpng part of the image if necessary.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L691-L709 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | logclose | static int
logclose(Image *image, FILE *f, const char *name, const char *operation)
{
int e = errno;
fclose(f);
return logerror(image, name, operation, strerror(e));
} | /* Log an error and close a file (just a utility to do both things in one
* function call.)
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L714-L721 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | checkopaque | static int
checkopaque(Image *image)
{
if (image->image.opaque != NULL)
{
png_image_free(&image->image);
return logerror(image, image->file_name, ": opaque not NULL", "");
}
else if (image->image.warning_or_error != 0 && (image->opts & STRICT) != 0)
return logerror(image, image->file_name, " --strict", "");
else
return 1;
} | /* Make sure the png_image has been freed - validates that libpng is doing what
* the spec says and freeing the image.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L726-L740 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gp_g8 | static void
gp_g8(Pixel *p, png_const_voidp pb)
{
png_const_bytep pp = voidcast(png_const_bytep, pb);
p->r = p->g = p->b = pp[0];
p->a = 255;
} | /* Read a Pixel from a buffer. The code below stores the correct routine for
* the format in a function pointer, these are the routines:
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L771-L778 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_noop | static void
gpc_noop(Pixel *out, const Pixel *in, const Background *back)
{
(void)back;
out->r = in->r;
out->g = in->g;
out->b = in->b;
out->a = in->a;
} | /* Convertion between pixel formats. The code above effectively eliminates the
* component ordering changes leaving three basic changes:
*
* 1) Remove an alpha channel by pre-multiplication or compositing on a
* background color. (Adding an alpha channel is a no-op.)
*
* 2) Remove color by mapping to grayscale. (Grayscale to color is a no-op.)
*
* 3) Convert between 8-bit and 16-bit components. (Both directtions are
* relevant.)
*
* This gives the following base format conversion matrix:
*
* OUT: ----- 8-bit ----- ----- 16-bit -----
* IN G GA RGB RGBA G GA RGB RGBA
* 8 G . . . . lin lin lin lin
* 8 GA bckg . bckc . pre' pre pre' pre
* 8 RGB g8 g8 . . glin glin lin lin
* 8 RGBA g8b g8 bckc . gpr' gpre pre' pre
* 16 G sRGB sRGB sRGB sRGB . . . .
* 16 GA b16g unpg b16c unpc A . A .
* 16 RGB sG sG sRGB sRGB g16 g16 . .
* 16 RGBA gb16 sGp cb16 sCp g16 g16' A .
*
* 8-bit to 8-bit:
* bckg: composite on gray background
* bckc: composite on color background
* g8: convert sRGB components to sRGB grayscale
* g8b: convert sRGB components to grayscale and composite on gray background
*
* 8-bit to 16-bit:
* lin: make sRGB components linear, alpha := 65535
* pre: make sRGB components linear and premultiply by alpha (scale alpha)
* pre': as 'pre' but alpha := 65535
* glin: make sRGB components linear, convert to grayscale, alpha := 65535
* gpre: make sRGB components grayscale and linear and premultiply by alpha
* gpr': as 'gpre' but alpha := 65535
*
* 16-bit to 8-bit:
* sRGB: convert linear components to sRGB, alpha := 255
* unpg: unpremultiply gray component and convert to sRGB (scale alpha)
* unpc: unpremultiply color components and convert to sRGB (scale alpha)
* b16g: composite linear onto gray background and convert the result to sRGB
* b16c: composite linear onto color background and convert the result to sRGB
* sG: convert linear RGB to sRGB grayscale
* sGp: unpremultiply RGB then convert to sRGB grayscale
* sCp: unpremultiply RGB then convert to sRGB
* gb16: composite linear onto background and convert to sRGB grayscale
* (order doesn't matter, the composite and grayscale operations permute)
* cb16: composite linear onto background and convert to sRGB
*
* 16-bit to 16-bit:
* A: set alpha to 65535
* g16: convert linear RGB to linear grayscale (alpha := 65535)
* g16': as 'g16' but alpha is unchanged
*/
/* Simple copy: */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1125-L1133 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_bckg | static void
gpc_bckg(Pixel *out, const Pixel *in, const Background *back)
{
if (in->a <= 0)
out->r = out->g = out->b = back->ig;
else if (in->a >= 255)
out->r = out->g = out->b = in->g;
else
{
double a = in->a / 255.;
out->r = out->g = out->b = sRGB(sRGB_to_d[in->g] * a + back->dg * (1-a));
}
out->a = 255;
} | /* 8-bit to 8-bit conversions */
/* bckg: composite on gray background */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1175-L1192 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_bckc | static void
gpc_bckc(Pixel *out, const Pixel *in, const Background *back)
{
if (in->a <= 0)
{
out->r = back->ir;
out->g = back->ig;
out->b = back->ib;
}
else if (in->a >= 255)
{
out->r = in->r;
out->g = in->g;
out->b = in->b;
}
else
{
double a = in->a / 255.;
out->r = sRGB(sRGB_to_d[in->r] * a + back->dr * (1-a));
out->g = sRGB(sRGB_to_d[in->g] * a + back->dg * (1-a));
out->b = sRGB(sRGB_to_d[in->b] * a + back->db * (1-a));
}
out->a = 255;
} | /* bckc: composite on color background */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1195-L1222 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_g8 | static void
gpc_g8(Pixel *out, const Pixel *in, const Background *back)
{
(void)back;
if (in->r == in->g && in->g == in->b)
out->r = out->g = out->b = in->g;
else
out->r = out->g = out->b =
sRGB(YfromRGB(sRGB_to_d[in->r], sRGB_to_d[in->g], sRGB_to_d[in->b]));
out->a = in->a;
} | /* g8: convert sRGB components to sRGB grayscale */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1225-L1238 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_g8b | static void
gpc_g8b(Pixel *out, const Pixel *in, const Background *back)
{
if (in->a <= 0)
out->r = out->g = out->b = back->ig;
else if (in->a >= 255)
{
if (in->r == in->g && in->g == in->b)
out->r = out->g = out->b = in->g;
else
out->r = out->g = out->b = sRGB(YfromRGB(
sRGB_to_d[in->r], sRGB_to_d[in->g], sRGB_to_d[in->b]));
}
else
{
double a = in->a/255.;
out->r = out->g = out->b = sRGB(a * YfromRGB(sRGB_to_d[in->r],
sRGB_to_d[in->g], sRGB_to_d[in->b]) + back->dg * (1-a));
}
out->a = 255;
} | /* g8b: convert sRGB components to grayscale and composite on gray background */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1241-L1266 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_lin | static void
gpc_lin(Pixel *out, const Pixel *in, const Background *back)
{
(void)back;
out->r = ilinear(in->r);
if (in->g == in->r)
{
out->g = out->r;
if (in->b == in->r)
out->b = out->r;
else
out->b = ilinear(in->b);
}
else
{
out->g = ilinear(in->g);
if (in->b == in->r)
out->b = out->r;
else if (in->b == in->g)
out->b = out->g;
else
out->b = ilinear(in->b);
}
out->a = 65535;
} | /* 8-bit to 16-bit conversions */
/* lin: make sRGB components linear, alpha := 65535 */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1270-L1303 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_pre | static void
gpc_pre(Pixel *out, const Pixel *in, const Background *back)
{
(void)back;
out->r = ilineara(in->r, in->a);
if (in->g == in->r)
{
out->g = out->r;
if (in->b == in->r)
out->b = out->r;
else
out->b = ilineara(in->b, in->a);
}
else
{
out->g = ilineara(in->g, in->a);
if (in->b == in->r)
out->b = out->r;
else if (in->b == in->g)
out->b = out->g;
else
out->b = ilineara(in->b, in->a);
}
out->a = in->a * 257;
} | /* pre: make sRGB components linear and premultiply by alpha (scale alpha) */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1306-L1339 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_preq | static void
gpc_preq(Pixel *out, const Pixel *in, const Background *back)
{
(void)back;
out->r = ilineara(in->r, in->a);
if (in->g == in->r)
{
out->g = out->r;
if (in->b == in->r)
out->b = out->r;
else
out->b = ilineara(in->b, in->a);
}
else
{
out->g = ilineara(in->g, in->a);
if (in->b == in->r)
out->b = out->r;
else if (in->b == in->g)
out->b = out->g;
else
out->b = ilineara(in->b, in->a);
}
out->a = 65535;
} | /* pre': as 'pre' but alpha := 65535 */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1342-L1375 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_glin | static void
gpc_glin(Pixel *out, const Pixel *in, const Background *back)
{
(void)back;
if (in->r == in->g && in->g == in->b)
out->r = out->g = out->b = ilinear(in->g);
else
out->r = out->g = out->b = u16d(65535 *
YfromRGB(sRGB_to_d[in->r], sRGB_to_d[in->g], sRGB_to_d[in->b]));
out->a = 65535;
} | /* glin: make sRGB components linear, convert to grayscale, alpha := 65535 */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1378-L1391 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_gpre | static void
gpc_gpre(Pixel *out, const Pixel *in, const Background *back)
{
(void)back;
if (in->r == in->g && in->g == in->b)
out->r = out->g = out->b = ilineara(in->g, in->a);
else
out->r = out->g = out->b = u16d(in->a * 257 *
YfromRGB(sRGB_to_d[in->r], sRGB_to_d[in->g], sRGB_to_d[in->b]));
out->a = 257 * in->a;
} | /* gpre: make sRGB components grayscale and linear and premultiply by alpha */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1394-L1407 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_gprq | static void
gpc_gprq(Pixel *out, const Pixel *in, const Background *back)
{
(void)back;
if (in->r == in->g && in->g == in->b)
out->r = out->g = out->b = ilineara(in->g, in->a);
else
out->r = out->g = out->b = u16d(in->a * 257 *
YfromRGB(sRGB_to_d[in->r], sRGB_to_d[in->g], sRGB_to_d[in->b]));
out->a = 65535;
} | /* gpr': as 'gpre' but alpha := 65535 */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1410-L1423 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_Lin | static void
gpc_Lin(Pixel *out, const Pixel *in, const Background *back)
{
(void)back;
out->r = ilinear_g22(in->r);
if (in->g == in->r)
{
out->g = out->r;
if (in->b == in->r)
out->b = out->r;
else
out->b = ilinear_g22(in->b);
}
else
{
out->g = ilinear_g22(in->g);
if (in->b == in->r)
out->b = out->r;
else if (in->b == in->g)
out->b = out->g;
else
out->b = ilinear_g22(in->b);
}
out->a = 65535;
} | /* 8-bit to 16-bit conversions for gAMA 45455 encoded values */
/* Lin: make gAMA 45455 components linear, alpha := 65535 */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1427-L1460 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_Pre | static void
gpc_Pre(Pixel *out, const Pixel *in, const Background *back)
{
(void)back;
out->r = ilineara_g22(in->r, in->a);
if (in->g == in->r)
{
out->g = out->r;
if (in->b == in->r)
out->b = out->r;
else
out->b = ilineara_g22(in->b, in->a);
}
else
{
out->g = ilineara_g22(in->g, in->a);
if (in->b == in->r)
out->b = out->r;
else if (in->b == in->g)
out->b = out->g;
else
out->b = ilineara_g22(in->b, in->a);
}
out->a = in->a * 257;
} | /* Pre: make gAMA 45455 components linear and premultiply by alpha (scale alpha)
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1465-L1498 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_Preq | static void
gpc_Preq(Pixel *out, const Pixel *in, const Background *back)
{
(void)back;
out->r = ilineara_g22(in->r, in->a);
if (in->g == in->r)
{
out->g = out->r;
if (in->b == in->r)
out->b = out->r;
else
out->b = ilineara_g22(in->b, in->a);
}
else
{
out->g = ilineara_g22(in->g, in->a);
if (in->b == in->r)
out->b = out->r;
else if (in->b == in->g)
out->b = out->g;
else
out->b = ilineara_g22(in->b, in->a);
}
out->a = 65535;
} | /* Pre': as 'Pre' but alpha := 65535 */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1503-L1536 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_Glin | static void
gpc_Glin(Pixel *out, const Pixel *in, const Background *back)
{
(void)back;
if (in->r == in->g && in->g == in->b)
out->r = out->g = out->b = ilinear_g22(in->g);
else
out->r = out->g = out->b = u16d(65535 *
YfromRGB(g22_to_d[in->r], g22_to_d[in->g], g22_to_d[in->b]));
out->a = 65535;
} | /* Glin: make gAMA 45455 components linear, convert to grayscale, alpha := 65535
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1542-L1555 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_Gpre | static void
gpc_Gpre(Pixel *out, const Pixel *in, const Background *back)
{
(void)back;
if (in->r == in->g && in->g == in->b)
out->r = out->g = out->b = ilineara_g22(in->g, in->a);
else
out->r = out->g = out->b = u16d(in->a * 257 *
YfromRGB(g22_to_d[in->r], g22_to_d[in->g], g22_to_d[in->b]));
out->a = 257 * in->a;
} | /* Gpre: make gAMA 45455 components grayscale and linear and premultiply by
* alpha.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1562-L1575 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_Gprq | static void
gpc_Gprq(Pixel *out, const Pixel *in, const Background *back)
{
(void)back;
if (in->r == in->g && in->g == in->b)
out->r = out->g = out->b = ilineara_g22(in->g, in->a);
else
out->r = out->g = out->b = u16d(in->a * 257 *
YfromRGB(g22_to_d[in->r], g22_to_d[in->g], g22_to_d[in->b]));
out->a = 65535;
} | /* Gpr': as 'Gpre' but alpha := 65535 */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1580-L1593 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_sRGB | static void
gpc_sRGB(Pixel *out, const Pixel *in, const Background *back)
{
(void)back;
out->r = isRGB(in->r);
if (in->g == in->r)
{
out->g = out->r;
if (in->b == in->r)
out->b = out->r;
else
out->b = isRGB(in->b);
}
else
{
out->g = isRGB(in->g);
if (in->b == in->r)
out->b = out->r;
else if (in->b == in->g)
out->b = out->g;
else
out->b = isRGB(in->b);
}
out->a = 255;
} | /* 16-bit to 8-bit conversions */
/* sRGB: convert linear components to sRGB, alpha := 255 */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1598-L1631 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_unpg | static void
gpc_unpg(Pixel *out, const Pixel *in, const Background *back)
{
(void)back;
if (in->a <= 128)
{
out->r = out->g = out->b = 255;
out->a = 0;
}
else
{
out->r = out->g = out->b = sRGB((double)in->g / in->a);
out->a = u8d(in->a / 257.);
}
} | /* unpg: unpremultiply gray component and convert to sRGB (scale alpha) */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1634-L1650 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_unpc | static void
gpc_unpc(Pixel *out, const Pixel *in, const Background *back)
{
(void)back;
if (in->a <= 128)
{
out->r = out->g = out->b = 255;
out->a = 0;
}
else
{
out->r = sRGB((double)in->r / in->a);
out->g = sRGB((double)in->g / in->a);
out->b = sRGB((double)in->b / in->a);
out->a = u8d(in->a / 257.);
}
} | /* unpc: unpremultiply color components and convert to sRGB (scale alpha) */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1653-L1671 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_b16g | static void
gpc_b16g(Pixel *out, const Pixel *in, const Background *back)
{
if (in->a <= 0)
out->r = out->g = out->b = back->ig;
else
{
double a = in->a/65535.;
double a1 = 1-a;
a /= 65535;
out->r = out->g = out->b = sRGB(in->g * a + back->dg * a1);
}
out->a = 255;
} | /* b16g: composite linear onto gray background and convert the result to sRGB */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1674-L1690 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_b16c | static void
gpc_b16c(Pixel *out, const Pixel *in, const Background *back)
{
if (in->a <= 0)
{
out->r = back->ir;
out->g = back->ig;
out->b = back->ib;
}
else
{
double a = in->a/65535.;
double a1 = 1-a;
a /= 65535;
out->r = sRGB(in->r * a + back->dr * a1);
out->g = sRGB(in->g * a + back->dg * a1);
out->b = sRGB(in->b * a + back->db * a1);
}
out->a = 255;
} | /* b16c: composite linear onto color background and convert the result to sRGB*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1693-L1715 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_sG | static void
gpc_sG(Pixel *out, const Pixel *in, const Background *back)
{
(void)back;
out->r = out->g = out->b = sRGB(YfromRGBint(in->r, in->g, in->b)/65535);
out->a = 255;
} | /* sG: convert linear RGB to sRGB grayscale */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1718-L1725 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_sGp | static void
gpc_sGp(Pixel *out, const Pixel *in, const Background *back)
{
(void)back;
if (in->a <= 128)
{
out->r = out->g = out->b = 255;
out->a = 0;
}
else
{
out->r = out->g = out->b = sRGB(YfromRGBint(in->r, in->g, in->b)/in->a);
out->a = u8d(in->a / 257.);
}
} | /* sGp: unpremultiply RGB then convert to sRGB grayscale */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1728-L1744 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_sCp | static void
gpc_sCp(Pixel *out, const Pixel *in, const Background *back)
{
(void)back;
if (in->a <= 128)
{
out->r = out->g = out->b = 255;
out->a = 0;
}
else
{
out->r = sRGB((double)in->r / in->a);
out->g = sRGB((double)in->g / in->a);
out->b = sRGB((double)in->b / in->a);
out->a = u8d(in->a / 257.);
}
} | /* sCp: unpremultiply RGB then convert to sRGB */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1747-L1765 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_gb16 | static void
gpc_gb16(Pixel *out, const Pixel *in, const Background *back)
{
if (in->a <= 0)
out->r = out->g = out->b = back->ig;
else if (in->a >= 65535)
out->r = out->g = out->b = isRGB(in->g);
else
{
double a = in->a / 65535.;
double a1 = 1-a;
a /= 65535;
out->r = out->g = out->b = sRGB(in->g * a + back->dg * a1);
}
out->a = 255;
} | /* gb16: composite linear onto background and convert to sRGB grayscale */
/* (order doesn't matter, the composite and grayscale operations permute) */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1769-L1788 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_cb16 | static void
gpc_cb16(Pixel *out, const Pixel *in, const Background *back)
{
if (in->a <= 0)
{
out->r = back->ir;
out->g = back->ig;
out->b = back->ib;
}
else if (in->a >= 65535)
{
out->r = isRGB(in->r);
out->g = isRGB(in->g);
out->b = isRGB(in->b);
}
else
{
double a = in->a / 65535.;
double a1 = 1-a;
a /= 65535;
out->r = sRGB(in->r * a + back->dr * a1);
out->g = sRGB(in->g * a + back->dg * a1);
out->b = sRGB(in->b * a + back->db * a1);
}
out->a = 255;
} | /* cb16: composite linear onto background and convert to sRGB */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1791-L1820 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_A | static void
gpc_A(Pixel *out, const Pixel *in, const Background *back)
{
(void)back;
out->r = in->r;
out->g = in->g;
out->b = in->b;
out->a = 65535;
} | /* 16-bit to 16-bit conversions */
/* A: set alpha to 65535 */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1824-L1832 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_g16 | static void
gpc_g16(Pixel *out, const Pixel *in, const Background *back)
{
(void)back;
out->r = out->g = out->b = u16d(YfromRGBint(in->r, in->g, in->b));
out->a = 65535;
} | /* g16: convert linear RGB to linear grayscale (alpha := 65535) */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1835-L1841 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gpc_g16q | static void
gpc_g16q(Pixel *out, const Pixel *in, const Background *back)
{
(void)back;
out->r = out->g = out->b = u16d(YfromRGBint(in->r, in->g, in->b));
out->a = in->a;
} | /* g16': as 'g16' but alpha is unchanged */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L1844-L1850 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | transform_from_formats | static void
transform_from_formats(Transform *result, Image *in_image,
const Image *out_image, png_const_colorp background, int via_linear)
{
png_uint_32 in_format, out_format;
png_uint_32 in_base, out_base;
memset(result, 0, sizeof *result);
/* Store the original images for error messages */
result->in_image = in_image;
result->out_image = out_image;
in_format = in_image->image.format;
out_format = out_image->image.format;
if (in_format & PNG_FORMAT_FLAG_LINEAR)
result->in_opaque = 65535;
else
result->in_opaque = 255;
result->output_8bit = (out_format & PNG_FORMAT_FLAG_LINEAR) == 0;
result->is_palette = 0; /* set by caller if required */
result->accumulate = (in_image->opts & ACCUMULATE) != 0;
/* The loaders (which need the ordering information) */
result->in_gp = get_pixel(in_format);
result->out_gp = get_pixel(out_format);
/* Remove the ordering information: */
in_format &= BASE_FORMATS | PNG_FORMAT_FLAG_COLORMAP;
in_base = in_format & BASE_FORMATS;
out_format &= BASE_FORMATS | PNG_FORMAT_FLAG_COLORMAP;
out_base = out_format & BASE_FORMATS;
if (via_linear)
{
/* Check for an error in this program: */
if (out_format & (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_COLORMAP))
{
fprintf(stderr, "internal transform via linear error 0x%x->0x%x\n",
in_format, out_format);
exit(1);
}
result->transform = gpc_fn[in_base][out_base | PNG_FORMAT_FLAG_LINEAR];
result->from_linear = gpc_fn[out_base | PNG_FORMAT_FLAG_LINEAR][out_base];
result->error_ptr = gpc_error_via_linear[in_format][out_format];
}
else if (~in_format & out_format & PNG_FORMAT_FLAG_COLORMAP)
{
/* The input is not colormapped but the output is, the errors will
* typically be large (only the grayscale-no-alpha case permits preserving
* even 8-bit values.)
*/
result->transform = gpc_fn[in_base][out_base];
result->from_linear = NULL;
result->error_ptr = gpc_error_to_colormap[in_base][out_base];
}
else
{
/* The caller handles the colormap->pixel value conversion, so the
* transform function just gets a pixel value, however because libpng
* currently contains a different implementation for mapping a colormap if
* both input and output are colormapped we need different conversion
* functions to deal with errors in the libpng implementation.
*/
if (in_format & out_format & PNG_FORMAT_FLAG_COLORMAP)
result->transform = gpc_fn_colormapped[in_base][out_base];
else
result->transform = gpc_fn[in_base][out_base];
result->from_linear = NULL;
result->error_ptr = gpc_error[in_format][out_format];
}
/* Follow the libpng simplified API rules to work out what to pass to the gpc
* routines as a background value, if one is not required pass NULL so that
* this program crashes in the even of a programming error.
*/
result->background = NULL; /* default: not required */
/* Rule 1: background only need be supplied if alpha is to be removed */
if (in_format & ~out_format & PNG_FORMAT_FLAG_ALPHA)
{
/* The input value is 'NULL' to use the background and (otherwise) an sRGB
* background color (to use a solid color). The code above uses a fixed
* byte value, BUFFER_INIT8, for buffer even for 16-bit output. For
* linear (16-bit) output the sRGB background color is ignored; the
* composition is always on the background (so BUFFER_INIT8 * 257), except
* that for the colormap (i.e. linear colormapped output) black is used.
*/
result->background = &result->background_color;
if (out_format & PNG_FORMAT_FLAG_LINEAR || via_linear)
{
if (out_format & PNG_FORMAT_FLAG_COLORMAP)
{
result->background_color.ir =
result->background_color.ig =
result->background_color.ib = 0;
result->background_color.dr =
result->background_color.dg =
result->background_color.db = 0;
}
else
{
result->background_color.ir =
result->background_color.ig =
result->background_color.ib = BUFFER_INIT8 * 257;
result->background_color.dr =
result->background_color.dg =
result->background_color.db = 0;
}
}
else /* sRGB output */
{
if (background != NULL)
{
if (out_format & PNG_FORMAT_FLAG_COLOR)
{
result->background_color.ir = background->red;
result->background_color.ig = background->green;
result->background_color.ib = background->blue;
/* TODO: sometimes libpng uses the power law conversion here, how
* to handle this?
*/
result->background_color.dr = sRGB_to_d[background->red];
result->background_color.dg = sRGB_to_d[background->green];
result->background_color.db = sRGB_to_d[background->blue];
}
else /* grayscale: libpng only looks at 'g' */
{
result->background_color.ir =
result->background_color.ig =
result->background_color.ib = background->green;
/* TODO: sometimes libpng uses the power law conversion here, how
* to handle this?
*/
result->background_color.dr =
result->background_color.dg =
result->background_color.db = sRGB_to_d[background->green];
}
}
else if ((out_format & PNG_FORMAT_FLAG_COLORMAP) == 0)
{
result->background_color.ir =
result->background_color.ig =
result->background_color.ib = BUFFER_INIT8;
/* TODO: sometimes libpng uses the power law conversion here, how
* to handle this?
*/
result->background_color.dr =
result->background_color.dg =
result->background_color.db = sRGB_to_d[BUFFER_INIT8];
}
/* Else the output is colormapped and a background color must be
* provided; if pngstest crashes then that is a bug in this program
* (though libpng should png_error as well.)
*/
else
result->background = NULL;
}
}
if (result->background == NULL)
{
result->background_color.ir =
result->background_color.ig =
result->background_color.ib = -1; /* not used */
result->background_color.dr =
result->background_color.dg =
result->background_color.db = 1E30; /* not used */
}
/* Copy the error values into the Transform: */
result->error[0] = result->error_ptr[0];
result->error[1] = result->error_ptr[1];
result->error[2] = result->error_ptr[2];
result->error[3] = result->error_ptr[3];
} | /* Return a 'transform' as above for the given format conversion. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L2134-L2322 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | init_error_via_linear | static void
init_error_via_linear(void)
{
int alpha;
error_via_linear[0] = 255; /* transparent pixel */
for (alpha=1; alpha<=255; ++alpha)
{
/* 16-bit values less than 128.5 get rounded to 8-bit 0 and so the worst
* case error arises with 16-bit 128.5, work out what sRGB
* (non-associated) value generates 128.5; any value less than this is
* going to map to 0, so the worst error is floor(value).
*
* Note that errors are considerably higher (more than a factor of 2)
* because libpng uses a simple power law for sRGB data at present.
*
* Add .1 for arithmetic errors inside libpng.
*/
double v = floor(255*pow(.5/*(128.5 * 255 / 65535)*/ / alpha, 1/2.2)+.1);
error_via_linear[alpha] = (int)v;
}
/* This is actually 14.99, but, despite the closeness to 15, 14 seems to work
* ok in this case.
*/
error_in_libpng_gamma = 14;
} | /* Indexed by 8-bit alpha */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L2356-L2384 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | compare_two_images | static int
compare_two_images(Image *a, Image *b, int via_linear,
png_const_colorp background)
{
ptrdiff_t stridea = a->stride;
ptrdiff_t strideb = b->stride;
png_const_bytep rowa = a->buffer+16;
png_const_bytep rowb = b->buffer+16;
const png_uint_32 width = a->image.width;
const png_uint_32 height = a->image.height;
const png_uint_32 formata = a->image.format;
const png_uint_32 formatb = b->image.format;
const unsigned int a_sample = PNG_IMAGE_SAMPLE_SIZE(formata);
const unsigned int b_sample = PNG_IMAGE_SAMPLE_SIZE(formatb);
int alpha_added, alpha_removed;
int bchannels;
int btoa[4];
png_uint_32 y;
Transform tr;
/* This should never happen: */
if (width != b->image.width || height != b->image.height)
return logerror(a, a->file_name, ": width x height changed: ",
b->file_name);
/* Set up the background and the transform */
transform_from_formats(&tr, a, b, background, via_linear);
/* Find the first row and inter-row space. */
if (!(formata & PNG_FORMAT_FLAG_COLORMAP) &&
(formata & PNG_FORMAT_FLAG_LINEAR))
stridea *= 2;
if (!(formatb & PNG_FORMAT_FLAG_COLORMAP) &&
(formatb & PNG_FORMAT_FLAG_LINEAR))
strideb *= 2;
if (stridea < 0) rowa += (height-1) * (-stridea);
if (strideb < 0) rowb += (height-1) * (-strideb);
/* First shortcut the two colormap case by comparing the image data; if it
* matches then we expect the colormaps to match, although this is not
* absolutely necessary for an image match. If the colormaps fail to match
* then there is a problem in libpng.
*/
if (formata & formatb & PNG_FORMAT_FLAG_COLORMAP)
{
/* Only check colormap entries that actually exist; */
png_const_bytep ppa, ppb;
int match;
png_byte in_use[256], amax = 0, bmax = 0;
memset(in_use, 0, sizeof in_use);
ppa = rowa;
ppb = rowb;
/* Do this the slow way to accumulate the 'in_use' flags, don't break out
* of the loop until the end; this validates the color-mapped data to
* ensure all pixels are valid color-map indexes.
*/
for (y=0, match=1; y<height && match; ++y, ppa += stridea, ppb += strideb)
{
png_uint_32 x;
for (x=0; x<width; ++x)
{
png_byte bval = ppb[x];
png_byte aval = ppa[x];
if (bval > bmax)
bmax = bval;
if (bval != aval)
match = 0;
in_use[aval] = 1;
if (aval > amax)
amax = aval;
}
}
/* If the buffers match then the colormaps must too. */
if (match)
{
/* Do the color-maps match, entry by entry? Only check the 'in_use'
* entries. An error here should be logged as a color-map error.
*/
png_const_bytep a_cmap = (png_const_bytep)a->colormap;
png_const_bytep b_cmap = (png_const_bytep)b->colormap;
int result = 1; /* match by default */
/* This is used in logpixel to get the error message correct. */
tr.is_palette = 1;
for (y=0; y<256; ++y, a_cmap += a_sample, b_cmap += b_sample)
if (in_use[y])
{
/* The colormap entries should be valid, but because libpng doesn't
* do any checking at present the original image may contain invalid
* pixel values. These cause an error here (at present) unless
* accumulating errors in which case the program just ignores them.
*/
if (y >= a->image.colormap_entries)
{
if ((a->opts & ACCUMULATE) == 0)
{
char pindex[9];
sprintf(pindex, "%lu[%lu]", (unsigned long)y,
(unsigned long)a->image.colormap_entries);
logerror(a, a->file_name, ": bad pixel index: ", pindex);
}
result = 0;
}
else if (y >= b->image.colormap_entries)
{
if ((a->opts & ACCUMULATE) == 0)
{
char pindex[9];
sprintf(pindex, "%lu[%lu]", (unsigned long)y,
(unsigned long)b->image.colormap_entries);
logerror(b, b->file_name, ": bad pixel index: ", pindex);
}
result = 0;
}
/* All the mismatches are logged here; there can only be 256! */
else if (!cmppixel(&tr, a_cmap, b_cmap, 0, y))
result = 0;
}
/* If reqested copy the error values back from the Transform. */
if (a->opts & ACCUMULATE)
{
tr.error_ptr[0] = tr.error[0];
tr.error_ptr[1] = tr.error[1];
tr.error_ptr[2] = tr.error[2];
tr.error_ptr[3] = tr.error[3];
result = 1; /* force a continue */
}
return result;
}
/* else the image buffers don't match pixel-wise so compare sample values
* instead, but first validate that the pixel indexes are in range (but
* only if not accumulating, when the error is ignored.)
*/
else if ((a->opts & ACCUMULATE) == 0)
{
/* Check the original image first,
* TODO: deal with input images with bad pixel values?
*/
if (amax >= a->image.colormap_entries)
{
char pindex[9];
sprintf(pindex, "%d[%lu]", amax,
(unsigned long)a->image.colormap_entries);
return logerror(a, a->file_name, ": bad pixel index: ", pindex);
}
else if (bmax >= b->image.colormap_entries)
{
char pindex[9];
sprintf(pindex, "%d[%lu]", bmax,
(unsigned long)b->image.colormap_entries);
return logerror(b, b->file_name, ": bad pixel index: ", pindex);
}
}
}
/* We can directly compare pixel values without the need to use the read
* or transform support (i.e. a memory compare) if:
*
* 1) The bit depth has not changed.
* 2) RGB to grayscale has not been done (the reverse is ok; we just compare
* the three RGB values to the original grayscale.)
* 3) An alpha channel has not been removed from an 8-bit format, or the
* 8-bit alpha value of the pixel was 255 (opaque).
*
* If an alpha channel has been *added* then it must have the relevant opaque
* value (255 or 65535).
*
* The fist two the tests (in the order given above) (using the boolean
* equivalence !a && !b == !(a || b))
*/
if (!(((formata ^ formatb) & PNG_FORMAT_FLAG_LINEAR) |
(formata & (formatb ^ PNG_FORMAT_FLAG_COLOR) & PNG_FORMAT_FLAG_COLOR)))
{
/* Was an alpha channel changed? */
const png_uint_32 alpha_changed = (formata ^ formatb) &
PNG_FORMAT_FLAG_ALPHA;
/* Was an alpha channel removed? (The third test.) If so the direct
* comparison is only possible if the input alpha is opaque.
*/
alpha_removed = (formata & alpha_changed) != 0;
/* Was an alpha channel added? */
alpha_added = (formatb & alpha_changed) != 0;
/* The channels may have been moved between input and output, this finds
* out how, recording the result in the btoa array, which says where in
* 'a' to find each channel of 'b'. If alpha was added then btoa[alpha]
* ends up as 4 (and is not used.)
*/
{
int i;
png_byte aloc[4];
png_byte bloc[4];
/* The following are used only if the formats match, except that
* 'bchannels' is a flag for matching formats. btoa[x] says, for each
* channel in b, where to find the corresponding value in a, for the
* bchannels. achannels may be different for a gray to rgb transform
* (a will be 1 or 2, b will be 3 or 4 channels.)
*/
(void)component_loc(aloc, formata);
bchannels = component_loc(bloc, formatb);
/* Hence the btoa array. */
for (i=0; i<4; ++i) if (bloc[i] < 4)
btoa[bloc[i]] = aloc[i]; /* may be '4' for alpha */
if (alpha_added)
alpha_added = bloc[0]; /* location of alpha channel in image b */
else
alpha_added = 4; /* Won't match an image b channel */
if (alpha_removed)
alpha_removed = aloc[0]; /* location of alpha channel in image a */
else
alpha_removed = 4;
}
}
else
{
/* Direct compare is not possible, cancel out all the corresponding local
* variables.
*/
bchannels = 0;
alpha_removed = alpha_added = 4;
btoa[3] = btoa[2] = btoa[1] = btoa[0] = 4; /* 4 == not present */
}
for (y=0; y<height; ++y, rowa += stridea, rowb += strideb)
{
png_const_bytep ppa, ppb;
png_uint_32 x;
for (x=0, ppa=rowa, ppb=rowb; x<width; ++x)
{
png_const_bytep psa, psb;
if (formata & PNG_FORMAT_FLAG_COLORMAP)
psa = (png_const_bytep)a->colormap + a_sample * *ppa++;
else
psa = ppa, ppa += a_sample;
if (formatb & PNG_FORMAT_FLAG_COLORMAP)
psb = (png_const_bytep)b->colormap + b_sample * *ppb++;
else
psb = ppb, ppb += b_sample;
/* Do the fast test if possible. */
if (bchannels)
{
/* Check each 'b' channel against either the corresponding 'a'
* channel or the opaque alpha value, as appropriate. If
* alpha_removed value is set (not 4) then also do this only if the
* 'a' alpha channel (alpha_removed) is opaque; only relevant for
* the 8-bit case.
*/
if (formatb & PNG_FORMAT_FLAG_LINEAR) /* 16-bit checks */
{
png_const_uint_16p pua = aligncastconst(png_const_uint_16p, psa);
png_const_uint_16p pub = aligncastconst(png_const_uint_16p, psb);
switch (bchannels)
{
case 4:
if (pua[btoa[3]] != pub[3]) break;
case 3:
if (pua[btoa[2]] != pub[2]) break;
case 2:
if (pua[btoa[1]] != pub[1]) break;
case 1:
if (pua[btoa[0]] != pub[0]) break;
if (alpha_added != 4 && pub[alpha_added] != 65535) break;
continue; /* x loop */
default:
break; /* impossible */
}
}
else if (alpha_removed == 4 || psa[alpha_removed] == 255)
{
switch (bchannels)
{
case 4:
if (psa[btoa[3]] != psb[3]) break;
case 3:
if (psa[btoa[2]] != psb[2]) break;
case 2:
if (psa[btoa[1]] != psb[1]) break;
case 1:
if (psa[btoa[0]] != psb[0]) break;
if (alpha_added != 4 && psb[alpha_added] != 255) break;
continue; /* x loop */
default:
break; /* impossible */
}
}
}
/* If we get to here the fast match failed; do the slow match for this
* pixel.
*/
if (!cmppixel(&tr, psa, psb, x, y) && (a->opts & KEEP_GOING) == 0)
return 0; /* error case */
}
}
/* If reqested copy the error values back from the Transform. */
if (a->opts & ACCUMULATE)
{
tr.error_ptr[0] = tr.error[0];
tr.error_ptr[1] = tr.error[1];
tr.error_ptr[2] = tr.error[2];
tr.error_ptr[3] = tr.error[3];
}
return 1;
} | /* Compare two images, the original 'a', which was written out then read back in
* to * give image 'b'. The formats may have been changed.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L2665-L3002 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | read_file | static int
read_file(Image *image, png_uint_32 format, png_const_colorp background)
{
memset(&image->image, 0, sizeof image->image);
image->image.version = PNG_IMAGE_VERSION;
if (image->input_memory != NULL)
{
if (!png_image_begin_read_from_memory(&image->image, image->input_memory,
image->input_memory_size))
return logerror(image, "memory init: ", image->file_name, "");
}
else if (image->input_file != NULL)
{
if (!png_image_begin_read_from_stdio(&image->image, image->input_file))
return logerror(image, "stdio init: ", image->file_name, "");
}
else
{
if (!png_image_begin_read_from_file(&image->image, image->file_name))
return logerror(image, "file init: ", image->file_name, "");
}
/* This must be set after the begin_read call: */
if (image->opts & sRGB_16BIT)
image->image.flags |= PNG_IMAGE_FLAG_16BIT_sRGB;
/* Have an initialized image with all the data we need plus, maybe, an
* allocated file (myfile) or buffer (mybuffer) that need to be freed.
*/
{
int result;
png_uint_32 image_format;
/* Print both original and output formats. */
image_format = image->image.format;
if (image->opts & VERBOSE)
{
printf("%s %lu x %lu %s -> %s", image->file_name,
(unsigned long)image->image.width,
(unsigned long)image->image.height,
format_names[image_format & FORMAT_MASK],
(format & FORMAT_NO_CHANGE) != 0 || image->image.format == format
? "no change" : format_names[format & FORMAT_MASK]);
if (background != NULL)
printf(" background(%d,%d,%d)\n", background->red,
background->green, background->blue);
else
printf("\n");
fflush(stdout);
}
/* 'NO_CHANGE' combined with the color-map flag forces the base format
* flags to be set on read to ensure that the original representation is
* not lost in the pass through a colormap format.
*/
if ((format & FORMAT_NO_CHANGE) != 0)
{
if ((format & PNG_FORMAT_FLAG_COLORMAP) != 0 &&
(image_format & PNG_FORMAT_FLAG_COLORMAP) != 0)
format = (image_format & ~BASE_FORMATS) | (format & BASE_FORMATS);
else
format = image_format;
}
image->image.format = format;
image->stride = PNG_IMAGE_ROW_STRIDE(image->image) + image->stride_extra;
allocbuffer(image);
result = png_image_finish_read(&image->image, background,
image->buffer+16, (png_int_32)image->stride, image->colormap);
checkbuffer(image, image->file_name);
if (result)
return checkopaque(image);
else
return logerror(image, image->file_name, ": image read failed", "");
}
} | /* Read the file; how the read gets done depends on which of input_file and
* input_memory have been set.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L3007-L3094 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | read_one_file | static int
read_one_file(Image *image)
{
if (!(image->opts & READ_FILE) || (image->opts & USE_STDIO))
{
/* memory or stdio. */
FILE *f = fopen(image->file_name, "rb");
if (f != NULL)
{
if (image->opts & READ_FILE)
image->input_file = f;
else /* memory */
{
if (fseek(f, 0, SEEK_END) == 0)
{
long int cb = ftell(f);
if (cb > 0 && (unsigned long int)cb < (size_t)~(size_t)0)
{
png_bytep b = voidcast(png_bytep, malloc((size_t)cb));
if (b != NULL)
{
rewind(f);
if (fread(b, (size_t)cb, 1, f) == 1)
{
fclose(f);
image->input_memory_size = cb;
image->input_memory = b;
}
else
{
free(b);
return logclose(image, f, image->file_name,
": read failed: ");
}
}
else
return logclose(image, f, image->file_name,
": out of memory: ");
}
else if (cb == 0)
return logclose(image, f, image->file_name,
": zero length: ");
else
return logclose(image, f, image->file_name,
": tell failed: ");
}
else
return logclose(image, f, image->file_name, ": seek failed: ");
}
}
else
return logerror(image, image->file_name, ": open failed: ",
strerror(errno));
}
return read_file(image, FORMAT_NO_CHANGE, NULL);
} | /* Reads from a filename, which must be in image->file_name, but uses
* image->opts to choose the method. The file is always read in its native
* format (the one the simplified API suggests).
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L3100-L3167 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | main | int main(void)
{
fprintf(stderr, "pngstest: no read support in libpng, test skipped\n");
/* So the test is skipped: */
return 77;
} | /* !PNG_SIMPLIFIED_READ_SUPPORTED */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngstest.c#L3736-L3741 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | fix | static png_fixed_point
fix(double d)
{
d = floor(d * PNG_FP_1 + .5);
return (png_fixed_point)d;
} | /* Convert a double precision value to fixed point. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L182-L187 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | row_copy | static void
row_copy(png_bytep toBuffer, png_const_bytep fromBuffer, unsigned int bitWidth)
{
memcpy(toBuffer, fromBuffer, bitWidth >> 3);
if ((bitWidth & 7) != 0)
{
unsigned int mask;
toBuffer += bitWidth >> 3;
fromBuffer += bitWidth >> 3;
/* The remaining bits are in the top of the byte, the mask is the bits to
* retain.
*/
mask = 0xff >> (bitWidth & 7);
*toBuffer = (png_byte)((*toBuffer & mask) | (*fromBuffer & ~mask));
}
} | /* Copy a complete row of pixels, taking into account potential partial
* bytes at the end.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L482-L499 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | pixel_cmp | static int
pixel_cmp(png_const_bytep pa, png_const_bytep pb, png_uint_32 bit_width)
{
#if PNG_LIBPNG_VER < 10506
if (memcmp(pa, pb, bit_width>>3) == 0)
{
png_uint_32 p;
if ((bit_width & 7) == 0) return 0;
/* Ok, any differences? */
p = pa[bit_width >> 3];
p ^= pb[bit_width >> 3];
if (p == 0) return 0;
/* There are, but they may not be significant, remove the bits
* after the end (the low order bits in PNG.)
*/
bit_width &= 7;
p >>= 8-bit_width;
if (p == 0) return 0;
}
#else
/* From libpng-1.5.6 the overwrite should be fixed, so compare the trailing
* bits too:
*/
if (memcmp(pa, pb, (bit_width+7)>>3) == 0)
return 0;
#endif
/* Return the index of the changed byte. */
{
png_uint_32 where = 0;
while (pa[where] == pb[where]) ++where;
return 1+where;
}
} | /* Compare pixels - they are assumed to start at the first byte in the
* given buffers.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L504-L543 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | random_32 | static png_uint_32
random_32(void)
{
for(;;)
{
png_byte mark[4];
png_uint_32 result;
store_pool_mark(mark);
result = png_get_uint_32(mark);
if (result != 0)
return result;
}
} | /* Use this for random 32 bit values; this function makes sure the result is
* non-zero.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L659-L674 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | internal_error | static void
internal_error(png_store *ps, png_const_charp message)
{
store_log(ps, NULL, message, 1 /* error */);
/* And finally throw an exception. */
{
struct exception_context *the_exception_context = &ps->exception_context;
Throw ps;
}
} | /* Internal error function, called with a png_store but no libpng stuff. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L883-L893 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | store_read_buffer_avail | static size_t
store_read_buffer_avail(png_store *ps)
{
if (ps->current != NULL && ps->next != NULL)
{
png_store_buffer *next = &ps->current->data;
size_t cbAvail = ps->current->datacount;
while (next != ps->next && next != NULL)
{
next = next->prev;
cbAvail += STORE_BUFFER_SIZE;
}
if (next != ps->next)
png_error(ps->pread, "buffer read error");
if (cbAvail > ps->readpos)
return cbAvail - ps->readpos;
}
return 0;
} | /* Return total bytes available for read. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L1111-L1133 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | store_read_imp | static void
store_read_imp(png_store *ps, png_bytep pb, png_size_t st)
{
if (ps->current == NULL || ps->next == NULL)
png_error(ps->pread, "store state damaged");
while (st > 0)
{
size_t cbAvail = store_read_buffer_size(ps) - ps->readpos;
if (cbAvail > 0)
{
if (cbAvail > st) cbAvail = st;
memcpy(pb, ps->next->buffer + ps->readpos, cbAvail);
st -= cbAvail;
pb += cbAvail;
ps->readpos += cbAvail;
}
else if (!store_read_buffer_next(ps))
png_error(ps->pread, "read beyond end of file");
}
} | /* Need separate implementation and callback to allow use of the same code
* during progressive read, where the io_ptr is set internally by libpng.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L1162-L1184 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | set_store_for_read | static png_structp
set_store_for_read(png_store *ps, png_infopp ppi, png_uint_32 id,
PNG_CONST char *name)
{
/* Set the name for png_error */
safecat(ps->test, sizeof ps->test, 0, name);
if (ps->pread != NULL)
png_error(ps->pread, "read store already in use");
store_read_reset(ps);
/* Both the create APIs can return NULL if used in their default mode
* (because there is no other way of handling an error because the jmp_buf
* by default is stored in png_struct and that has not been allocated!)
* However, given that store_error works correctly in these circumstances
* we don't ever expect NULL in this program.
*/
if (ps->speed)
ps->pread = png_create_read_struct(PNG_LIBPNG_VER_STRING, ps,
store_error, store_warning);
else
ps->pread = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, ps,
store_error, store_warning, &ps->read_memory_pool, store_malloc,
store_free);
if (ps->pread == NULL)
{
struct exception_context *the_exception_context = &ps->exception_context;
store_log(ps, NULL, "png_create_read_struct returned NULL (unexpected)",
1 /*error*/);
Throw ps;
}
store_read_set(ps, id);
if (ppi != NULL)
*ppi = ps->piread = png_create_info_struct(ps->pread);
return ps->pread;
} | /* The main interface for reading a saved file - pass the id number of the file
* to retrieve. Ids must be unique or the earlier file will be hidden. The API
* returns a png_struct and, optionally, a png_info. Both of these will be
* destroyed by store_read_reset above.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L1599-L1642 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | outerr | static double outerr(PNG_CONST png_modifier *pm, int in_depth, int out_depth)
{
/* There is a serious error in the 2 and 4 bit grayscale transform because
* the gamma table value (8 bits) is simply shifted, not rounded, so the
* error in 4 bit grayscale gamma is up to the value below. This is a hack
* to allow pngvalid to succeed:
*
* TODO: fix this in libpng
*/
if (out_depth == 2)
return .73182-.5;
if (out_depth == 4)
return .90644-.5;
if (out_depth == 16 && (in_depth == 16 ||
!pm->calculations_use_input_precision))
return pm->maxout16;
/* This is the case where the value was calculated at 8-bit precision then
* scaled to 16 bits.
*/
else if (out_depth == 16)
return pm->maxout8 * 257;
else
return pm->maxout8;
} | /* Output error - the error in the encoded value. This is determined by the
* digitization of the output so can be +/-0.5 in the actual output value. In
* the expand_16 case with the current code in libpng the expand happens after
* all the calculations are done in 8 bit arithmetic, so even though the output
* depth is 16 the output error is determined by the 8 bit calculation.
*
* This limit is not determined by the bit depth of internal calculations.
*
* The specified parameter does *not* include the base .5 digitization error but
* it is added here.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L2053-L2080 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | outlog | static double outlog(PNG_CONST png_modifier *pm, int in_depth, int out_depth)
{
/* The command line parameters are either 8 bit (0..255) or 16 bit (0..65535)
* and so must be adjusted for low bit depth grayscale:
*/
if (out_depth <= 8)
{
if (pm->log8 == 0) /* switched off */
return 256;
if (out_depth < 8)
return pm->log8 / 255 * ((1<<out_depth)-1);
return pm->log8;
}
if (out_depth == 16 && (in_depth == 16 ||
!pm->calculations_use_input_precision))
{
if (pm->log16 == 0)
return 65536;
return pm->log16;
}
/* This is the case where the value was calculated at 8-bit precision then
* scaled to 16 bits.
*/
if (pm->log8 == 0)
return 65536;
return pm->log8 * 257;
} | /* This does the same thing as the above however it returns the value to log,
* rather than raising a warning. This is useful for debugging to track down
* exactly what set of parameters cause high error values.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L2086-L2118 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | output_quantization_factor | static int output_quantization_factor(PNG_CONST png_modifier *pm, int in_depth,
int out_depth)
{
if (out_depth == 16 && in_depth != 16
&& pm->calculations_use_input_precision)
return 257;
else
return 1;
} | /* This complements the above by providing the appropriate quantization for the
* final value. Normally this would just be quantization to an integral value,
* but in the 8 bit calculation case it's actually quantization to a multiple of
* 257!
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L2125-L2133 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | modifier_total_encodings | static unsigned int
modifier_total_encodings(PNG_CONST png_modifier *pm)
{
return 1 + /* (1) nothing */
pm->ngammas + /* (2) gamma values to test */
pm->nencodings + /* (3) total number of encodings */
/* The following test only works after the first time through the
* png_modifier code because 'bit_depth' is set when the IHDR is read.
* modifier_reset, below, preserves the setting until after it has called
* the iterate function (also below.)
*
* For this reason do not rely on this function outside a call to
* modifier_reset.
*/
((pm->bit_depth == 16 || pm->assume_16_bit_calculations) ?
pm->nencodings : 0); /* (4) encodings with gamma == 1.0 */
} | /* Iterate through the usefully testable color encodings. An encoding is one
* of:
*
* 1) Nothing (no color space, no gamma).
* 2) Just a gamma value from the gamma array (including 1.0)
* 3) A color space from the encodings array with the corresponding gamma.
* 4) The same, but with gamma 1.0 (only really useful with 16 bit calculations)
*
* The iterator selects these in turn, the randomizer selects one at random,
* which is used depends on the setting of the 'test_exhaustive' flag. Notice
* that this function changes the colour space encoding so it must only be
* called on completion of the previous test. This is what 'modifier_reset'
* does, below.
*
* After the function has been called the 'repeat' flag will still be set; the
* caller of modifier_reset must reset it at the start of each run of the test!
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L2231-L2247 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | modifier_set_encoding | static void
modifier_set_encoding(png_modifier *pm)
{
/* Set the encoding to the one specified by the current encoding counter,
* first clear out all the settings - this corresponds to an encoding_counter
* of 0.
*/
pm->current_gamma = 0;
pm->current_encoding = 0;
pm->encoding_ignored = 0; /* not ignored yet - happens in _ini functions. */
/* Now, if required, set the gamma and encoding fields. */
if (pm->encoding_counter > 0)
{
/* The gammas[] array is an array of screen gammas, not encoding gammas,
* so we need the inverse:
*/
if (pm->encoding_counter <= pm->ngammas)
pm->current_gamma = 1/pm->gammas[pm->encoding_counter-1];
else
{
unsigned int i = pm->encoding_counter - pm->ngammas;
if (i >= pm->nencodings)
{
i %= pm->nencodings;
pm->current_gamma = 1; /* Linear, only in the 16 bit case */
}
else
pm->current_gamma = pm->encodings[i].gamma;
pm->current_encoding = pm->encodings + i;
}
}
} | /* The following must be called before anything else to get the encoding set up
* on the modifier. In particular it must be called before the transform init
* functions are called.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L2306-L2342 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | modifier_color_encoding_is_sRGB | static int
modifier_color_encoding_is_sRGB(PNG_CONST png_modifier *pm)
{
return pm->current_encoding != 0 && pm->current_encoding == pm->encodings &&
pm->current_encoding->gamma == pm->current_gamma;
} | /* Enquiry functions to find out what is set. Notice that there is an implicit
* assumption below that the first encoding in the list is the one for sRGB.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L2347-L2352 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | modifier_crc | static void
modifier_crc(png_bytep buffer)
{
/* Recalculate the chunk CRC - a complete chunk must be in
* the buffer, at the start.
*/
uInt datalen = png_get_uint_32(buffer);
uLong crc = crc32(0, buffer+4, datalen+4);
/* The cast to png_uint_32 is safe because a crc32 is always a 32 bit value.
*/
png_save_uint_32(buffer+datalen+8, (png_uint_32)crc);
} | /* The guts of modification are performed during a read. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L2372-L2383 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | modifier_read_imp | static void
modifier_read_imp(png_modifier *pm, png_bytep pb, png_size_t st)
{
while (st > 0)
{
size_t cb;
png_uint_32 len, chunk;
png_modification *mod;
if (pm->buffer_position >= pm->buffer_count) switch (pm->state)
{
static png_byte sign[8] = { 137, 80, 78, 71, 13, 10, 26, 10 };
case modifier_start:
store_read_imp(&pm->this, pm->buffer, 8); /* size of signature. */
pm->buffer_count = 8;
pm->buffer_position = 0;
if (memcmp(pm->buffer, sign, 8) != 0)
png_error(pm->this.pread, "invalid PNG file signature");
pm->state = modifier_signature;
break;
case modifier_signature:
store_read_imp(&pm->this, pm->buffer, 13+12); /* size of IHDR */
pm->buffer_count = 13+12;
pm->buffer_position = 0;
if (png_get_uint_32(pm->buffer) != 13 ||
png_get_uint_32(pm->buffer+4) != CHUNK_IHDR)
png_error(pm->this.pread, "invalid IHDR");
/* Check the list of modifiers for modifications to the IHDR. */
mod = pm->modifications;
while (mod != NULL)
{
if (mod->chunk == CHUNK_IHDR && mod->modify_fn &&
(*mod->modify_fn)(pm, mod, 0))
{
mod->modified = 1;
modifier_setbuffer(pm);
}
/* Ignore removal or add if IHDR! */
mod = mod->next;
}
/* Cache information from the IHDR (the modified one.) */
pm->bit_depth = pm->buffer[8+8];
pm->colour_type = pm->buffer[8+8+1];
pm->state = modifier_IHDR;
pm->flush = 0;
break;
case modifier_IHDR:
default:
/* Read a new chunk and process it until we see PLTE, IDAT or
* IEND. 'flush' indicates that there is still some data to
* output from the preceding chunk.
*/
if ((cb = pm->flush) > 0)
{
if (cb > st) cb = st;
pm->flush -= cb;
store_read_imp(&pm->this, pb, cb);
pb += cb;
st -= cb;
if (st == 0) return;
}
/* No more bytes to flush, read a header, or handle a pending
* chunk.
*/
if (pm->pending_chunk != 0)
{
png_save_uint_32(pm->buffer, pm->pending_len);
png_save_uint_32(pm->buffer+4, pm->pending_chunk);
pm->pending_len = 0;
pm->pending_chunk = 0;
}
else
store_read_imp(&pm->this, pm->buffer, 8);
pm->buffer_count = 8;
pm->buffer_position = 0;
/* Check for something to modify or a terminator chunk. */
len = png_get_uint_32(pm->buffer);
chunk = png_get_uint_32(pm->buffer+4);
/* Terminators first, they may have to be delayed for added
* chunks
*/
if (chunk == CHUNK_PLTE || chunk == CHUNK_IDAT ||
chunk == CHUNK_IEND)
{
mod = pm->modifications;
while (mod != NULL)
{
if ((mod->add == chunk ||
(mod->add == CHUNK_PLTE && chunk == CHUNK_IDAT)) &&
mod->modify_fn != NULL && !mod->modified && !mod->added)
{
/* Regardless of what the modify function does do not run
* this again.
*/
mod->added = 1;
if ((*mod->modify_fn)(pm, mod, 1 /*add*/))
{
/* Reset the CRC on a new chunk */
if (pm->buffer_count > 0)
modifier_setbuffer(pm);
else
{
pm->buffer_position = 0;
mod->removed = 1;
}
/* The buffer has been filled with something (we assume)
* so output this. Pend the current chunk.
*/
pm->pending_len = len;
pm->pending_chunk = chunk;
break; /* out of while */
}
}
mod = mod->next;
}
/* Don't do any further processing if the buffer was modified -
* otherwise the code will end up modifying a chunk that was
* just added.
*/
if (mod != NULL)
break; /* out of switch */
}
/* If we get to here then this chunk may need to be modified. To
* do this it must be less than 1024 bytes in total size, otherwise
* it just gets flushed.
*/
if (len+12 <= sizeof pm->buffer)
{
store_read_imp(&pm->this, pm->buffer+pm->buffer_count,
len+12-pm->buffer_count);
pm->buffer_count = len+12;
/* Check for a modification, else leave it be. */
mod = pm->modifications;
while (mod != NULL)
{
if (mod->chunk == chunk)
{
if (mod->modify_fn == NULL)
{
/* Remove this chunk */
pm->buffer_count = pm->buffer_position = 0;
mod->removed = 1;
break; /* Terminate the while loop */
}
else if ((*mod->modify_fn)(pm, mod, 0))
{
mod->modified = 1;
/* The chunk may have been removed: */
if (pm->buffer_count == 0)
{
pm->buffer_position = 0;
break;
}
modifier_setbuffer(pm);
}
}
mod = mod->next;
}
}
else
pm->flush = len+12 - pm->buffer_count; /* data + crc */
/* Take the data from the buffer (if there is any). */
break;
}
/* Here to read from the modifier buffer (not directly from
* the store, as in the flush case above.)
*/
cb = pm->buffer_count - pm->buffer_position;
if (cb > st)
cb = st;
memcpy(pb, pm->buffer + pm->buffer_position, cb);
st -= cb;
pb += cb;
pm->buffer_position += cb;
}
} | /* Separate the callback into the actual implementation (which is passed the
* png_modifier explicitly) and the callback, which gets the modifier from the
* png_struct.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L2397-L2599 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | modifier_read | static void
modifier_read(png_structp ppIn, png_bytep pb, png_size_t st)
{
png_const_structp pp = ppIn;
png_modifier *pm = voidcast(png_modifier*, png_get_io_ptr(pp));
if (pm == NULL || pm->this.pread != pp)
png_error(pp, "bad modifier_read call");
modifier_read_imp(pm, pb, st);
} | /* The callback: */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L2602-L2612 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | modifier_progressive_read | static void
modifier_progressive_read(png_modifier *pm, png_structp pp, png_infop pi)
{
if (pm->this.pread != pp || pm->this.current == NULL ||
pm->this.next == NULL)
png_error(pp, "store state damaged (progressive)");
/* This is another Horowitz and Hill random noise generator. In this case
* the aim is to stress the progressive reader with truly horrible variable
* buffer sizes in the range 1..500, so a sequence of 9 bit random numbers
* is generated. We could probably just count from 1 to 32767 and get as
* good a result.
*/
for (;;)
{
static png_uint_32 noise = 1;
png_size_t cb, cbAvail;
png_byte buffer[512];
/* Generate 15 more bits of stuff: */
noise = (noise << 9) | ((noise ^ (noise >> (9-5))) & 0x1ff);
cb = noise & 0x1ff;
/* Check that this number of bytes are available (in the current buffer.)
* (This doesn't quite work - the modifier might delete a chunk; unlikely
* but possible, it doesn't happen at present because the modifier only
* adds chunks to standard images.)
*/
cbAvail = store_read_buffer_avail(&pm->this);
if (pm->buffer_count > pm->buffer_position)
cbAvail += pm->buffer_count - pm->buffer_position;
if (cb > cbAvail)
{
/* Check for EOF: */
if (cbAvail == 0)
break;
cb = cbAvail;
}
modifier_read_imp(pm, buffer, cb);
png_process_data(pp, pi, buffer, cb);
}
/* Check the invariants at the end (if this fails it's a problem in this
* file!)
*/
if (pm->buffer_count > pm->buffer_position ||
pm->this.next != &pm->this.current->data ||
pm->this.readpos < pm->this.current->datacount)
png_error(pp, "progressive read implementation error");
} | /* Like store_progressive_read but the data is getting changed as we go so we
* need a local buffer.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L2617-L2669 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | set_modifier_for_read | static png_structp
set_modifier_for_read(png_modifier *pm, png_infopp ppi, png_uint_32 id,
PNG_CONST char *name)
{
/* Do this first so that the modifier fields are cleared even if an error
* happens allocating the png_struct. No allocation is done here so no
* cleanup is required.
*/
pm->state = modifier_start;
pm->bit_depth = 0;
pm->colour_type = 255;
pm->pending_len = 0;
pm->pending_chunk = 0;
pm->flush = 0;
pm->buffer_count = 0;
pm->buffer_position = 0;
return set_store_for_read(&pm->this, ppi, id, name);
} | /* Set up a modifier. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L2672-L2691 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | standard_width | static png_uint_32
standard_width(png_const_structp pp, png_uint_32 id)
{
png_uint_32 width = WIDTH_FROM_ID(id);
UNUSED(pp)
if (width == 0)
width = transform_width(pp, COL_FROM_ID(id), DEPTH_FROM_ID(id));
return width;
} | /* The following can only be defined here, now we have the definitions
* of the transform image sizes.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L3175-L3185 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | standard_row | static void
standard_row(png_const_structp pp, png_byte std[STANDARD_ROWMAX],
png_uint_32 id, png_uint_32 y)
{
if (WIDTH_FROM_ID(id) == 0)
transform_row(pp, std, COL_FROM_ID(id), DEPTH_FROM_ID(id), y);
else
size_row(std, WIDTH_FROM_ID(id) * bit_size(pp, COL_FROM_ID(id),
DEPTH_FROM_ID(id)), y);
} | /* Return a row based on image id and 'y' for checking: */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L3783-L3792 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | image_transform_png_set_palette_to_rgb_set | static void
image_transform_png_set_palette_to_rgb_set(PNG_CONST image_transform *this,
transform_display *that, png_structp pp, png_infop pi)
{
png_set_palette_to_rgb(pp);
this->next->set(this->next, that, pp, pi);
} | /* png_set_palette_to_rgb */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L6040-L6046 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | image_transform_png_set_tRNS_to_alpha_set | static void
image_transform_png_set_tRNS_to_alpha_set(PNG_CONST image_transform *this,
transform_display *that, png_structp pp, png_infop pi)
{
png_set_tRNS_to_alpha(pp);
this->next->set(this->next, that, pp, pi);
} | /* png_set_tRNS_to_alpha */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L6078-L6084 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | image_transform_png_set_gray_to_rgb_set | static void
image_transform_png_set_gray_to_rgb_set(PNG_CONST image_transform *this,
transform_display *that, png_structp pp, png_infop pi)
{
png_set_gray_to_rgb(pp);
this->next->set(this->next, that, pp, pi);
} | /* png_set_gray_to_rgb */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L6136-L6142 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | image_transform_png_set_expand_set | static void
image_transform_png_set_expand_set(PNG_CONST image_transform *this,
transform_display *that, png_structp pp, png_infop pi)
{
png_set_expand(pp);
this->next->set(this->next, that, pp, pi);
} | /* png_set_expand */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L6195-L6201 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | image_transform_png_set_expand_gray_1_2_4_to_8_set | static void
image_transform_png_set_expand_gray_1_2_4_to_8_set(
PNG_CONST image_transform *this, transform_display *that, png_structp pp,
png_infop pi)
{
png_set_expand_gray_1_2_4_to_8(pp);
this->next->set(this->next, that, pp, pi);
} | /* png_set_expand_gray_1_2_4_to_8
* LIBPNG BUG: this just does an 'expand'
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L6244-L6251 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | image_transform_png_set_expand_16_set | static void
image_transform_png_set_expand_16_set(PNG_CONST image_transform *this,
transform_display *that, png_structp pp, png_infop pi)
{
png_set_expand_16(pp);
this->next->set(this->next, that, pp, pi);
} | /* png_set_expand_16 */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L6276-L6282 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | image_transform_png_set_scale_16_set | static void
image_transform_png_set_scale_16_set(PNG_CONST image_transform *this,
transform_display *that, png_structp pp, png_infop pi)
{
png_set_scale_16(pp);
this->next->set(this->next, that, pp, pi);
} | /* API added in 1.5.4 */
/* png_set_scale_16 */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L6324-L6330 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | image_transform_png_set_strip_16_set | static void
image_transform_png_set_strip_16_set(PNG_CONST image_transform *this,
transform_display *that, png_structp pp, png_infop pi)
{
png_set_strip_16(pp);
this->next->set(this->next, that, pp, pi);
} | /* the default before 1.5.4 */
/* png_set_strip_16 */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L6368-L6374 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | image_transform_png_set_strip_alpha_set | static void
image_transform_png_set_strip_alpha_set(PNG_CONST image_transform *this,
transform_display *that, png_structp pp, png_infop pi)
{
png_set_strip_alpha(pp);
this->next->set(this->next, that, pp, pi);
} | /* png_set_strip_alpha */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L6435-L6441 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gamma_component_compose | static double
gamma_component_compose(int do_background, double input_sample, double alpha,
double background, int *compose)
{
switch (do_background)
{
#ifdef PNG_READ_BACKGROUND_SUPPORTED
case PNG_BACKGROUND_GAMMA_SCREEN:
case PNG_BACKGROUND_GAMMA_FILE:
case PNG_BACKGROUND_GAMMA_UNIQUE:
/* Standard PNG background processing. */
if (alpha < 1)
{
if (alpha > 0)
{
input_sample = input_sample * alpha + background * (1-alpha);
if (compose != NULL)
*compose = 1;
}
else
input_sample = background;
}
break;
#endif
#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
case ALPHA_MODE_OFFSET + PNG_ALPHA_STANDARD:
case ALPHA_MODE_OFFSET + PNG_ALPHA_BROKEN:
/* The components are premultiplied in either case and the output is
* gamma encoded (to get standard Porter-Duff we expect the output
* gamma to be set to 1.0!)
*/
case ALPHA_MODE_OFFSET + PNG_ALPHA_OPTIMIZED:
/* The optimization is that the partial-alpha entries are linear
* while the opaque pixels are gamma encoded, but this only affects the
* output encoding.
*/
if (alpha < 1)
{
if (alpha > 0)
{
input_sample *= alpha;
if (compose != NULL)
*compose = 1;
}
else
input_sample = 0;
}
break;
#endif
default:
/* Standard cases where no compositing is done (so the component
* value is already correct.)
*/
UNUSED(alpha)
UNUSED(background)
UNUSED(compose)
break;
}
return input_sample;
} | /* This function handles composition of a single non-alpha component. The
* argument is the input sample value, in the range 0..1, and the alpha value.
* The result is the composed, linear, input sample. If alpha is less than zero
* this is the alpha component and the function should not be called!
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L7709-L7773 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | gamma_component_validate | static double
gamma_component_validate(PNG_CONST char *name, PNG_CONST validate_info *vi,
PNG_CONST unsigned int id, PNG_CONST unsigned int od,
PNG_CONST double alpha /* <0 for the alpha channel itself */,
PNG_CONST double background /* component background value */)
{
PNG_CONST unsigned int isbit = id >> vi->isbit_shift;
PNG_CONST unsigned int sbit_max = vi->sbit_max;
PNG_CONST unsigned int outmax = vi->outmax;
PNG_CONST int do_background = vi->do_background;
double i;
/* First check on the 'perfect' result obtained from the digitized input
* value, id, and compare this against the actual digitized result, 'od'.
* 'i' is the input result in the range 0..1:
*/
i = isbit; i /= sbit_max;
/* Check for the fast route: if we don't do any background composition or if
* this is the alpha channel ('alpha' < 0) or if the pixel is opaque then
* just use the gamma_correction field to correct to the final output gamma.
*/
if (alpha == 1 /* opaque pixel component */ || !do_background
#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
|| do_background == ALPHA_MODE_OFFSET + PNG_ALPHA_PNG
#endif
|| (alpha < 0 /* alpha channel */
#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
&& do_background != ALPHA_MODE_OFFSET + PNG_ALPHA_BROKEN
#endif
))
{
/* Then get the gamma corrected version of 'i' and compare to 'od', any
* error less than .5 is insignificant - just quantization of the output
* value to the nearest digital value (nevertheless the error is still
* recorded - it's interesting ;-)
*/
double encoded_sample = i;
double encoded_error;
/* alpha less than 0 indicates the alpha channel, which is always linear
*/
if (alpha >= 0 && vi->gamma_correction > 0)
encoded_sample = pow(encoded_sample, vi->gamma_correction);
encoded_sample *= outmax;
encoded_error = fabs(od-encoded_sample);
if (encoded_error > vi->dp->maxerrout)
vi->dp->maxerrout = encoded_error;
if (encoded_error < vi->maxout_total && encoded_error < vi->outlog)
return i;
}
/* The slow route - attempt to do linear calculations. */
/* There may be an error, or background processing is required, so calculate
* the actual sample values - unencoded light intensity values. Note that in
* practice these are not completely unencoded because they include a
* 'viewing correction' to decrease or (normally) increase the perceptual
* contrast of the image. There's nothing we can do about this - we don't
* know what it is - so assume the unencoded value is perceptually linear.
*/
{
double input_sample = i; /* In range 0..1 */
double output, error, encoded_sample, encoded_error;
double es_lo, es_hi;
int compose = 0; /* Set to one if composition done */
int output_is_encoded; /* Set if encoded to screen gamma */
int log_max_error = 1; /* Check maximum error values */
png_const_charp pass = 0; /* Reason test passes (or 0 for fail) */
/* Convert to linear light (with the above caveat.) The alpha channel is
* already linear.
*/
if (alpha >= 0)
{
int tcompose;
if (vi->file_inverse > 0)
input_sample = pow(input_sample, vi->file_inverse);
/* Handle the compose processing: */
tcompose = 0;
input_sample = gamma_component_compose(do_background, input_sample,
alpha, background, &tcompose);
if (tcompose)
compose = 1;
}
/* And similarly for the output value, but we need to check the background
* handling to linearize it correctly.
*/
output = od;
output /= outmax;
output_is_encoded = vi->screen_gamma > 0;
if (alpha < 0) /* The alpha channel */
{
#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
if (do_background != ALPHA_MODE_OFFSET + PNG_ALPHA_BROKEN)
#endif
{
/* In all other cases the output alpha channel is linear already,
* don't log errors here, they are much larger in linear data.
*/
output_is_encoded = 0;
log_max_error = 0;
}
}
#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
else /* A component */
{
if (do_background == ALPHA_MODE_OFFSET + PNG_ALPHA_OPTIMIZED &&
alpha < 1) /* the optimized case - linear output */
{
if (alpha > 0) log_max_error = 0;
output_is_encoded = 0;
}
}
#endif
if (output_is_encoded)
output = pow(output, vi->screen_gamma);
/* Calculate (or recalculate) the encoded_sample value and repeat the
* check above (unnecessary if we took the fast route, but harmless.)
*/
encoded_sample = input_sample;
if (output_is_encoded)
encoded_sample = pow(encoded_sample, vi->screen_inverse);
encoded_sample *= outmax;
encoded_error = fabs(od-encoded_sample);
/* Don't log errors in the alpha channel, or the 'optimized' case,
* neither are significant to the overall perception.
*/
if (log_max_error && encoded_error > vi->dp->maxerrout)
vi->dp->maxerrout = encoded_error;
if (encoded_error < vi->maxout_total)
{
if (encoded_error < vi->outlog)
return i;
/* Test passed but error is bigger than the log limit, record why the
* test passed:
*/
pass = "less than maxout:\n";
}
/* i: the original input value in the range 0..1
*
* pngvalid calculations:
* input_sample: linear result; i linearized and composed, range 0..1
* encoded_sample: encoded result; input_sample scaled to ouput bit depth
*
* libpng calculations:
* output: linear result; od scaled to 0..1 and linearized
* od: encoded result from libpng
*/
/* Now we have the numbers for real errors, both absolute values as as a
* percentage of the correct value (output):
*/
error = fabs(input_sample-output);
if (log_max_error && error > vi->dp->maxerrabs)
vi->dp->maxerrabs = error;
/* The following is an attempt to ignore the tendency of quantization to
* dominate the percentage errors for lower result values:
*/
if (log_max_error && input_sample > .5)
{
double percentage_error = error/input_sample;
if (percentage_error > vi->dp->maxerrpc)
vi->dp->maxerrpc = percentage_error;
}
/* Now calculate the digitization limits for 'encoded_sample' using the
* 'max' values. Note that maxout is in the encoded space but maxpc and
* maxabs are in linear light space.
*
* First find the maximum error in linear light space, range 0..1:
*/
{
double tmp = input_sample * vi->maxpc;
if (tmp < vi->maxabs) tmp = vi->maxabs;
/* If 'compose' is true the composition was done in linear space using
* integer arithmetic. This introduces an extra error of +/- 0.5 (at
* least) in the integer space used. 'maxcalc' records this, taking
* into account the possibility that even for 16 bit output 8 bit space
* may have been used.
*/
if (compose && tmp < vi->maxcalc) tmp = vi->maxcalc;
/* The 'maxout' value refers to the encoded result, to compare with
* this encode input_sample adjusted by the maximum error (tmp) above.
*/
es_lo = encoded_sample - vi->maxout;
if (es_lo > 0 && input_sample-tmp > 0)
{
double low_value = input_sample-tmp;
if (output_is_encoded)
low_value = pow(low_value, vi->screen_inverse);
low_value *= outmax;
if (low_value < es_lo) es_lo = low_value;
/* Quantize this appropriately: */
es_lo = ceil(es_lo / vi->outquant - .5) * vi->outquant;
}
else
es_lo = 0;
es_hi = encoded_sample + vi->maxout;
if (es_hi < outmax && input_sample+tmp < 1)
{
double high_value = input_sample+tmp;
if (output_is_encoded)
high_value = pow(high_value, vi->screen_inverse);
high_value *= outmax;
if (high_value > es_hi) es_hi = high_value;
es_hi = floor(es_hi / vi->outquant + .5) * vi->outquant;
}
else
es_hi = outmax;
}
/* The primary test is that the final encoded value returned by the
* library should be between the two limits (inclusive) that were
* calculated above.
*/
if (od >= es_lo && od <= es_hi)
{
/* The value passes, but we may need to log the information anyway. */
if (encoded_error < vi->outlog)
return i;
if (pass == 0)
pass = "within digitization limits:\n";
}
{
/* There has been an error in processing, or we need to log this
* value.
*/
double is_lo, is_hi;
/* pass is set at this point if either of the tests above would have
* passed. Don't do these additional tests here - just log the
* original [es_lo..es_hi] values.
*/
if (pass == 0 && vi->use_input_precision)
{
/* Ok, something is wrong - this actually happens in current libpng
* 16-to-8 processing. Assume that the input value (id, adjusted
* for sbit) can be anywhere between value-.5 and value+.5 - quite a
* large range if sbit is low.
*/
double tmp = (isbit - .5)/sbit_max;
if (tmp <= 0)
tmp = 0;
else if (alpha >= 0 && vi->file_inverse > 0 && tmp < 1)
tmp = pow(tmp, vi->file_inverse);
tmp = gamma_component_compose(do_background, tmp, alpha, background,
NULL);
if (output_is_encoded && tmp > 0 && tmp < 1)
tmp = pow(tmp, vi->screen_inverse);
is_lo = ceil(outmax * tmp - vi->maxout_total);
if (is_lo < 0)
is_lo = 0;
tmp = (isbit + .5)/sbit_max;
if (tmp <= 0)
tmp = 0;
else if (alpha >= 0 && vi->file_inverse > 0 && tmp < 1)
tmp = pow(tmp, vi->file_inverse);
tmp = gamma_component_compose(do_background, tmp, alpha, background,
NULL);
if (output_is_encoded && tmp > 0 && tmp < 1)
tmp = pow(tmp, vi->screen_inverse);
is_hi = floor(outmax * tmp + vi->maxout_total);
if (is_hi > outmax)
is_hi = outmax;
if (!(od < is_lo || od > is_hi))
{
if (encoded_error < vi->outlog)
return i;
pass = "within input precision limits:\n";
}
/* One last chance. If this is an alpha channel and the 16to8
* option has been used and 'inaccurate' scaling is used then the
* bit reduction is obtained by simply using the top 8 bits of the
* value.
*
* This is only done for older libpng versions when the 'inaccurate'
* (chop) method of scaling was used.
*/
# ifndef PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
# if PNG_LIBPNG_VER < 10504
/* This may be required for other components in the future,
* but at present the presence of gamma correction effectively
* prevents the errors in the component scaling (I don't quite
* understand why, but since it's better this way I care not
* to ask, JB 20110419.)
*/
if (pass == 0 && alpha < 0 && vi->scale16 && vi->sbit > 8 &&
vi->sbit + vi->isbit_shift == 16)
{
tmp = ((id >> 8) - .5)/255;
if (tmp > 0)
{
is_lo = ceil(outmax * tmp - vi->maxout_total);
if (is_lo < 0) is_lo = 0;
}
else
is_lo = 0;
tmp = ((id >> 8) + .5)/255;
if (tmp < 1)
{
is_hi = floor(outmax * tmp + vi->maxout_total);
if (is_hi > outmax) is_hi = outmax;
}
else
is_hi = outmax;
if (!(od < is_lo || od > is_hi))
{
if (encoded_error < vi->outlog)
return i;
pass = "within 8 bit limits:\n";
}
}
# endif
# endif
}
else /* !use_input_precision */
is_lo = es_lo, is_hi = es_hi;
/* Attempt to output a meaningful error/warning message: the message
* output depends on the background/composite operation being performed
* because this changes what parameters were actually used above.
*/
{
size_t pos = 0;
/* Need either 1/255 or 1/65535 precision here; 3 or 6 decimal
* places. Just use outmax to work out which.
*/
int precision = (outmax >= 1000 ? 6 : 3);
int use_input=1, use_background=0, do_compose=0;
char msg[256];
if (pass != 0)
pos = safecat(msg, sizeof msg, pos, "\n\t");
/* Set up the various flags, the output_is_encoded flag above
* is also used below. do_compose is just a double check.
*/
switch (do_background)
{
# ifdef PNG_READ_BACKGROUND_SUPPORTED
case PNG_BACKGROUND_GAMMA_SCREEN:
case PNG_BACKGROUND_GAMMA_FILE:
case PNG_BACKGROUND_GAMMA_UNIQUE:
use_background = (alpha >= 0 && alpha < 1);
/*FALL THROUGH*/
# endif
# ifdef PNG_READ_ALPHA_MODE_SUPPORTED
case ALPHA_MODE_OFFSET + PNG_ALPHA_STANDARD:
case ALPHA_MODE_OFFSET + PNG_ALPHA_BROKEN:
case ALPHA_MODE_OFFSET + PNG_ALPHA_OPTIMIZED:
# endif /* ALPHA_MODE_SUPPORTED */
do_compose = (alpha > 0 && alpha < 1);
use_input = (alpha != 0);
break;
default:
break;
}
/* Check the 'compose' flag */
if (compose != do_compose)
png_error(vi->pp, "internal error (compose)");
/* 'name' is the component name */
pos = safecat(msg, sizeof msg, pos, name);
pos = safecat(msg, sizeof msg, pos, "(");
pos = safecatn(msg, sizeof msg, pos, id);
if (use_input || pass != 0/*logging*/)
{
if (isbit != id)
{
/* sBIT has reduced the precision of the input: */
pos = safecat(msg, sizeof msg, pos, ", sbit(");
pos = safecatn(msg, sizeof msg, pos, vi->sbit);
pos = safecat(msg, sizeof msg, pos, "): ");
pos = safecatn(msg, sizeof msg, pos, isbit);
}
pos = safecat(msg, sizeof msg, pos, "/");
/* The output is either "id/max" or "id sbit(sbit): isbit/max" */
pos = safecatn(msg, sizeof msg, pos, vi->sbit_max);
}
pos = safecat(msg, sizeof msg, pos, ")");
/* A component may have been multiplied (in linear space) by the
* alpha value, 'compose' says whether this is relevant.
*/
if (compose || pass != 0)
{
/* If any form of composition is being done report our
* calculated linear value here (the code above doesn't record
* the input value before composition is performed, so what
* gets reported is the value after composition.)
*/
if (use_input || pass != 0)
{
if (vi->file_inverse > 0)
{
pos = safecat(msg, sizeof msg, pos, "^");
pos = safecatd(msg, sizeof msg, pos, vi->file_inverse, 2);
}
else
pos = safecat(msg, sizeof msg, pos, "[linear]");
pos = safecat(msg, sizeof msg, pos, "*(alpha)");
pos = safecatd(msg, sizeof msg, pos, alpha, precision);
}
/* Now record the *linear* background value if it was used
* (this function is not passed the original, non-linear,
* value but it is contained in the test name.)
*/
if (use_background)
{
pos = safecat(msg, sizeof msg, pos, use_input ? "+" : " ");
pos = safecat(msg, sizeof msg, pos, "(background)");
pos = safecatd(msg, sizeof msg, pos, background, precision);
pos = safecat(msg, sizeof msg, pos, "*");
pos = safecatd(msg, sizeof msg, pos, 1-alpha, precision);
}
}
/* Report the calculated value (input_sample) and the linearized
* libpng value (output) unless this is just a component gamma
* correction.
*/
if (compose || alpha < 0 || pass != 0)
{
pos = safecat(msg, sizeof msg, pos,
pass != 0 ? " =\n\t" : " = ");
pos = safecatd(msg, sizeof msg, pos, input_sample, precision);
pos = safecat(msg, sizeof msg, pos, " (libpng: ");
pos = safecatd(msg, sizeof msg, pos, output, precision);
pos = safecat(msg, sizeof msg, pos, ")");
/* Finally report the output gamma encoding, if any. */
if (output_is_encoded)
{
pos = safecat(msg, sizeof msg, pos, " ^");
pos = safecatd(msg, sizeof msg, pos, vi->screen_inverse, 2);
pos = safecat(msg, sizeof msg, pos, "(to screen) =");
}
else
pos = safecat(msg, sizeof msg, pos, " [screen is linear] =");
}
if ((!compose && alpha >= 0) || pass != 0)
{
if (pass != 0) /* logging */
pos = safecat(msg, sizeof msg, pos, "\n\t[overall:");
/* This is the non-composition case, the internal linear
* values are irrelevant (though the log below will reveal
* them.) Output a much shorter warning/error message and report
* the overall gamma correction.
*/
if (vi->gamma_correction > 0)
{
pos = safecat(msg, sizeof msg, pos, " ^");
pos = safecatd(msg, sizeof msg, pos, vi->gamma_correction, 2);
pos = safecat(msg, sizeof msg, pos, "(gamma correction) =");
}
else
pos = safecat(msg, sizeof msg, pos,
" [no gamma correction] =");
if (pass != 0)
pos = safecat(msg, sizeof msg, pos, "]");
}
/* This is our calculated encoded_sample which should (but does
* not) match od:
*/
pos = safecat(msg, sizeof msg, pos, pass != 0 ? "\n\t" : " ");
pos = safecatd(msg, sizeof msg, pos, is_lo, 1);
pos = safecat(msg, sizeof msg, pos, " < ");
pos = safecatd(msg, sizeof msg, pos, encoded_sample, 1);
pos = safecat(msg, sizeof msg, pos, " (libpng: ");
pos = safecatn(msg, sizeof msg, pos, od);
pos = safecat(msg, sizeof msg, pos, ")");
pos = safecat(msg, sizeof msg, pos, "/");
pos = safecatn(msg, sizeof msg, pos, outmax);
pos = safecat(msg, sizeof msg, pos, " < ");
pos = safecatd(msg, sizeof msg, pos, is_hi, 1);
if (pass == 0) /* The error condition */
{
# ifdef PNG_WARNINGS_SUPPORTED
png_warning(vi->pp, msg);
# else
store_warning(vi->pp, msg);
# endif
}
else /* logging this value */
store_verbose(&vi->dp->pm->this, vi->pp, pass, msg);
}
}
}
return i;
} | /* This API returns the encoded *input* component, in the range 0..1 */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/png/contrib/libtests/pngvalid.c#L7776-L8332 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.