| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#include "png.h" |
| 32 |
|
| 33 |
#if defined(_WIN32_WCE) |
| 34 |
# if _WIN32_WCE < 211 |
| 35 |
__error__ (f|w)printf functions are not supported on old WindowsCE.; |
| 36 |
# endif |
| 37 |
# include <windows.h> |
| 38 |
# include <stdlib.h> |
| 39 |
# define READFILE(file, data, length, check) \ |
| 40 |
if (ReadFile(file, data, length, &check,NULL)) check = 0 |
| 41 |
# define WRITEFILE(file, data, length, check)) \ |
| 42 |
if (WriteFile(file, data, length, &check, NULL)) check = 0 |
| 43 |
# define FCLOSE(file) CloseHandle(file) |
| 44 |
#else |
| 45 |
# include <stdio.h> |
| 46 |
# include <stdlib.h> |
| 47 |
# define READFILE(file, data, length, check) \ |
| 48 |
check=(png_size_t)fread(data,(png_size_t)1,length,file) |
| 49 |
# define WRITEFILE(file, data, length, check) \ |
| 50 |
check=(png_size_t)fwrite(data,(png_size_t)1, length, file) |
| 51 |
# define FCLOSE(file) fclose(file) |
| 52 |
#endif |
| 53 |
|
| 54 |
#if defined(PNG_NO_STDIO) |
| 55 |
# if defined(_WIN32_WCE) |
| 56 |
typedef HANDLE png_FILE_p; |
| 57 |
# else |
| 58 |
typedef FILE * png_FILE_p; |
| 59 |
# endif |
| 60 |
#endif |
| 61 |
|
| 62 |
|
| 63 |
#ifndef PNG_DEBUG |
| 64 |
# define PNG_DEBUG 0 |
| 65 |
#endif |
| 66 |
|
| 67 |
#if !PNG_DEBUG |
| 68 |
# define SINGLE_ROWBUF_ALLOC |
| 69 |
#endif |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
#ifdef PNG_NO_FLOATING_POINT_SUPPORTED |
| 76 |
#undef PNGTEST_TIMING |
| 77 |
#endif |
| 78 |
|
| 79 |
#ifdef PNGTEST_TIMING |
| 80 |
static float t_start, t_stop, t_decode, t_encode, t_misc; |
| 81 |
#include <time.h> |
| 82 |
#endif |
| 83 |
|
| 84 |
|
| 85 |
#ifndef png_jmpbuf |
| 86 |
# define png_jmpbuf(png_ptr) png_ptr->jmpbuf |
| 87 |
#endif |
| 88 |
|
| 89 |
#ifdef PNGTEST_TIMING |
| 90 |
static float t_start, t_stop, t_decode, t_encode, t_misc; |
| 91 |
#if !defined(PNG_tIME_SUPPORTED) |
| 92 |
#include <time.h> |
| 93 |
#endif |
| 94 |
#endif |
| 95 |
|
| 96 |
#if defined(PNG_TIME_RFC1123_SUPPORTED) |
| 97 |
static int tIME_chunk_present=0; |
| 98 |
static char tIME_string[30] = "no tIME chunk present in file"; |
| 99 |
#endif |
| 100 |
|
| 101 |
static int verbose = 0; |
| 102 |
|
| 103 |
int test_one_file PNGARG((PNG_CONST char *inname, PNG_CONST char *outname)); |
| 104 |
|
| 105 |
#ifdef __TURBOC__ |
| 106 |
#include <mem.h> |
| 107 |
#endif |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
#define STDERR stdout |
| 112 |
|
| 113 |
|
| 114 |
static int status_pass=1; |
| 115 |
static int status_dots_requested=0; |
| 116 |
static int status_dots=1; |
| 117 |
|
| 118 |
void |
| 119 |
#ifdef PNG_1_0_X |
| 120 |
PNGAPI |
| 121 |
#endif |
| 122 |
read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass); |
| 123 |
void |
| 124 |
#ifdef PNG_1_0_X |
| 125 |
PNGAPI |
| 126 |
#endif |
| 127 |
read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass) |
| 128 |
{ |
| 129 |
if(png_ptr == NULL || row_number > PNG_UINT_31_MAX) return; |
| 130 |
if(status_pass != pass) |
| 131 |
{ |
| 132 |
fprintf(stdout,"\n Pass %d: ",pass); |
| 133 |
status_pass = pass; |
| 134 |
status_dots = 31; |
| 135 |
} |
| 136 |
status_dots--; |
| 137 |
if(status_dots == 0) |
| 138 |
{ |
| 139 |
fprintf(stdout, "\n "); |
| 140 |
status_dots=30; |
| 141 |
} |
| 142 |
fprintf(stdout, "r"); |
| 143 |
} |
| 144 |
|
| 145 |
void |
| 146 |
#ifdef PNG_1_0_X |
| 147 |
PNGAPI |
| 148 |
#endif |
| 149 |
write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass); |
| 150 |
void |
| 151 |
#ifdef PNG_1_0_X |
| 152 |
PNGAPI |
| 153 |
#endif |
| 154 |
write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass) |
| 155 |
{ |
| 156 |
if(png_ptr == NULL || row_number > PNG_UINT_31_MAX || pass > 7) return; |
| 157 |
fprintf(stdout, "w"); |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
static png_uint_32 filters_used[256]; |
| 166 |
void |
| 167 |
#ifdef PNG_1_0_X |
| 168 |
PNGAPI |
| 169 |
#endif |
| 170 |
count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data); |
| 171 |
void |
| 172 |
#ifdef PNG_1_0_X |
| 173 |
PNGAPI |
| 174 |
#endif |
| 175 |
count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data) |
| 176 |
{ |
| 177 |
if(png_ptr != NULL && row_info != NULL) |
| 178 |
++filters_used[*(data-1)]; |
| 179 |
} |
| 180 |
#endif |
| 181 |
|
| 182 |
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
static png_uint_32 zero_samples; |
| 187 |
|
| 188 |
void |
| 189 |
#ifdef PNG_1_0_X |
| 190 |
PNGAPI |
| 191 |
#endif |
| 192 |
count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data); |
| 193 |
void |
| 194 |
#ifdef PNG_1_0_X |
| 195 |
PNGAPI |
| 196 |
#endif |
| 197 |
count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data) |
| 198 |
{ |
| 199 |
png_bytep dp = data; |
| 200 |
if(png_ptr == NULL)return; |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
if(row_info->color_type == 0 || row_info->color_type == 3) |
| 215 |
{ |
| 216 |
int pos=0; |
| 217 |
png_uint_32 n, nstop; |
| 218 |
for (n=0, nstop=row_info->width; n<nstop; n++) |
| 219 |
{ |
| 220 |
if(row_info->bit_depth == 1) |
| 221 |
{ |
| 222 |
if(((*dp << pos++ ) & 0x80) == 0) zero_samples++; |
| 223 |
if(pos == 8) |
| 224 |
{ |
| 225 |
pos = 0; |
| 226 |
dp++; |
| 227 |
} |
| 228 |
} |
| 229 |
if(row_info->bit_depth == 2) |
| 230 |
{ |
| 231 |
if(((*dp << (pos+=2)) & 0xc0) == 0) zero_samples++; |
| 232 |
if(pos == 8) |
| 233 |
{ |
| 234 |
pos = 0; |
| 235 |
dp++; |
| 236 |
} |
| 237 |
} |
| 238 |
if(row_info->bit_depth == 4) |
| 239 |
{ |
| 240 |
if(((*dp << (pos+=4)) & 0xf0) == 0) zero_samples++; |
| 241 |
if(pos == 8) |
| 242 |
{ |
| 243 |
pos = 0; |
| 244 |
dp++; |
| 245 |
} |
| 246 |
} |
| 247 |
if(row_info->bit_depth == 8) |
| 248 |
if(*dp++ == 0) zero_samples++; |
| 249 |
if(row_info->bit_depth == 16) |
| 250 |
{ |
| 251 |
if((*dp | *(dp+1)) == 0) zero_samples++; |
| 252 |
dp+=2; |
| 253 |
} |
| 254 |
} |
| 255 |
} |
| 256 |
else |
| 257 |
{ |
| 258 |
png_uint_32 n, nstop; |
| 259 |
int channel; |
| 260 |
int color_channels = row_info->channels; |
| 261 |
if(row_info->color_type > 3)color_channels--; |
| 262 |
|
| 263 |
for (n=0, nstop=row_info->width; n<nstop; n++) |
| 264 |
{ |
| 265 |
for (channel = 0; channel < color_channels; channel++) |
| 266 |
{ |
| 267 |
if(row_info->bit_depth == 8) |
| 268 |
if(*dp++ == 0) zero_samples++; |
| 269 |
if(row_info->bit_depth == 16) |
| 270 |
{ |
| 271 |
if((*dp | *(dp+1)) == 0) zero_samples++; |
| 272 |
dp+=2; |
| 273 |
} |
| 274 |
} |
| 275 |
if(row_info->color_type > 3) |
| 276 |
{ |
| 277 |
dp++; |
| 278 |
if(row_info->bit_depth == 16)dp++; |
| 279 |
} |
| 280 |
} |
| 281 |
} |
| 282 |
} |
| 283 |
#endif |
| 284 |
|
| 285 |
static int wrote_question = 0; |
| 286 |
|
| 287 |
#if defined(PNG_NO_STDIO) |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
#ifndef USE_FAR_KEYWORD |
| 297 |
static void |
| 298 |
pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length) |
| 299 |
{ |
| 300 |
png_size_t check; |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
READFILE((png_FILE_p)png_ptr->io_ptr, data, length, check); |
| 306 |
|
| 307 |
if (check != length) |
| 308 |
{ |
| 309 |
png_error(png_ptr, "Read Error!"); |
| 310 |
} |
| 311 |
} |
| 312 |
#else |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
#define NEAR_BUF_SIZE 1024 |
| 319 |
#define MIN(a,b) (a <= b ? a : b) |
| 320 |
|
| 321 |
static void |
| 322 |
pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length) |
| 323 |
{ |
| 324 |
int check; |
| 325 |
png_byte *n_data; |
| 326 |
png_FILE_p io_ptr; |
| 327 |
|
| 328 |
|
| 329 |
n_data = (png_byte *)CVT_PTR_NOCHECK(data); |
| 330 |
io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); |
| 331 |
if ((png_bytep)n_data == data) |
| 332 |
{ |
| 333 |
READFILE(io_ptr, n_data, length, check); |
| 334 |
} |
| 335 |
else |
| 336 |
{ |
| 337 |
png_byte buf[NEAR_BUF_SIZE]; |
| 338 |
png_size_t read, remaining, err; |
| 339 |
check = 0; |
| 340 |
remaining = length; |
| 341 |
do |
| 342 |
{ |
| 343 |
read = MIN(NEAR_BUF_SIZE, remaining); |
| 344 |
READFILE(io_ptr, buf, 1, err); |
| 345 |
png_memcpy(data, buf, read); |
| 346 |
if(err != read) |
| 347 |
break; |
| 348 |
else |
| 349 |
check += err; |
| 350 |
data += read; |
| 351 |
remaining -= read; |
| 352 |
} |
| 353 |
while (remaining != 0); |
| 354 |
} |
| 355 |
if (check != length) |
| 356 |
{ |
| 357 |
png_error(png_ptr, "read Error"); |
| 358 |
} |
| 359 |
} |
| 360 |
#endif |
| 361 |
|
| 362 |
#if defined(PNG_WRITE_FLUSH_SUPPORTED) |
| 363 |
static void |
| 364 |
pngtest_flush(png_structp png_ptr) |
| 365 |
{ |
| 366 |
#if !defined(_WIN32_WCE) |
| 367 |
png_FILE_p io_ptr; |
| 368 |
io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr)); |
| 369 |
if (io_ptr != NULL) |
| 370 |
fflush(io_ptr); |
| 371 |
#endif |
| 372 |
} |
| 373 |
#endif |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
#ifndef USE_FAR_KEYWORD |
| 380 |
static void |
| 381 |
pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length) |
| 382 |
{ |
| 383 |
png_uint_32 check; |
| 384 |
|
| 385 |
WRITEFILE((png_FILE_p)png_ptr->io_ptr, data, length, check); |
| 386 |
if (check != length) |
| 387 |
{ |
| 388 |
png_error(png_ptr, "Write Error"); |
| 389 |
} |
| 390 |
} |
| 391 |
#else |
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
#define NEAR_BUF_SIZE 1024 |
| 398 |
#define MIN(a,b) (a <= b ? a : b) |
| 399 |
|
| 400 |
static void |
| 401 |
pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length) |
| 402 |
{ |
| 403 |
png_uint_32 check; |
| 404 |
png_byte *near_data; |
| 405 |
png_FILE_p io_ptr; |
| 406 |
|
| 407 |
|
| 408 |
near_data = (png_byte *)CVT_PTR_NOCHECK(data); |
| 409 |
io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); |
| 410 |
if ((png_bytep)near_data == data) |
| 411 |
{ |
| 412 |
WRITEFILE(io_ptr, near_data, length, check); |
| 413 |
} |
| 414 |
else |
| 415 |
{ |
| 416 |
png_byte buf[NEAR_BUF_SIZE]; |
| 417 |
png_size_t written, remaining, err; |
| 418 |
check = 0; |
| 419 |
remaining = length; |
| 420 |
do |
| 421 |
{ |
| 422 |
written = MIN(NEAR_BUF_SIZE, remaining); |
| 423 |
png_memcpy(buf, data, written); |
| 424 |
WRITEFILE(io_ptr, buf, written, err); |
| 425 |
if (err != written) |
| 426 |
break; |
| 427 |
else |
| 428 |
check += err; |
| 429 |
data += written; |
| 430 |
remaining -= written; |
| 431 |
} |
| 432 |
while (remaining != 0); |
| 433 |
} |
| 434 |
if (check != length) |
| 435 |
{ |
| 436 |
png_error(png_ptr, "Write Error"); |
| 437 |
} |
| 438 |
} |
| 439 |
|
| 440 |
#endif |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
static void |
| 448 |
pngtest_warning(png_structp png_ptr, png_const_charp message) |
| 449 |
{ |
| 450 |
PNG_CONST char *name = "UNKNOWN (ERROR!)"; |
| 451 |
if (png_ptr != NULL && png_ptr->error_ptr != NULL) |
| 452 |
name = png_ptr->error_ptr; |
| 453 |
fprintf(STDERR, "%s: libpng warning: %s\n", name, message); |
| 454 |
} |
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
static void |
| 462 |
pngtest_error(png_structp png_ptr, png_const_charp message) |
| 463 |
{ |
| 464 |
pngtest_warning(png_ptr, message); |
| 465 |
|
| 466 |
|
| 467 |
} |
| 468 |
#endif |
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG |
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
typedef struct memory_information |
| 483 |
{ |
| 484 |
png_uint_32 size; |
| 485 |
png_voidp pointer; |
| 486 |
struct memory_information FAR *next; |
| 487 |
} memory_information; |
| 488 |
typedef memory_information FAR *memory_infop; |
| 489 |
|
| 490 |
static memory_infop pinformation = NULL; |
| 491 |
static int current_allocation = 0; |
| 492 |
static int maximum_allocation = 0; |
| 493 |
static int total_allocation = 0; |
| 494 |
static int num_allocations = 0; |
| 495 |
|
| 496 |
png_voidp png_debug_malloc PNGARG((png_structp png_ptr, png_uint_32 size)); |
| 497 |
void png_debug_free PNGARG((png_structp png_ptr, png_voidp ptr)); |
| 498 |
|
| 499 |
png_voidp |
| 500 |
png_debug_malloc(png_structp png_ptr, png_uint_32 size) |
| 501 |
{ |
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
if (size == 0) |
| 507 |
return (NULL); |
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
{ |
| 512 |
|
| 513 |
memory_infop pinfo; |
| 514 |
png_set_mem_fn(png_ptr, NULL, NULL, NULL); |
| 515 |
pinfo = (memory_infop)png_malloc(png_ptr, |
| 516 |
(png_uint_32)png_sizeof (*pinfo)); |
| 517 |
pinfo->size = size; |
| 518 |
current_allocation += size; |
| 519 |
total_allocation += size; |
| 520 |
num_allocations ++; |
| 521 |
if (current_allocation > maximum_allocation) |
| 522 |
maximum_allocation = current_allocation; |
| 523 |
pinfo->pointer = (png_voidp)png_malloc(png_ptr, size); |
| 524 |
|
| 525 |
png_set_mem_fn(png_ptr, png_voidp_NULL, (png_malloc_ptr)png_debug_malloc, |
| 526 |
(png_free_ptr)png_debug_free); |
| 527 |
if (size != 0 && pinfo->pointer == NULL) |
| 528 |
{ |
| 529 |
current_allocation -= size; |
| 530 |
total_allocation -= size; |
| 531 |
png_error(png_ptr, |
| 532 |
"out of memory in pngtest->png_debug_malloc."); |
| 533 |
} |
| 534 |
pinfo->next = pinformation; |
| 535 |
pinformation = pinfo; |
| 536 |
|
| 537 |
png_memset(pinfo->pointer, 0xdd, pinfo->size); |
| 538 |
if(verbose) |
| 539 |
printf("png_malloc %lu bytes at %x\n",size,pinfo->pointer); |
| 540 |
return (png_voidp)(pinfo->pointer); |
| 541 |
} |
| 542 |
} |
| 543 |
|
| 544 |
|
| 545 |
void |
| 546 |
png_debug_free(png_structp png_ptr, png_voidp ptr) |
| 547 |
{ |
| 548 |
if (png_ptr == NULL) |
| 549 |
fprintf(STDERR, "NULL pointer to png_debug_free.\n"); |
| 550 |
if (ptr == 0) |
| 551 |
{ |
| 552 |
#if 0 |
| 553 |
fprintf(STDERR, "WARNING: freeing NULL pointer\n"); |
| 554 |
#endif |
| 555 |
return; |
| 556 |
} |
| 557 |
|
| 558 |
|
| 559 |
{ |
| 560 |
memory_infop FAR *ppinfo = &pinformation; |
| 561 |
for (;;) |
| 562 |
{ |
| 563 |
memory_infop pinfo = *ppinfo; |
| 564 |
if (pinfo->pointer == ptr) |
| 565 |
{ |
| 566 |
*ppinfo = pinfo->next; |
| 567 |
current_allocation -= pinfo->size; |
| 568 |
if (current_allocation < 0) |
| 569 |
fprintf(STDERR, "Duplicate free of memory\n"); |
| 570 |
|
| 571 |
|
| 572 |
png_memset(ptr, 0x55, pinfo->size); |
| 573 |
png_free_default(png_ptr, pinfo); |
| 574 |
pinfo=NULL; |
| 575 |
break; |
| 576 |
} |
| 577 |
if (pinfo->next == NULL) |
| 578 |
{ |
| 579 |
fprintf(STDERR, "Pointer %x not found\n", (unsigned int)ptr); |
| 580 |
break; |
| 581 |
} |
| 582 |
ppinfo = &pinfo->next; |
| 583 |
} |
| 584 |
} |
| 585 |
|
| 586 |
|
| 587 |
if(verbose) |
| 588 |
printf("Freeing %x\n",ptr); |
| 589 |
png_free_default(png_ptr, ptr); |
| 590 |
ptr=NULL; |
| 591 |
} |
| 592 |
#endif |
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
int |
| 597 |
test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) |
| 598 |
{ |
| 599 |
static png_FILE_p fpin; |
| 600 |
static png_FILE_p fpout; |
| 601 |
png_structp read_ptr; |
| 602 |
png_infop read_info_ptr, end_info_ptr; |
| 603 |
#ifdef PNG_WRITE_SUPPORTED |
| 604 |
png_structp write_ptr; |
| 605 |
png_infop write_info_ptr; |
| 606 |
png_infop write_end_info_ptr; |
| 607 |
#else |
| 608 |
png_structp write_ptr = NULL; |
| 609 |
png_infop write_info_ptr = NULL; |
| 610 |
png_infop write_end_info_ptr = NULL; |
| 611 |
#endif |
| 612 |
png_bytep row_buf; |
| 613 |
png_uint_32 y; |
| 614 |
png_uint_32 width, height; |
| 615 |
int num_pass, pass; |
| 616 |
int bit_depth, color_type; |
| 617 |
#ifdef PNG_SETJMP_SUPPORTED |
| 618 |
#ifdef USE_FAR_KEYWORD |
| 619 |
jmp_buf jmpbuf; |
| 620 |
#endif |
| 621 |
#endif |
| 622 |
|
| 623 |
#if defined(_WIN32_WCE) |
| 624 |
TCHAR path[MAX_PATH]; |
| 625 |
#endif |
| 626 |
char inbuf[256], outbuf[256]; |
| 627 |
|
| 628 |
row_buf = NULL; |
| 629 |
|
| 630 |
#if defined(_WIN32_WCE) |
| 631 |
MultiByteToWideChar(CP_ACP, 0, inname, -1, path, MAX_PATH); |
| 632 |
if ((fpin = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE) |
| 633 |
#else |
| 634 |
if ((fpin = fopen(inname, "rb")) == NULL) |
| 635 |
#endif |
| 636 |
{ |
| 637 |
fprintf(STDERR, "Could not find input file %s\n", inname); |
| 638 |
return (1); |
| 639 |
} |
| 640 |
|
| 641 |
#if defined(_WIN32_WCE) |
| 642 |
MultiByteToWideChar(CP_ACP, 0, outname, -1, path, MAX_PATH); |
| 643 |
if ((fpout = CreateFile(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL)) == INVALID_HANDLE_VALUE) |
| 644 |
#else |
| 645 |
if ((fpout = fopen(outname, "wb")) == NULL) |
| 646 |
#endif |
| 647 |
{ |
| 648 |
fprintf(STDERR, "Could not open output file %s\n", outname); |
| 649 |
FCLOSE(fpin); |
| 650 |
return (1); |
| 651 |
} |
| 652 |
|
| 653 |
png_debug(0, "Allocating read and write structures\n"); |
| 654 |
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG |
| 655 |
read_ptr = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, png_voidp_NULL, |
| 656 |
png_error_ptr_NULL, png_error_ptr_NULL, png_voidp_NULL, |
| 657 |
(png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free); |
| 658 |
#else |
| 659 |
read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, png_voidp_NULL, |
| 660 |
png_error_ptr_NULL, png_error_ptr_NULL); |
| 661 |
#endif |
| 662 |
#if defined(PNG_NO_STDIO) |
| 663 |
png_set_error_fn(read_ptr, (png_voidp)inname, pngtest_error, |
| 664 |
pngtest_warning); |
| 665 |
#endif |
| 666 |
#ifdef PNG_WRITE_SUPPORTED |
| 667 |
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG |
| 668 |
write_ptr = png_create_write_struct_2(PNG_LIBPNG_VER_STRING, png_voidp_NULL, |
| 669 |
png_error_ptr_NULL, png_error_ptr_NULL, png_voidp_NULL, |
| 670 |
(png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free); |
| 671 |
#else |
| 672 |
write_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, png_voidp_NULL, |
| 673 |
png_error_ptr_NULL, png_error_ptr_NULL); |
| 674 |
#endif |
| 675 |
#if defined(PNG_NO_STDIO) |
| 676 |
png_set_error_fn(write_ptr, (png_voidp)inname, pngtest_error, |
| 677 |
pngtest_warning); |
| 678 |
#endif |
| 679 |
#endif |
| 680 |
png_debug(0, "Allocating read_info, write_info and end_info structures\n"); |
| 681 |
read_info_ptr = png_create_info_struct(read_ptr); |
| 682 |
end_info_ptr = png_create_info_struct(read_ptr); |
| 683 |
#ifdef PNG_WRITE_SUPPORTED |
| 684 |
write_info_ptr = png_create_info_struct(write_ptr); |
| 685 |
write_end_info_ptr = png_create_info_struct(write_ptr); |
| 686 |
#endif |
| 687 |
|
| 688 |
#ifdef PNG_SETJMP_SUPPORTED |
| 689 |
png_debug(0, "Setting jmpbuf for read struct\n"); |
| 690 |
#ifdef USE_FAR_KEYWORD |
| 691 |
if (setjmp(jmpbuf)) |
| 692 |
#else |
| 693 |
if (setjmp(png_jmpbuf(read_ptr))) |
| 694 |
#endif |
| 695 |
{ |
| 696 |
fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname); |
| 697 |
if (row_buf) |
| 698 |
png_free(read_ptr, row_buf); |
| 699 |
png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); |
| 700 |
#ifdef PNG_WRITE_SUPPORTED |
| 701 |
png_destroy_info_struct(write_ptr, &write_end_info_ptr); |
| 702 |
png_destroy_write_struct(&write_ptr, &write_info_ptr); |
| 703 |
#endif |
| 704 |
FCLOSE(fpin); |
| 705 |
FCLOSE(fpout); |
| 706 |
return (1); |
| 707 |
} |
| 708 |
#ifdef USE_FAR_KEYWORD |
| 709 |
png_memcpy(png_jmpbuf(read_ptr),jmpbuf,png_sizeof(jmp_buf)); |
| 710 |
#endif |
| 711 |
|
| 712 |
#ifdef PNG_WRITE_SUPPORTED |
| 713 |
png_debug(0, "Setting jmpbuf for write struct\n"); |
| 714 |
#ifdef USE_FAR_KEYWORD |
| 715 |
if (setjmp(jmpbuf)) |
| 716 |
#else |
| 717 |
if (setjmp(png_jmpbuf(write_ptr))) |
| 718 |
#endif |
| 719 |
{ |
| 720 |
fprintf(STDERR, "%s -> %s: libpng write error\n", inname, outname); |
| 721 |
png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); |
| 722 |
png_destroy_info_struct(write_ptr, &write_end_info_ptr); |
| 723 |
#ifdef PNG_WRITE_SUPPORTED |
| 724 |
png_destroy_write_struct(&write_ptr, &write_info_ptr); |
| 725 |
#endif |
| 726 |
FCLOSE(fpin); |
| 727 |
FCLOSE(fpout); |
| 728 |
return (1); |
| 729 |
} |
| 730 |
#ifdef USE_FAR_KEYWORD |
| 731 |
png_memcpy(png_jmpbuf(write_ptr),jmpbuf,png_sizeof(jmp_buf)); |
| 732 |
#endif |
| 733 |
#endif |
| 734 |
#endif |
| 735 |
|
| 736 |
png_debug(0, "Initializing input and output streams\n"); |
| 737 |
#if !defined(PNG_NO_STDIO) |
| 738 |
png_init_io(read_ptr, fpin); |
| 739 |
# ifdef PNG_WRITE_SUPPORTED |
| 740 |
png_init_io(write_ptr, fpout); |
| 741 |
# endif |
| 742 |
#else |
| 743 |
png_set_read_fn(read_ptr, (png_voidp)fpin, pngtest_read_data); |
| 744 |
# ifdef PNG_WRITE_SUPPORTED |
| 745 |
png_set_write_fn(write_ptr, (png_voidp)fpout, pngtest_write_data, |
| 746 |
# if defined(PNG_WRITE_FLUSH_SUPPORTED) |
| 747 |
pngtest_flush); |
| 748 |
# else |
| 749 |
NULL); |
| 750 |
# endif |
| 751 |
# endif |
| 752 |
#endif |
| 753 |
if(status_dots_requested == 1) |
| 754 |
{ |
| 755 |
#ifdef PNG_WRITE_SUPPORTED |
| 756 |
png_set_write_status_fn(write_ptr, write_row_callback); |
| 757 |
#endif |
| 758 |
png_set_read_status_fn(read_ptr, read_row_callback); |
| 759 |
} |
| 760 |
else |
| 761 |
{ |
| 762 |
#ifdef PNG_WRITE_SUPPORTED |
| 763 |
png_set_write_status_fn(write_ptr, png_write_status_ptr_NULL); |
| 764 |
#endif |
| 765 |
png_set_read_status_fn(read_ptr, png_read_status_ptr_NULL); |
| 766 |
} |
| 767 |
|
| 768 |
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) |
| 769 |
{ |
| 770 |
int i; |
| 771 |
for(i=0; i<256; i++) |
| 772 |
filters_used[i]=0; |
| 773 |
png_set_read_user_transform_fn(read_ptr, count_filters); |
| 774 |
} |
| 775 |
#endif |
| 776 |
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) |
| 777 |
zero_samples=0; |
| 778 |
png_set_write_user_transform_fn(write_ptr, count_zero_samples); |
| 779 |
#endif |
| 780 |
|
| 781 |
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) |
| 782 |
# ifndef PNG_HANDLE_CHUNK_ALWAYS |
| 783 |
# define PNG_HANDLE_CHUNK_ALWAYS 3 |
| 784 |
# endif |
| 785 |
png_set_keep_unknown_chunks(read_ptr, PNG_HANDLE_CHUNK_ALWAYS, |
| 786 |
png_bytep_NULL, 0); |
| 787 |
#endif |
| 788 |
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) |
| 789 |
# ifndef PNG_HANDLE_CHUNK_IF_SAFE |
| 790 |
# define PNG_HANDLE_CHUNK_IF_SAFE 2 |
| 791 |
# endif |
| 792 |
png_set_keep_unknown_chunks(write_ptr, PNG_HANDLE_CHUNK_IF_SAFE, |
| 793 |
png_bytep_NULL, 0); |
| 794 |
#endif |
| 795 |
|
| 796 |
png_debug(0, "Reading info struct\n"); |
| 797 |
png_read_info(read_ptr, read_info_ptr); |
| 798 |
|
| 799 |
png_debug(0, "Transferring info struct\n"); |
| 800 |
{ |
| 801 |
int interlace_type, compression_type, filter_type; |
| 802 |
|
| 803 |
if (png_get_IHDR(read_ptr, read_info_ptr, &width, &height, &bit_depth, |
| 804 |
&color_type, &interlace_type, &compression_type, &filter_type)) |
| 805 |
{ |
| 806 |
png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth, |
| 807 |
#if defined(PNG_WRITE_INTERLACING_SUPPORTED) |
| 808 |
color_type, interlace_type, compression_type, filter_type); |
| 809 |
#else |
| 810 |
color_type, PNG_INTERLACE_NONE, compression_type, filter_type); |
| 811 |
#endif |
| 812 |
} |
| 813 |
} |
| 814 |
#if defined(PNG_FIXED_POINT_SUPPORTED) |
| 815 |
#if defined(PNG_cHRM_SUPPORTED) |
| 816 |
{ |
| 817 |
png_fixed_point white_x, white_y, red_x, red_y, green_x, green_y, blue_x, |
| 818 |
blue_y; |
| 819 |
if (png_get_cHRM_fixed(read_ptr, read_info_ptr, &white_x, &white_y, &red_x, |
| 820 |
&red_y, &green_x, &green_y, &blue_x, &blue_y)) |
| 821 |
{ |
| 822 |
png_set_cHRM_fixed(write_ptr, write_info_ptr, white_x, white_y, red_x, |
| 823 |
red_y, green_x, green_y, blue_x, blue_y); |
| 824 |
} |
| 825 |
} |
| 826 |
#endif |
| 827 |
#if defined(PNG_gAMA_SUPPORTED) |
| 828 |
{ |
| 829 |
png_fixed_point gamma; |
| 830 |
|
| 831 |
if (png_get_gAMA_fixed(read_ptr, read_info_ptr, &gamma)) |
| 832 |
{ |
| 833 |
png_set_gAMA_fixed(write_ptr, write_info_ptr, gamma); |
| 834 |
} |
| 835 |
} |
| 836 |
#endif |
| 837 |
#else |
| 838 |
#if defined(PNG_FLOATING_POINT_SUPPORTED) |
| 839 |
#if defined(PNG_cHRM_SUPPORTED) |
| 840 |
{ |
| 841 |
double white_x, white_y, red_x, red_y, green_x, green_y, blue_x, |
| 842 |
blue_y; |
| 843 |
if (png_get_cHRM(read_ptr, read_info_ptr, &white_x, &white_y, &red_x, |
| 844 |
&red_y, &green_x, &green_y, &blue_x, &blue_y)) |
| 845 |
{ |
| 846 |
png_set_cHRM(write_ptr, write_info_ptr, white_x, white_y, red_x, |
| 847 |
red_y, green_x, green_y, blue_x, blue_y); |
| 848 |
} |
| 849 |
} |
| 850 |
#endif |
| 851 |
#if defined(PNG_gAMA_SUPPORTED) |
| 852 |
{ |
| 853 |
double gamma; |
| 854 |
|
| 855 |
if (png_get_gAMA(read_ptr, read_info_ptr, &gamma)) |
| 856 |
{ |
| 857 |
png_set_gAMA(write_ptr, write_info_ptr, gamma); |
| 858 |
} |
| 859 |
} |
| 860 |
#endif |
| 861 |
#endif |
| 862 |
#endif |
| 863 |
#if defined(PNG_iCCP_SUPPORTED) |
| 864 |
{ |
| 865 |
png_charp name; |
| 866 |
png_charp profile; |
| 867 |
png_uint_32 proflen; |
| 868 |
int compression_type; |
| 869 |
|
| 870 |
if (png_get_iCCP(read_ptr, read_info_ptr, &name, &compression_type, |
| 871 |
&profile, &proflen)) |
| 872 |
{ |
| 873 |
png_set_iCCP(write_ptr, write_info_ptr, name, compression_type, |
| 874 |
profile, proflen); |
| 875 |
} |
| 876 |
} |
| 877 |
#endif |
| 878 |
#if defined(PNG_sRGB_SUPPORTED) |
| 879 |
{ |
| 880 |
int intent; |
| 881 |
|
| 882 |
if (png_get_sRGB(read_ptr, read_info_ptr, &intent)) |
| 883 |
{ |
| 884 |
png_set_sRGB(write_ptr, write_info_ptr, intent); |
| 885 |
} |
| 886 |
} |
| 887 |
#endif |
| 888 |
{ |
| 889 |
png_colorp palette; |
| 890 |
int num_palette; |
| 891 |
|
| 892 |
if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette)) |
| 893 |
{ |
| 894 |
png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette); |
| 895 |
} |
| 896 |
} |
| 897 |
#if defined(PNG_bKGD_SUPPORTED) |
| 898 |
{ |
| 899 |
png_color_16p background; |
| 900 |
|
| 901 |
if (png_get_bKGD(read_ptr, read_info_ptr, &background)) |
| 902 |
{ |
| 903 |
png_set_bKGD(write_ptr, write_info_ptr, background); |
| 904 |
} |
| 905 |
} |
| 906 |
#endif |
| 907 |
#if defined(PNG_hIST_SUPPORTED) |
| 908 |
{ |
| 909 |
png_uint_16p hist; |
| 910 |
|
| 911 |
if (png_get_hIST(read_ptr, read_info_ptr, &hist)) |
| 912 |
{ |
| 913 |
png_set_hIST(write_ptr, write_info_ptr, hist); |
| 914 |
} |
| 915 |
} |
| 916 |
#endif |
| 917 |
#if defined(PNG_oFFs_SUPPORTED) |
| 918 |
{ |
| 919 |
png_int_32 offset_x, offset_y; |
| 920 |
int unit_type; |
| 921 |
|
| 922 |
if (png_get_oFFs(read_ptr, read_info_ptr,&offset_x,&offset_y,&unit_type)) |
| 923 |
{ |
| 924 |
png_set_oFFs(write_ptr, write_info_ptr, offset_x, offset_y, unit_type); |
| 925 |
} |
| 926 |
} |
| 927 |
#endif |
| 928 |
#if defined(PNG_pCAL_SUPPORTED) |
| 929 |
{ |
| 930 |
png_charp purpose, units; |
| 931 |
png_charpp params; |
| 932 |
png_int_32 X0, X1; |
| 933 |
int type, nparams; |
| 934 |
|
| 935 |
if (png_get_pCAL(read_ptr, read_info_ptr, &purpose, &X0, &X1, &type, |
| 936 |
&nparams, &units, ¶ms)) |
| 937 |
{ |
| 938 |
png_set_pCAL(write_ptr, write_info_ptr, purpose, X0, X1, type, |
| 939 |
nparams, units, params); |
| 940 |
} |
| 941 |
} |
| 942 |
#endif |
| 943 |
#if defined(PNG_pHYs_SUPPORTED) |
| 944 |
{ |
| 945 |
png_uint_32 res_x, res_y; |
| 946 |
int unit_type; |
| 947 |
|
| 948 |
if (png_get_pHYs(read_ptr, read_info_ptr, &res_x, &res_y, &unit_type)) |
| 949 |
{ |
| 950 |
png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type); |
| 951 |
} |
| 952 |
} |
| 953 |
#endif |
| 954 |
#if defined(PNG_sBIT_SUPPORTED) |
| 955 |
{ |
| 956 |
png_color_8p sig_bit; |
| 957 |
|
| 958 |
if (png_get_sBIT(read_ptr, read_info_ptr, &sig_bit)) |
| 959 |
{ |
| 960 |
png_set_sBIT(write_ptr, write_info_ptr, sig_bit); |
| 961 |
} |
| 962 |
} |
| 963 |
#endif |
| 964 |
#if defined(PNG_sCAL_SUPPORTED) |
| 965 |
#ifdef PNG_FLOATING_POINT_SUPPORTED |
| 966 |
{ |
| 967 |
int unit; |
| 968 |
double scal_width, scal_height; |
| 969 |
|
| 970 |
if (png_get_sCAL(read_ptr, read_info_ptr, &unit, &scal_width, |
| 971 |
&scal_height)) |
| 972 |
{ |
| 973 |
png_set_sCAL(write_ptr, write_info_ptr, unit, scal_width, scal_height); |
| 974 |
} |
| 975 |
} |
| 976 |
#else |
| 977 |
#ifdef PNG_FIXED_POINT_SUPPORTED |
| 978 |
{ |
| 979 |
int unit; |
| 980 |
png_charp scal_width, scal_height; |
| 981 |
|
| 982 |
if (png_get_sCAL_s(read_ptr, read_info_ptr, &unit, &scal_width, |
| 983 |
&scal_height)) |
| 984 |
{ |
| 985 |
png_set_sCAL_s(write_ptr, write_info_ptr, unit, scal_width, scal_height); |
| 986 |
} |
| 987 |
} |
| 988 |
#endif |
| 989 |
#endif |
| 990 |
#endif |
| 991 |
#if defined(PNG_TEXT_SUPPORTED) |
| 992 |
{ |
| 993 |
png_textp text_ptr; |
| 994 |
int num_text; |
| 995 |
|
| 996 |
if (png_get_text(read_ptr, read_info_ptr, &text_ptr, &num_text) > 0) |
| 997 |
{ |
| 998 |
png_debug1(0, "Handling %d iTXt/tEXt/zTXt chunks\n", num_text); |
| 999 |
png_set_text(write_ptr, write_info_ptr, text_ptr, num_text); |
| 1000 |
} |
| 1001 |
} |
| 1002 |
#endif |
| 1003 |
#if defined(PNG_tIME_SUPPORTED) |
| 1004 |
{ |
| 1005 |
png_timep mod_time; |
| 1006 |
|
| 1007 |
if (png_get_tIME(read_ptr, read_info_ptr, &mod_time)) |
| 1008 |
{ |
| 1009 |
png_set_tIME(write_ptr, write_info_ptr, mod_time); |
| 1010 |
#if defined(PNG_TIME_RFC1123_SUPPORTED) |
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
png_strcpy(tIME_string,png_convert_to_rfc1123(read_ptr, mod_time)); |
| 1015 |
tIME_chunk_present++; |
| 1016 |
#endif |
| 1017 |
} |
| 1018 |
} |
| 1019 |
#endif |
| 1020 |
#if defined(PNG_tRNS_SUPPORTED) |
| 1021 |
{ |
| 1022 |
png_bytep trans; |
| 1023 |
int num_trans; |
| 1024 |
png_color_16p trans_values; |
| 1025 |
|
| 1026 |
if (png_get_tRNS(read_ptr, read_info_ptr, &trans, &num_trans, |
| 1027 |
&trans_values)) |
| 1028 |
{ |
| 1029 |
png_set_tRNS(write_ptr, write_info_ptr, trans, num_trans, |
| 1030 |
trans_values); |
| 1031 |
} |
| 1032 |
} |
| 1033 |
#endif |
| 1034 |
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) |
| 1035 |
{ |
| 1036 |
png_unknown_chunkp unknowns; |
| 1037 |
int num_unknowns = (int)png_get_unknown_chunks(read_ptr, read_info_ptr, |
| 1038 |
&unknowns); |
| 1039 |
if (num_unknowns) |
| 1040 |
{ |
| 1041 |
png_size_t i; |
| 1042 |
png_set_unknown_chunks(write_ptr, write_info_ptr, unknowns, |
| 1043 |
num_unknowns); |
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
for (i = 0; i < (png_size_t)num_unknowns; i++) |
| 1048 |
png_set_unknown_chunk_location(write_ptr, write_info_ptr, i, |
| 1049 |
unknowns[i].location); |
| 1050 |
} |
| 1051 |
} |
| 1052 |
#endif |
| 1053 |
|
| 1054 |
#ifdef PNG_WRITE_SUPPORTED |
| 1055 |
png_debug(0, "\nWriting info struct\n"); |
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
png_write_info(write_ptr, write_info_ptr); |
| 1061 |
#endif |
| 1062 |
|
| 1063 |
#ifdef SINGLE_ROWBUF_ALLOC |
| 1064 |
png_debug(0, "\nAllocating row buffer..."); |
| 1065 |
row_buf = (png_bytep)png_malloc(read_ptr, |
| 1066 |
png_get_rowbytes(read_ptr, read_info_ptr)); |
| 1067 |
png_debug1(0, "0x%08lx\n\n", (unsigned long)row_buf); |
| 1068 |
#endif |
| 1069 |
png_debug(0, "Writing row data\n"); |
| 1070 |
|
| 1071 |
#if defined(PNG_READ_INTERLACING_SUPPORTED) || \ |
| 1072 |
defined(PNG_WRITE_INTERLACING_SUPPORTED) |
| 1073 |
num_pass = png_set_interlace_handling(read_ptr); |
| 1074 |
# ifdef PNG_WRITE_SUPPORTED |
| 1075 |
png_set_interlace_handling(write_ptr); |
| 1076 |
# endif |
| 1077 |
#else |
| 1078 |
num_pass=1; |
| 1079 |
#endif |
| 1080 |
|
| 1081 |
#ifdef PNGTEST_TIMING |
| 1082 |
t_stop = (float)clock(); |
| 1083 |
t_misc += (t_stop - t_start); |
| 1084 |
t_start = t_stop; |
| 1085 |
#endif |
| 1086 |
for (pass = 0; pass < num_pass; pass++) |
| 1087 |
{ |
| 1088 |
png_debug1(0, "Writing row data for pass %d\n",pass); |
| 1089 |
for (y = 0; y < height; y++) |
| 1090 |
{ |
| 1091 |
#ifndef SINGLE_ROWBUF_ALLOC |
| 1092 |
png_debug2(0, "\nAllocating row buffer (pass %d, y = %ld)...", pass,y); |
| 1093 |
row_buf = (png_bytep)png_malloc(read_ptr, |
| 1094 |
png_get_rowbytes(read_ptr, read_info_ptr)); |
| 1095 |
png_debug2(0, "0x%08lx (%ld bytes)\n", (unsigned long)row_buf, |
| 1096 |
png_get_rowbytes(read_ptr, read_info_ptr)); |
| 1097 |
#endif |
| 1098 |
png_read_rows(read_ptr, (png_bytepp)&row_buf, png_bytepp_NULL, 1); |
| 1099 |
|
| 1100 |
#ifdef PNG_WRITE_SUPPORTED |
| 1101 |
#ifdef PNGTEST_TIMING |
| 1102 |
t_stop = (float)clock(); |
| 1103 |
t_decode += (t_stop - t_start); |
| 1104 |
t_start = t_stop; |
| 1105 |
#endif |
| 1106 |
png_write_rows(write_ptr, (png_bytepp)&row_buf, 1); |
| 1107 |
#ifdef PNGTEST_TIMING |
| 1108 |
t_stop = (float)clock(); |
| 1109 |
t_encode += (t_stop - t_start); |
| 1110 |
t_start = t_stop; |
| 1111 |
#endif |
| 1112 |
#endif |
| 1113 |
|
| 1114 |
#ifndef SINGLE_ROWBUF_ALLOC |
| 1115 |
png_debug2(0, "Freeing row buffer (pass %d, y = %ld)\n\n", pass, y); |
| 1116 |
png_free(read_ptr, row_buf); |
| 1117 |
#endif |
| 1118 |
} |
| 1119 |
} |
| 1120 |
|
| 1121 |
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) |
| 1122 |
png_free_data(read_ptr, read_info_ptr, PNG_FREE_UNKN, -1); |
| 1123 |
#endif |
| 1124 |
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) |
| 1125 |
png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1); |
| 1126 |
#endif |
| 1127 |
|
| 1128 |
png_debug(0, "Reading and writing end_info data\n"); |
| 1129 |
|
| 1130 |
png_read_end(read_ptr, end_info_ptr); |
| 1131 |
#if defined(PNG_TEXT_SUPPORTED) |
| 1132 |
{ |
| 1133 |
png_textp text_ptr; |
| 1134 |
int num_text; |
| 1135 |
|
| 1136 |
if (png_get_text(read_ptr, end_info_ptr, &text_ptr, &num_text) > 0) |
| 1137 |
{ |
| 1138 |
png_debug1(0, "Handling %d iTXt/tEXt/zTXt chunks\n", num_text); |
| 1139 |
png_set_text(write_ptr, write_end_info_ptr, text_ptr, num_text); |
| 1140 |
} |
| 1141 |
} |
| 1142 |
#endif |
| 1143 |
#if defined(PNG_tIME_SUPPORTED) |
| 1144 |
{ |
| 1145 |
png_timep mod_time; |
| 1146 |
|
| 1147 |
if (png_get_tIME(read_ptr, end_info_ptr, &mod_time)) |
| 1148 |
{ |
| 1149 |
png_set_tIME(write_ptr, write_end_info_ptr, mod_time); |
| 1150 |
#if defined(PNG_TIME_RFC1123_SUPPORTED) |
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
png_strcpy(tIME_string,png_convert_to_rfc1123(read_ptr, mod_time)); |
| 1155 |
tIME_chunk_present++; |
| 1156 |
#endif |
| 1157 |
} |
| 1158 |
} |
| 1159 |
#endif |
| 1160 |
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) |
| 1161 |
{ |
| 1162 |
png_unknown_chunkp unknowns; |
| 1163 |
int num_unknowns; |
| 1164 |
num_unknowns = (int)png_get_unknown_chunks(read_ptr, end_info_ptr, |
| 1165 |
&unknowns); |
| 1166 |
if (num_unknowns) |
| 1167 |
{ |
| 1168 |
png_size_t i; |
| 1169 |
png_set_unknown_chunks(write_ptr, write_end_info_ptr, unknowns, |
| 1170 |
num_unknowns); |
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
for (i = 0; i < (png_size_t)num_unknowns; i++) |
| 1175 |
png_set_unknown_chunk_location(write_ptr, write_end_info_ptr, i, |
| 1176 |
unknowns[i].location); |
| 1177 |
} |
| 1178 |
} |
| 1179 |
#endif |
| 1180 |
#ifdef PNG_WRITE_SUPPORTED |
| 1181 |
png_write_end(write_ptr, write_end_info_ptr); |
| 1182 |
#endif |
| 1183 |
|
| 1184 |
#ifdef PNG_EASY_ACCESS_SUPPORTED |
| 1185 |
if(verbose) |
| 1186 |
{ |
| 1187 |
png_uint_32 iwidth, iheight; |
| 1188 |
iwidth = png_get_image_width(write_ptr, write_info_ptr); |
| 1189 |
iheight = png_get_image_height(write_ptr, write_info_ptr); |
| 1190 |
fprintf(STDERR, "Image width = %lu, height = %lu\n", |
| 1191 |
iwidth, iheight); |
| 1192 |
} |
| 1193 |
#endif |
| 1194 |
|
| 1195 |
png_debug(0, "Destroying data structs\n"); |
| 1196 |
#ifdef SINGLE_ROWBUF_ALLOC |
| 1197 |
png_debug(1, "destroying row_buf for read_ptr\n"); |
| 1198 |
png_free(read_ptr, row_buf); |
| 1199 |
row_buf=NULL; |
| 1200 |
#endif |
| 1201 |
png_debug(1, "destroying read_ptr, read_info_ptr, end_info_ptr\n"); |
| 1202 |
png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); |
| 1203 |
#ifdef PNG_WRITE_SUPPORTED |
| 1204 |
png_debug(1, "destroying write_end_info_ptr\n"); |
| 1205 |
png_destroy_info_struct(write_ptr, &write_end_info_ptr); |
| 1206 |
png_debug(1, "destroying write_ptr, write_info_ptr\n"); |
| 1207 |
png_destroy_write_struct(&write_ptr, &write_info_ptr); |
| 1208 |
#endif |
| 1209 |
png_debug(0, "Destruction complete.\n"); |
| 1210 |
|
| 1211 |
FCLOSE(fpin); |
| 1212 |
FCLOSE(fpout); |
| 1213 |
|
| 1214 |
png_debug(0, "Opening files for comparison\n"); |
| 1215 |
#if defined(_WIN32_WCE) |
| 1216 |
MultiByteToWideChar(CP_ACP, 0, inname, -1, path, MAX_PATH); |
| 1217 |
if ((fpin = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE) |
| 1218 |
#else |
| 1219 |
if ((fpin = fopen(inname, "rb")) == NULL) |
| 1220 |
#endif |
| 1221 |
{ |
| 1222 |
fprintf(STDERR, "Could not find file %s\n", inname); |
| 1223 |
return (1); |
| 1224 |
} |
| 1225 |
|
| 1226 |
#if defined(_WIN32_WCE) |
| 1227 |
MultiByteToWideChar(CP_ACP, 0, outname, -1, path, MAX_PATH); |
| 1228 |
if ((fpout = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE) |
| 1229 |
#else |
| 1230 |
if ((fpout = fopen(outname, "rb")) == NULL) |
| 1231 |
#endif |
| 1232 |
{ |
| 1233 |
fprintf(STDERR, "Could not find file %s\n", outname); |
| 1234 |
FCLOSE(fpin); |
| 1235 |
return (1); |
| 1236 |
} |
| 1237 |
|
| 1238 |
for(;;) |
| 1239 |
{ |
| 1240 |
png_size_t num_in, num_out; |
| 1241 |
|
| 1242 |
READFILE(fpin, inbuf, 1, num_in); |
| 1243 |
READFILE(fpout, outbuf, 1, num_out); |
| 1244 |
|
| 1245 |
if (num_in != num_out) |
| 1246 |
{ |
| 1247 |
fprintf(STDERR, "\nFiles %s and %s are of a different size\n", |
| 1248 |
inname, outname); |
| 1249 |
if(wrote_question == 0) |
| 1250 |
{ |
| 1251 |
fprintf(STDERR, |
| 1252 |
" Was %s written with the same maximum IDAT chunk size (%d bytes),", |
| 1253 |
inname,PNG_ZBUF_SIZE); |
| 1254 |
fprintf(STDERR, |
| 1255 |
"\n filtering heuristic (libpng default), compression"); |
| 1256 |
fprintf(STDERR, |
| 1257 |
" level (zlib default),\n and zlib version (%s)?\n\n", |
| 1258 |
ZLIB_VERSION); |
| 1259 |
wrote_question=1; |
| 1260 |
} |
| 1261 |
FCLOSE(fpin); |
| 1262 |
FCLOSE(fpout); |
| 1263 |
return (0); |
| 1264 |
} |
| 1265 |
|
| 1266 |
if (!num_in) |
| 1267 |
break; |
| 1268 |
|
| 1269 |
if (png_memcmp(inbuf, outbuf, num_in)) |
| 1270 |
{ |
| 1271 |
fprintf(STDERR, "\nFiles %s and %s are different\n", inname, outname); |
| 1272 |
if(wrote_question == 0) |
| 1273 |
{ |
| 1274 |
fprintf(STDERR, |
| 1275 |
" Was %s written with the same maximum IDAT chunk size (%d bytes),", |
| 1276 |
inname,PNG_ZBUF_SIZE); |
| 1277 |
fprintf(STDERR, |
| 1278 |
"\n filtering heuristic (libpng default), compression"); |
| 1279 |
fprintf(STDERR, |
| 1280 |
" level (zlib default),\n and zlib version (%s)?\n\n", |
| 1281 |
ZLIB_VERSION); |
| 1282 |
wrote_question=1; |
| 1283 |
} |
| 1284 |
FCLOSE(fpin); |
| 1285 |
FCLOSE(fpout); |
| 1286 |
return (0); |
| 1287 |
} |
| 1288 |
} |
| 1289 |
|
| 1290 |
FCLOSE(fpin); |
| 1291 |
FCLOSE(fpout); |
| 1292 |
|
| 1293 |
return (0); |
| 1294 |
} |
| 1295 |
|
| 1296 |
|
| 1297 |
#ifdef RISCOS |
| 1298 |
static PNG_CONST char *inname = "pngtest/png"; |
| 1299 |
static PNG_CONST char *outname = "pngout/png"; |
| 1300 |
#else |
| 1301 |
static PNG_CONST char *inname = "pngtest.png"; |
| 1302 |
static PNG_CONST char *outname = "pngout.png"; |
| 1303 |
#endif |
| 1304 |
|
| 1305 |
int |
| 1306 |
main(int argc, char *argv[]) |
| 1307 |
{ |
| 1308 |
int multiple = 0; |
| 1309 |
int ierror = 0; |
| 1310 |
|
| 1311 |
fprintf(STDERR, "Testing libpng version %s\n", PNG_LIBPNG_VER_STRING); |
| 1312 |
fprintf(STDERR, " with zlib version %s\n", ZLIB_VERSION); |
| 1313 |
fprintf(STDERR,"%s",png_get_copyright(NULL)); |
| 1314 |
|
| 1315 |
fprintf(STDERR," library (%lu):%s", png_access_version_number(), |
| 1316 |
png_get_header_version(NULL)); |
| 1317 |
|
| 1318 |
fprintf(STDERR," pngtest (%lu):%s", (unsigned long)PNG_LIBPNG_VER, |
| 1319 |
PNG_HEADER_VERSION_STRING); |
| 1320 |
fprintf(STDERR," png_sizeof(png_struct)=%ld, png_sizeof(png_info)=%ld\n", |
| 1321 |
(long)png_sizeof(png_struct), (long)png_sizeof(png_info)); |
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K) |
| 1328 |
fprintf(STDERR, " NOTE: Zlib compiled for max 64k, libpng not\n"); |
| 1329 |
#endif |
| 1330 |
|
| 1331 |
#if !defined(MAXSEG_64K) && defined(PNG_MAX_MALLOC_64K) |
| 1332 |
fprintf(STDERR, " NOTE: libpng compiled for max 64k, zlib not\n"); |
| 1333 |
#endif |
| 1334 |
|
| 1335 |
if (strcmp(png_libpng_ver, PNG_LIBPNG_VER_STRING)) |
| 1336 |
{ |
| 1337 |
fprintf(STDERR, |
| 1338 |
"Warning: versions are different between png.h and png.c\n"); |
| 1339 |
fprintf(STDERR, " png.h version: %s\n", PNG_LIBPNG_VER_STRING); |
| 1340 |
fprintf(STDERR, " png.c version: %s\n\n", png_libpng_ver); |
| 1341 |
++ierror; |
| 1342 |
} |
| 1343 |
|
| 1344 |
if (argc > 1) |
| 1345 |
{ |
| 1346 |
if (strcmp(argv[1], "-m") == 0) |
| 1347 |
{ |
| 1348 |
multiple = 1; |
| 1349 |
status_dots_requested = 0; |
| 1350 |
} |
| 1351 |
else if (strcmp(argv[1], "-mv") == 0 || |
| 1352 |
strcmp(argv[1], "-vm") == 0 ) |
| 1353 |
{ |
| 1354 |
multiple = 1; |
| 1355 |
verbose = 1; |
| 1356 |
status_dots_requested = 1; |
| 1357 |
} |
| 1358 |
else if (strcmp(argv[1], "-v") == 0) |
| 1359 |
{ |
| 1360 |
verbose = 1; |
| 1361 |
status_dots_requested = 1; |
| 1362 |
inname = argv[2]; |
| 1363 |
} |
| 1364 |
else |
| 1365 |
{ |
| 1366 |
inname = argv[1]; |
| 1367 |
status_dots_requested = 0; |
| 1368 |
} |
| 1369 |
} |
| 1370 |
|
| 1371 |
if (!multiple && argc == 3+verbose) |
| 1372 |
outname = argv[2+verbose]; |
| 1373 |
|
| 1374 |
if ((!multiple && argc > 3+verbose) || (multiple && argc < 2)) |
| 1375 |
{ |
| 1376 |
fprintf(STDERR, |
| 1377 |
"usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n", |
| 1378 |
argv[0], argv[0]); |
| 1379 |
fprintf(STDERR, |
| 1380 |
" reads/writes one PNG file (without -m) or multiple files (-m)\n"); |
| 1381 |
fprintf(STDERR, |
| 1382 |
" with -m %s is used as a temporary file\n", outname); |
| 1383 |
exit(1); |
| 1384 |
} |
| 1385 |
|
| 1386 |
if (multiple) |
| 1387 |
{ |
| 1388 |
int i; |
| 1389 |
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG |
| 1390 |
int allocation_now = current_allocation; |
| 1391 |
#endif |
| 1392 |
for (i=2; i<argc; ++i) |
| 1393 |
{ |
| 1394 |
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) |
| 1395 |
int k; |
| 1396 |
#endif |
| 1397 |
int kerror; |
| 1398 |
fprintf(STDERR, "Testing %s:",argv[i]); |
| 1399 |
kerror = test_one_file(argv[i], outname); |
| 1400 |
if (kerror == 0) |
| 1401 |
{ |
| 1402 |
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) |
| 1403 |
fprintf(STDERR, "\n PASS (%lu zero samples)\n",zero_samples); |
| 1404 |
#else |
| 1405 |
fprintf(STDERR, " PASS\n"); |
| 1406 |
#endif |
| 1407 |
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) |
| 1408 |
for (k=0; k<256; k++) |
| 1409 |
if(filters_used[k]) |
| 1410 |
fprintf(STDERR, " Filter %d was used %lu times\n", |
| 1411 |
k,filters_used[k]); |
| 1412 |
#endif |
| 1413 |
#if defined(PNG_TIME_RFC1123_SUPPORTED) |
| 1414 |
if(tIME_chunk_present != 0) |
| 1415 |
fprintf(STDERR, " tIME = %s\n",tIME_string); |
| 1416 |
tIME_chunk_present = 0; |
| 1417 |
#endif |
| 1418 |
} |
| 1419 |
else |
| 1420 |
{ |
| 1421 |
fprintf(STDERR, " FAIL\n"); |
| 1422 |
ierror += kerror; |
| 1423 |
} |
| 1424 |
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG |
| 1425 |
if (allocation_now != current_allocation) |
| 1426 |
fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n", |
| 1427 |
current_allocation-allocation_now); |
| 1428 |
if (current_allocation != 0) |
| 1429 |
{ |
| 1430 |
memory_infop pinfo = pinformation; |
| 1431 |
|
| 1432 |
fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n", |
| 1433 |
current_allocation); |
| 1434 |
while (pinfo != NULL) |
| 1435 |
{ |
| 1436 |
fprintf(STDERR, " %lu bytes at %x\n", pinfo->size, |
| 1437 |
(unsigned int) pinfo->pointer); |
| 1438 |
pinfo = pinfo->next; |
| 1439 |
} |
| 1440 |
} |
| 1441 |
#endif |
| 1442 |
} |
| 1443 |
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG |
| 1444 |
fprintf(STDERR, " Current memory allocation: %10d bytes\n", |
| 1445 |
current_allocation); |
| 1446 |
fprintf(STDERR, " Maximum memory allocation: %10d bytes\n", |
| 1447 |
maximum_allocation); |
| 1448 |
fprintf(STDERR, " Total memory allocation: %10d bytes\n", |
| 1449 |
total_allocation); |
| 1450 |
fprintf(STDERR, " Number of allocations: %10d\n", |
| 1451 |
num_allocations); |
| 1452 |
#endif |
| 1453 |
} |
| 1454 |
else |
| 1455 |
{ |
| 1456 |
int i; |
| 1457 |
for (i=0; i<3; ++i) |
| 1458 |
{ |
| 1459 |
int kerror; |
| 1460 |
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG |
| 1461 |
int allocation_now = current_allocation; |
| 1462 |
#endif |
| 1463 |
if (i == 1) status_dots_requested = 1; |
| 1464 |
else if(verbose == 0)status_dots_requested = 0; |
| 1465 |
if (i == 0 || verbose == 1 || ierror != 0) |
| 1466 |
fprintf(STDERR, "Testing %s:",inname); |
| 1467 |
kerror = test_one_file(inname, outname); |
| 1468 |
if(kerror == 0) |
| 1469 |
{ |
| 1470 |
if(verbose == 1 || i == 2) |
| 1471 |
{ |
| 1472 |
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) |
| 1473 |
int k; |
| 1474 |
#endif |
| 1475 |
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) |
| 1476 |
fprintf(STDERR, "\n PASS (%lu zero samples)\n",zero_samples); |
| 1477 |
#else |
| 1478 |
fprintf(STDERR, " PASS\n"); |
| 1479 |
#endif |
| 1480 |
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) |
| 1481 |
for (k=0; k<256; k++) |
| 1482 |
if(filters_used[k]) |
| 1483 |
fprintf(STDERR, " Filter %d was used %lu times\n", |
| 1484 |
k,filters_used[k]); |
| 1485 |
#endif |
| 1486 |
#if defined(PNG_TIME_RFC1123_SUPPORTED) |
| 1487 |
if(tIME_chunk_present != 0) |
| 1488 |
fprintf(STDERR, " tIME = %s\n",tIME_string); |
| 1489 |
#endif |
| 1490 |
} |
| 1491 |
} |
| 1492 |
else |
| 1493 |
{ |
| 1494 |
if(verbose == 0 && i != 2) |
| 1495 |
fprintf(STDERR, "Testing %s:",inname); |
| 1496 |
fprintf(STDERR, " FAIL\n"); |
| 1497 |
ierror += kerror; |
| 1498 |
} |
| 1499 |
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG |
| 1500 |
if (allocation_now != current_allocation) |
| 1501 |
fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n", |
| 1502 |
current_allocation-allocation_now); |
| 1503 |
if (current_allocation != 0) |
| 1504 |
{ |
| 1505 |
memory_infop pinfo = pinformation; |
| 1506 |
|
| 1507 |
fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n", |
| 1508 |
current_allocation); |
| 1509 |
while (pinfo != NULL) |
| 1510 |
{ |
| 1511 |
fprintf(STDERR," %lu bytes at %x\n", |
| 1512 |
pinfo->size, (unsigned int)pinfo->pointer); |
| 1513 |
pinfo = pinfo->next; |
| 1514 |
} |
| 1515 |
} |
| 1516 |
#endif |
| 1517 |
} |
| 1518 |
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG |
| 1519 |
fprintf(STDERR, " Current memory allocation: %10d bytes\n", |
| 1520 |
current_allocation); |
| 1521 |
fprintf(STDERR, " Maximum memory allocation: %10d bytes\n", |
| 1522 |
maximum_allocation); |
| 1523 |
fprintf(STDERR, " Total memory allocation: %10d bytes\n", |
| 1524 |
total_allocation); |
| 1525 |
fprintf(STDERR, " Number of allocations: %10d\n", |
| 1526 |
num_allocations); |
| 1527 |
#endif |
| 1528 |
} |
| 1529 |
|
| 1530 |
#ifdef PNGTEST_TIMING |
| 1531 |
t_stop = (float)clock(); |
| 1532 |
t_misc += (t_stop - t_start); |
| 1533 |
t_start = t_stop; |
| 1534 |
fprintf(STDERR," CPU time used = %.3f seconds", |
| 1535 |
(t_misc+t_decode+t_encode)/(float)CLOCKS_PER_SEC); |
| 1536 |
fprintf(STDERR," (decoding %.3f,\n", |
| 1537 |
t_decode/(float)CLOCKS_PER_SEC); |
| 1538 |
fprintf(STDERR," encoding %.3f ,", |
| 1539 |
t_encode/(float)CLOCKS_PER_SEC); |
| 1540 |
fprintf(STDERR," other %.3f seconds)\n\n", |
| 1541 |
t_misc/(float)CLOCKS_PER_SEC); |
| 1542 |
#endif |
| 1543 |
|
| 1544 |
if (ierror == 0) |
| 1545 |
fprintf(STDERR, "libpng passes test\n"); |
| 1546 |
else |
| 1547 |
fprintf(STDERR, "libpng FAILS test\n"); |
| 1548 |
return (int)(ierror != 0); |
| 1549 |
} |
| 1550 |
|
| 1551 |
|
| 1552 |
typedef version_1_2_12 your_png_h_is_not_version_1_2_12; |