Lines Matching refs:dp

545 display_init(struct display *dp)
551 memset(dp, 0, sizeof *dp);
552 dp->options = WARNINGS; /* default to !verbose, !quiet */
553 dp->filename = NULL;
554 dp->operation = NULL;
555 dp->original_pp = NULL;
556 dp->original_ip = NULL;
557 dp->original_rows = NULL;
558 dp->read_pp = NULL;
559 dp->read_ip = NULL;
560 buffer_init(&dp->original_file);
563 dp->write_pp = NULL;
564 buffer_init(&dp->written_file);
569 display_clean_read(struct display *dp)
571 if (dp->read_pp != NULL)
572 png_destroy_read_struct(&dp->read_pp, &dp->read_ip, NULL);
577 display_clean_write(struct display *dp)
579 if (dp->write_pp != NULL)
580 png_destroy_write_struct(&dp->write_pp, NULL);
585 display_clean(struct display *dp)
588 display_clean_write(dp);
590 display_clean_read(dp);
592 dp->original_rowbytes = 0;
593 dp->original_rows = NULL;
594 dp->chunks = 0;
596 png_destroy_read_struct(&dp->original_pp, &dp->original_ip, NULL);
598 dp->results = 0; /* reset for next time */
605 struct display *dp = (struct display*)png_get_error_ptr(pp);
607 if (dp == NULL)
613 return dp;
626 display_log(struct display *dp, error_level level, const char *fmt, ...)
631 dp->results |= 1U << level;
633 if (level > (error_level)(dp->options & LEVEL_MASK))
655 dp->filename != NULL ? dp->filename : "<stdin>", lp, dp->operation);
657 if (dp->transforms != 0)
659 int tr = dp->transforms;
679 if (level > APP_FAIL || (level > ERRORS && !(dp->options & CONTINUE)))
680 longjmp(dp->error_return, level);
693 struct display *dp = get_dp(pp);
695 display_log(dp, LIBPNG_ERROR, "%s", error);
699 display_cache_file(struct display *dp, const char *filename)
705 dp->filename = filename;
711 display_log(dp, USER_ERROR, "open failed: %s", strerror(errno));
717 ret = buffer_from_file(&dp->original_file, fp);
722 display_log(dp, APP_ERROR, "read failed: %s", strerror(ret));
726 buffer_read(struct display *dp, struct buffer *bp, png_bytep data,
739 display_log(dp, USER_ERROR, "file truncated (%lu bytes)",
755 display_log(dp, INTERNAL_ERROR, "damaged buffer list");
781 read_png(struct display *dp, struct buffer *bp, const char *operation,
790 display_clean_read(dp);
794 dp->operation = operation;
795 dp->transforms = transforms;
798 dp->read_pp = pp = png_create_read_struct(PNG_LIBPNG_VER_STRING, dp,
801 display_log(dp, LIBPNG_ERROR, "failed to create read struct");
806 dp->read_ip = ip = png_create_info_struct(pp);
808 display_log(dp, LIBPNG_ERROR, "failed to create info struct");
839 update_display(struct display *dp)
848 read_png(dp, &dp->original_file, "original read", 0/*no transform*/);
851 dp->original_pp = pp = dp->read_pp, dp->read_pp = NULL;
852 dp->original_ip = ip = dp->read_ip, dp->read_ip = NULL;
854 dp->original_rowbytes = png_get_rowbytes(pp, ip);
855 if (dp->original_rowbytes == 0)
856 display_log(dp, LIBPNG_BUG, "png_get_rowbytes returned 0");
858 dp->chunks = png_get_valid(pp, ip, 0xffffffff);
859 if ((dp->chunks & PNG_INFO_IDAT) == 0) /* set by png_read_png */
860 display_log(dp, LIBPNG_BUG, "png_read_png did not set IDAT flag");
862 dp->original_rows = png_get_rows(pp, ip);
863 if (dp->original_rows == NULL)
864 display_log(dp, LIBPNG_BUG, "png_read_png did not create row buffers");
867 &dp->width, &dp->height, &dp->bit_depth, &dp->color_type,
868 &dp->interlace_method, &dp->compression_method, &dp->filter_method))
869 display_log(dp, LIBPNG_BUG, "png_get_IHDR failed");
876 png_uint_32 chunks = dp->chunks;
878 int ct = dp->color_type;
879 int bd = dp->bit_depth;
905 dp->active_transforms = active;
906 dp->ignored_transforms = inactive; /* excluding write-only transforms */
909 display_log(dp, INTERNAL_ERROR, "bad transform table");
914 compare_read(struct display *dp, int applied_transforms)
923 png_get_IHDR(dp->read_pp, dp->read_ip, &width, &height, &bit_depth,
926 # define C(item) if (item != dp->item) \
927 display_log(dp, APP_WARNING, "IHDR " #item "(%lu) changed to %lu",\
928 (unsigned long)dp->item, (unsigned long)item), e = #item
941 display_log(dp, APP_ERROR, "IHDR changed (%s)", e);
948 png_get_valid(dp->read_pp, dp->read_ip, 0xffffffff);
950 if (chunks != dp->chunks)
951 display_log(dp, APP_FAIL, "PNG chunks changed from 0x%lx to 0x%lx",
952 (unsigned long)dp->chunks, chunks);
956 rowbytes = png_get_rowbytes(dp->read_pp, dp->read_ip);
961 if (rowbytes != dp->original_rowbytes)
962 display_log(dp, APP_ERROR, "PNG rowbytes changed from %lu to %lu",
963 (unsigned long)dp->original_rowbytes, (unsigned long)rowbytes);
969 png_bytepp rows = png_get_rows(dp->read_pp, dp->read_ip);
985 display_log(dp, LIBPNG_BUG, "png_get_rows returned NULL");
988 (dp->active_transforms & PNG_TRANSFORM_SHIFT) == 0 ||
996 png_bytep orig = dp->original_rows[y];
1007 display_log(dp, APP_FAIL,
1023 if (png_get_sBIT(dp->read_pp, dp->read_ip, &sBIT) != PNG_INFO_sBIT)
1024 display_log(dp, INTERNAL_ERROR,
1056 display_log(dp, LIBPNG_ERROR, "invalid colour type %d",
1073 display_log(dp, LIBPNG_BUG,
1084 display_log(dp, INTERNAL_ERROR, "invalid bpp %u for bit_depth %u",
1128 display_log(dp, LIBPNG_BUG, "invalid bit depth %d", bit_depth);
1143 display_log(dp, INTERNAL_ERROR, "mask calculation error %u, %u",
1150 png_bytep orig = dp->original_rows[y];
1161 display_log(dp, APP_FAIL,
1171 display_log(dp, APP_FAIL,
1184 buffer_write(struct display *dp, struct buffer *buffer, png_bytep data,
1205 display_log(dp, APP_ERROR, "out of memory saving file");
1235 write_png(struct display *dp, png_infop ip, int transforms)
1237 display_clean_write(dp); /* safety */
1239 buffer_start_write(&dp->written_file);
1240 dp->operation = "write";
1241 dp->transforms = transforms;
1243 dp->write_pp = png_create_write_struct(PNG_LIBPNG_VER_STRING, dp,
1246 if (dp->write_pp == NULL)
1247 display_log(dp, APP_ERROR, "failed to create write png_struct");
1249 png_set_write_fn(dp->write_pp, &dp->written_file, write_function,
1254 png_set_user_limits(dp->write_pp, 0x7fffffff, 0x7fffffff);
1264 int ct = dp->color_type;
1270 png_set_IHDR(dp->write_pp, ip, dp->width, dp->height, dp->bit_depth, ct,
1271 dp->interlace_method, dp->compression_method, dp->filter_method);
1274 png_write_png(dp->write_pp, ip, transforms, NULL/*params*/);
1279 display_clean_write(dp);
1284 skip_transform(struct display *dp, int tr)
1287 if ((dp->options & SKIP_BUGS) != 0 && is_bad_combo(tr))
1292 if ((dp->options & LOG_SKIPPED) != 0)
1294 printf("SKIP: %s transforms ", dp->filename);
1310 display_log(dp, INFORMATION, "%s: skipped known bad combo 0x%x",
1311 dp->filename, tr);
1320 test_one_file(struct display *dp, const char *filename)
1325 dp->operation = "cache file";
1326 dp->transforms = 0;
1327 display_cache_file(dp, filename);
1328 update_display(dp);
1333 if (dp->ignored_transforms != 0)
1335 read_png(dp, &dp->original_file, "ignored transforms",
1336 dp->ignored_transforms);
1339 if (!compare_read(dp, 0/*transforms applied*/))
1348 dp->operation = "write";
1349 write_png(dp, dp->original_ip, 0/*transforms*/);
1350 read_png(dp, &dp->written_file, NULL, 0/*transforms*/);
1351 if (!compare_read(dp, 0/*transforms applied*/))
1363 unsigned int active = dp->active_transforms;
1364 const int exhaustive = (dp->options & EXHAUSTIVE) != 0;
1372 read_png(dp, &dp->original_file, "active transforms", current);
1392 dp->operation = "reversible transforms";
1393 write_png(dp, dp->read_ip, current);
1398 read_png(dp, &dp->written_file, NULL, 0);
1399 if (!compare_read(dp, current/*for the SHIFT/sBIT transform*/))
1435 || skip_transform(dp, next));
1453 if (dp->options & FIND_BAD_COMBOS)
1461 dp->filename, active, bad_combo, bad_combo_list,
1465 printf("%s: no %sbad combos found\n", dp->filename,
1466 (dp->options & SKIP_BUGS) ? "additional " : "");
1472 do_test(struct display *dp, const char *file)
1475 int ret = setjmp(dp->error_return);
1479 test_one_file(dp, file);
1484 display_log(dp, INTERNAL_ERROR, "unexpected return code %d", ret);