Lines Matching defs:dp
578 display_init(struct display *dp)
584 memset(dp, 0, sizeof *dp);
585 dp->options = WARNINGS; /* default to !verbose, !quiet */
586 dp->filename = NULL;
587 dp->operation = NULL;
588 dp->original_pp = NULL;
589 dp->original_ip = NULL;
590 dp->original_rows = NULL;
591 dp->read_pp = NULL;
592 dp->read_ip = NULL;
593 buffer_init(&dp->original_file);
596 dp->write_pp = NULL;
597 buffer_init(&dp->written_file);
602 display_clean_read(struct display *dp)
604 if (dp->read_pp != NULL)
605 png_destroy_read_struct(&dp->read_pp, &dp->read_ip, NULL);
610 display_clean_write(struct display *dp)
612 if (dp->write_pp != NULL)
613 png_destroy_write_struct(&dp->write_pp, NULL);
618 display_clean(struct display *dp)
621 display_clean_write(dp);
623 display_clean_read(dp);
625 dp->original_rowbytes = 0;
626 dp->original_rows = NULL;
627 dp->chunks = 0;
629 png_destroy_read_struct(&dp->original_pp, &dp->original_ip, NULL);
631 dp->results = 0; /* reset for next time */
635 display_destroy(struct display *dp)
639 buffer_destroy(&dp->written_file);
642 buffer_destroy(&dp->original_file);
649 struct display *dp = (struct display*)png_get_error_ptr(pp);
651 if (dp == NULL)
657 return dp;
670 display_log(struct display *dp, error_level level, const char *fmt, ...)
675 dp->results |= 1U << level;
677 if (level > (error_level)(dp->options & LEVEL_MASK))
699 dp->filename != NULL ? dp->filename : "<stdin>", lp, dp->operation);
701 if (dp->transforms != 0)
703 int tr = dp->transforms;
707 if (dp->options & LIST_COMBOS)
751 if (level > APP_FAIL || (level > ERRORS && !(dp->options & CONTINUE)))
752 longjmp(dp->error_return, level);
765 struct display *dp = get_dp(pp);
767 display_log(dp, LIBPNG_ERROR, "%s", error);
771 display_cache_file(struct display *dp, const char *filename)
777 dp->filename = filename;
783 display_log(dp, USER_ERROR, "open failed: %s", strerror(errno));
789 ret = buffer_from_file(&dp->original_file, fp);
794 display_log(dp, APP_ERROR, "read failed: %s", strerror(ret));
798 buffer_read(struct display *dp, struct buffer *bp, png_bytep data,
811 display_log(dp, USER_ERROR, "file truncated (%lu bytes)",
827 display_log(dp, INTERNAL_ERROR, "damaged buffer list");
853 read_png(struct display *dp, struct buffer *bp, const char *operation,
862 display_clean_read(dp);
866 dp->operation = operation;
867 dp->transforms = transforms;
870 dp->read_pp = pp = png_create_read_struct(PNG_LIBPNG_VER_STRING, dp,
873 display_log(dp, LIBPNG_ERROR, "failed to create read struct");
878 dp->read_ip = ip = png_create_info_struct(pp);
880 display_log(dp, LIBPNG_ERROR, "failed to create info struct");
911 update_display(struct display *dp)
920 read_png(dp, &dp->original_file, "original read", 0/*no transform*/);
923 dp->original_pp = pp = dp->read_pp, dp->read_pp = NULL;
924 dp->original_ip = ip = dp->read_ip, dp->read_ip = NULL;
926 dp->original_rowbytes = png_get_rowbytes(pp, ip);
927 if (dp->original_rowbytes == 0)
928 display_log(dp, LIBPNG_BUG, "png_get_rowbytes returned 0");
930 dp->chunks = png_get_valid(pp, ip, 0xffffffff);
931 if ((dp->chunks & PNG_INFO_IDAT) == 0) /* set by png_read_png */
932 display_log(dp, LIBPNG_BUG, "png_read_png did not set IDAT flag");
934 dp->original_rows = png_get_rows(pp, ip);
935 if (dp->original_rows == NULL)
936 display_log(dp, LIBPNG_BUG, "png_read_png did not create row buffers");
939 &dp->width, &dp->height, &dp->bit_depth, &dp->color_type,
940 &dp->interlace_method, &dp->compression_method, &dp->filter_method))
941 display_log(dp, LIBPNG_BUG, "png_get_IHDR failed");
948 png_uint_32 chunks = dp->chunks;
950 int ct = dp->color_type;
951 int bd = dp->bit_depth;
977 dp->active_transforms = active;
978 dp->ignored_transforms = inactive; /* excluding write-only transforms */
983 compare_read(struct display *dp, int applied_transforms)
992 png_get_IHDR(dp->read_pp, dp->read_ip, &width, &height, &bit_depth,
995 # define C(item) if (item != dp->item) \
996 display_log(dp, APP_WARNING, "IHDR " #item "(%lu) changed to %lu",\
997 (unsigned long)dp->item, (unsigned long)item), e = #item
1010 display_log(dp, APP_ERROR, "IHDR changed (%s)", e);
1017 png_get_valid(dp->read_pp, dp->read_ip, 0xffffffff);
1019 if (chunks != dp->chunks)
1020 display_log(dp, APP_FAIL, "PNG chunks changed from 0x%lx to 0x%lx",
1021 (unsigned long)dp->chunks, chunks);
1025 rowbytes = png_get_rowbytes(dp->read_pp, dp->read_ip);
1030 if (rowbytes != dp->original_rowbytes)
1031 display_log(dp, APP_ERROR, "PNG rowbytes changed from %lu to %lu",
1032 (unsigned long)dp->original_rowbytes, (unsigned long)rowbytes);
1038 png_bytepp rows = png_get_rows(dp->read_pp, dp->read_ip);
1054 display_log(dp, LIBPNG_BUG, "png_get_rows returned NULL");
1057 (dp->active_transforms & PNG_TRANSFORM_SHIFT) == 0 ||
1065 png_bytep orig = dp->original_rows[y];
1076 display_log(dp, APP_FAIL,
1092 if (png_get_sBIT(dp->read_pp, dp->read_ip, &sBIT) != PNG_INFO_sBIT)
1093 display_log(dp, INTERNAL_ERROR,
1125 display_log(dp, LIBPNG_ERROR, "invalid colour type %d",
1142 display_log(dp, LIBPNG_BUG,
1153 display_log(dp, INTERNAL_ERROR, "invalid bpp %u for bit_depth %u",
1197 display_log(dp, LIBPNG_BUG, "invalid bit depth %d", bit_depth);
1212 display_log(dp, INTERNAL_ERROR, "mask calculation error %u, %u",
1219 png_bytep orig = dp->original_rows[y];
1230 display_log(dp, APP_FAIL,
1240 display_log(dp, APP_FAIL,
1253 buffer_write(struct display *dp, struct buffer *buffer, png_bytep data,
1274 display_log(dp, APP_ERROR, "out of memory saving file");
1304 write_png(struct display *dp, png_infop ip, int transforms)
1306 display_clean_write(dp); /* safety */
1308 buffer_start_write(&dp->written_file);
1309 dp->operation = "write";
1310 dp->transforms = transforms;
1312 dp->write_pp = png_create_write_struct(PNG_LIBPNG_VER_STRING, dp,
1315 if (dp->write_pp == NULL)
1316 display_log(dp, APP_ERROR, "failed to create write png_struct");
1318 png_set_write_fn(dp->write_pp, &dp->written_file, write_function,
1323 png_set_user_limits(dp->write_pp, 0x7fffffff, 0x7fffffff);
1333 int ct = dp->color_type;
1339 png_set_IHDR(dp->write_pp, ip, dp->width, dp->height, dp->bit_depth, ct,
1340 dp->interlace_method, dp->compression_method, dp->filter_method);
1343 png_write_png(dp->write_pp, ip, transforms, NULL/*params*/);
1348 display_clean_write(dp);
1353 skip_transform(struct display *dp, int tr)
1356 if ((dp->options & SKIP_BUGS) != 0 && is_bad_combo(tr))
1361 if ((dp->options & LOG_SKIPPED) != 0)
1363 printf("SKIP: %s transforms ", dp->filename);
1379 display_log(dp, INFORMATION, "%s: skipped known bad combo 0x%x",
1380 dp->filename, tr);
1389 test_one_file(struct display *dp, const char *filename)
1394 dp->operation = "cache file";
1395 dp->transforms = 0;
1396 display_cache_file(dp, filename);
1397 update_display(dp);
1402 if (dp->ignored_transforms != 0)
1404 read_png(dp, &dp->original_file, "ignored transforms",
1405 dp->ignored_transforms);
1408 if (!compare_read(dp, 0/*transforms applied*/))
1417 dp->operation = "write";
1418 write_png(dp, dp->original_ip, 0/*transforms*/);
1419 read_png(dp, &dp->written_file, NULL, 0/*transforms*/);
1420 if (!compare_read(dp, 0/*transforms applied*/))
1432 unsigned int active = dp->active_transforms;
1433 const int exhaustive = (dp->options & EXHAUSTIVE) != 0;
1441 read_png(dp, &dp->original_file, "active transforms", current);
1461 dp->operation = "reversible transforms";
1462 write_png(dp, dp->read_ip, current);
1467 read_png(dp, &dp->written_file, NULL, 0);
1468 if (!compare_read(dp, current/*for the SHIFT/sBIT transform*/))
1504 || skip_transform(dp, next));
1522 if (dp->options & FIND_BAD_COMBOS)
1530 dp->filename, active, bad_combo, bad_combo_list,
1534 printf("%s: no %sbad combos found\n", dp->filename,
1535 (dp->options & SKIP_BUGS) ? "additional " : "");
1541 do_test(struct display *dp, const char *file)
1544 int ret = setjmp(dp->error_return);
1548 test_one_file(dp, file);
1553 display_log(dp, INTERNAL_ERROR, "unexpected return code %d", ret);