Lines Matching refs:dp

482 display_init(struct display *dp)  in display_init()  argument
488 memset(dp, 0, sizeof *dp); in display_init()
489 dp->operation = "internal error"; in display_init()
490 dp->filename = "command line"; in display_init()
491 dp->output_file = "no output file"; in display_init()
492 dp->options = WARNINGS; /* default to !verbose, !quiet */ in display_init()
493 dp->fp = NULL; in display_init()
494 dp->read_pp = NULL; in display_init()
495 dp->ip = NULL; in display_init()
496 dp->write_pp = NULL; in display_init()
497 dp->min_windowBits = -1; /* this is an OPTIND, so -1 won't match anything */ in display_init()
499 dp->text_ptr = NULL; in display_init()
500 dp->num_text = 0; in display_init()
501 dp->text_stashed = 0; in display_init()
506 display_clean_read(struct display *dp) in display_clean_read() argument
508 if (dp->read_pp != NULL) in display_clean_read()
509 png_destroy_read_struct(&dp->read_pp, NULL, NULL); in display_clean_read()
511 if (dp->fp != NULL) in display_clean_read()
513 FILE *fp = dp->fp; in display_clean_read()
514 dp->fp = NULL; in display_clean_read()
520 display_clean_write(struct display *dp) in display_clean_write() argument
522 if (dp->fp != NULL) in display_clean_write()
524 FILE *fp = dp->fp; in display_clean_write()
525 dp->fp = NULL; in display_clean_write()
529 if (dp->write_pp != NULL) in display_clean_write()
530 png_destroy_write_struct(&dp->write_pp, dp->tsp > 0 ? NULL : &dp->ip); in display_clean_write()
534 display_clean(struct display *dp) in display_clean() argument
536 display_clean_read(dp); in display_clean()
537 display_clean_write(dp); in display_clean()
538 dp->output_file = NULL; in display_clean()
544 if (dp->text_stashed) in display_clean()
546 dp->text_stashed = 0; in display_clean()
547 dp->num_text = 0; in display_clean()
548 free(dp->text_ptr); in display_clean()
549 dp->text_ptr = NULL; in display_clean()
554 dp->results = 0; /* reset for next time */ in display_clean()
558 display_destroy(struct display *dp) in display_destroy() argument
561 display_clean(dp); in display_destroy()
568 struct display *dp = (struct display*)png_get_error_ptr(pp); in get_dp() local
570 if (dp == NULL) in get_dp()
576 return dp; in get_dp()
589 display_log(struct display *dp, error_level level, const char *fmt, ...) in display_log() argument
594 dp->results |= 1U << level; in display_log()
596 if (level > (error_level)(dp->options & LEVEL_MASK)) in display_log()
618 dp->filename != NULL ? dp->filename : "<stdin>", lp, dp->operation); in display_log()
631 if (level > APP_FAIL || (level > ERRORS && !(dp->options & CONTINUE))) in display_log()
633 if (dp->errset) in display_log()
634 longjmp(dp->error_return, level); in display_log()
643 text_stash(struct display *dp) in text_stash() argument
665 dp->num_text = png_get_text(dp->write_pp, dp->ip, &chunks, NULL); in text_stash()
667 if (dp->num_text > 0) in text_stash()
669 dp->text_ptr = voidcast(png_textp, malloc(dp->num_text * sizeof *chunks)); in text_stash()
671 if (dp->text_ptr == NULL) in text_stash()
672 display_log(dp, APP_ERROR, "text chunks: stash malloc failed"); in text_stash()
675 memcpy(dp->text_ptr, chunks, dp->num_text * sizeof *chunks); in text_stash()
678 dp->text_stashed = 1; /* regardless of whether there are chunks or not */ in text_stash()
681 #define text_stash(dp) if (!dp->text_stashed) text_stash(dp) argument
684 text_restore(struct display *dp) in text_restore() argument
687 if (dp->text_ptr != NULL) in text_restore()
688 png_set_text(dp->write_pp, dp->ip, dp->text_ptr, dp->num_text); in text_restore()
691 #define text_restore(dp) if (dp->text_stashed) text_restore(dp) argument
694 #define text_stash(dp) ((void)0) argument
695 #define text_restore(dp) ((void)0) argument
712 option_index(struct display *dp, const char *opt, size_t len) in option_index() argument
727 display_log(dp, dp->errset ? INTERNAL_ERROR : USER_ERROR, in option_index()
733 #define OPTIND(dp, name) option_index(dp, #name, (sizeof #name)-1) argument
736 get_option(struct display *dp, const char *opt, int *value) in get_option() argument
738 const png_byte i = option_index(dp, opt, strlen(opt)); in get_option()
740 if (dp->entry[i]) /* option was set on command line */ in get_option()
742 *value = dp->value[i]; in get_option()
751 set_opt_string_(struct display *dp, unsigned int sp, png_byte opt, in set_opt_string_() argument
758 offset = dp->stack[sp-1].opt_string_end; in set_opt_string_()
761 offset = dp->opt_string_start; in set_opt_string_()
764 add = sprintf(dp->curr+offset, " --%s=%d", options[opt].name, in set_opt_string_()
765 dp->value[opt]); in set_opt_string_()
768 add = sprintf(dp->curr+offset, " --%s=%s", options[opt].name, entry_name); in set_opt_string_()
771 display_log(dp, INTERNAL_ERROR, "sprintf failed"); in set_opt_string_()
773 assert(offset+add < (int)/*SAFE*/sizeof dp->curr); in set_opt_string_()
778 set_opt_string(struct display *dp, unsigned int sp) in set_opt_string() argument
781 dp->stack[sp].opt_string_end = set_opt_string_(dp, sp, dp->stack[sp].opt, in set_opt_string()
782 options[dp->stack[sp].opt].values[dp->stack[sp].entry].name); in set_opt_string()
786 record_opt(struct display *dp, png_byte opt, const char *entry_name) in record_opt() argument
792 const unsigned int sp = dp->csp; /* stack entry of next searched option */ in record_opt()
794 if (sp >= dp->tsp) in record_opt()
800 const int offset = set_opt_string_(dp, sp, opt, entry_name); in record_opt()
803 dp->stack[sp-1].opt_string_end = offset; in record_opt()
806 dp->opt_string_start = offset; in record_opt()
813 opt_list_end(struct display *dp, png_byte opt, png_byte entry) in opt_list_end() argument
818 options[opt].values[entry+1U].value <= dp->value[opt] /* range end */; in opt_list_end()
826 push_opt(struct display *dp, unsigned int sp, png_byte opt, int search) in push_opt() argument
835 assert(sp == dp->tsp && sp < SL); in push_opt()
851 dp->tsp = sp+1U; in push_opt()
852 dp->stack[sp].best_size = in push_opt()
853 dp->stack[sp].lo_size = in push_opt()
854 dp->stack[sp].hi_size = MAX_SIZE; in push_opt()
858 dp->stack[sp].lo = options[opt].values[entry].value; in push_opt()
862 dp->stack[sp].hi = options[opt].values[entry+1].value; in push_opt()
868 dp->stack[sp].lo = INT_MAX; in push_opt()
869 dp->stack[sp].hi = INT_MIN; /* Prevent range chop */ in push_opt()
872 dp->stack[sp].opt = opt; in push_opt()
873 dp->stack[sp].entry = entry; in push_opt()
874 dp->stack[sp].best_val = dp->value[opt] = options[opt].values[entry].value; in push_opt()
876 set_opt_string(dp, sp); in push_opt()
881 if (opt_list_end(dp, opt, entry)) in push_opt()
883 dp->stack[sp].end = 1; in push_opt()
887 if (opt != dp->min_windowBits) in push_opt()
888 display_log(dp, APP_WARNING, "%s: only testing one value", in push_opt()
894 dp->stack[sp].end = 0; in push_opt()
895 dp->nsp = dp->tsp; in push_opt()
902 text_stash(dp); in push_opt()
906 next_opt(struct display *dp, unsigned int sp) in next_opt() argument
919 assert(sp+1U == dp->tsp && !dp->stack[sp].end); in next_opt()
921 opt = dp->stack[sp].opt; in next_opt()
922 entry = dp->stack[sp].entry; in next_opt()
936 if (dp->stack[sp].lo > dp->stack[sp].hi) in next_opt()
937 dp->value[opt]++; in next_opt()
942 png_alloc_size_t best_size = dp->stack[sp].best_size; in next_opt()
943 int lo = dp->stack[sp].lo; in next_opt()
944 int hi = dp->stack[sp].hi; in next_opt()
945 int val = dp->value[opt]; in next_opt()
953 dp->stack[sp].lo_size = best_size; in next_opt()
957 dp->stack[sp].end = 1; in next_opt()
964 dp->stack[sp].hi_size = best_size; in next_opt()
968 dp->stack[sp].end = 1; in next_opt()
975 png_alloc_size_t lo_size = dp->stack[sp].lo_size; in next_opt()
976 png_alloc_size_t hi_size = dp->stack[sp].hi_size; in next_opt()
987 dp->stack[sp].lo = val; in next_opt()
988 dp->stack[sp].lo_size = best_size; in next_opt()
991 lo = dp->stack[sp].lo; in next_opt()
992 lo_size = dp->stack[sp].lo_size; in next_opt()
998 dp->stack[sp].hi = val; in next_opt()
999 dp->stack[sp].hi_size = best_size; in next_opt()
1002 hi = dp->stack[sp].hi; in next_opt()
1003 hi_size = dp->stack[sp].hi_size; in next_opt()
1019 dp->stack[sp].end = 1; in next_opt()
1042 dp->stack[sp].end = 1; in next_opt()
1047 dp->stack[sp].hi = hi = val; in next_opt()
1048 dp->stack[sp].hi_size = best_size; in next_opt()
1062 dp->stack[sp].end = 1; in next_opt()
1067 dp->stack[sp].lo = lo = val; in next_opt()
1068 dp->stack[sp].lo_size = best_size; in next_opt()
1090 dp->stack[sp].hi = val; in next_opt()
1091 dp->stack[sp].hi_size = best_size; in next_opt()
1097 dp->stack[sp].lo = val; in next_opt()
1098 dp->stack[sp].lo_size = best_size; in next_opt()
1107 dp->stack[sp].end = 1; in next_opt()
1111 assert(val != dp->stack[sp].best_val); /* should be a new value */ in next_opt()
1112 dp->value[opt] = val; in next_opt()
1113 dp->stack[sp].best_size = MAX_SIZE; in next_opt()
1120 dp->value[opt] = options[opt].values[++entry].value; in next_opt()
1121 dp->stack[sp].entry = entry; in next_opt()
1124 set_opt_string(dp, sp); in next_opt()
1126 if (!search && opt_list_end(dp, opt, entry)) /* end of list */ in next_opt()
1127 dp->stack[sp].end = 1; in next_opt()
1129 else if (!dp->stack[sp].end) /* still active after all these tests */ in next_opt()
1130 dp->nsp = dp->tsp; in next_opt()
1134 compare_option(const struct display *dp, unsigned int sp) in compare_option() argument
1136 int opt = dp->stack[sp].opt; in compare_option()
1141 if (dp->stack[sp].best_val < dp->value[opt]) in compare_option()
1147 else if (dp->stack[sp].best_val > dp->value[opt]) in compare_option()
1149 if (dp->stack[sp].lo <= dp->stack[sp].hi /*searching*/) in compare_option()
1161 advance_opt(struct display *dp, png_byte opt, int search) in advance_opt() argument
1163 unsigned int sp = dp->csp++; /* my stack entry */ in advance_opt()
1165 assert(sp >= dp->nsp); /* nsp starts off zero */ in advance_opt()
1186 if (sp >= dp->tsp) in advance_opt()
1188 push_opt(dp, sp, opt, search); /* This sets tsp to sp+1 */ in advance_opt()
1201 assert(dp->write_size > 0U && dp->write_size < MAX_SIZE); in advance_opt()
1203 if (dp->stack[sp].best_size > dp->write_size || in advance_opt()
1204 (dp->stack[sp].best_size == dp->write_size && in advance_opt()
1205 compare_option(dp, sp) > 0)) in advance_opt()
1207 dp->stack[sp].best_size = dp->write_size; in advance_opt()
1208 dp->stack[sp].best_val = dp->value[opt]; in advance_opt()
1211 if (sp+1U >= dp->tsp) in advance_opt()
1213 next_opt(dp, sp); in advance_opt()
1217 else if (!dp->stack[sp].end) /* Active, not at top of stack */ in advance_opt()
1218 dp->nsp = sp+1U; in advance_opt()
1225 getallopts_(struct display *dp, const png_byte opt, int *value, int record) in getallopts_() argument
1229 if (dp->entry[opt]) /* option was set on command line */ in getallopts_()
1235 const char *entry_name = options[opt].values[dp->entry[opt]-1].name; in getallopts_()
1238 (void)advance_opt(dp, opt, 0/*do not search; iterate*/); in getallopts_()
1241 record_opt(dp, opt, entry_name); in getallopts_()
1243 *value = dp->value[opt]; in getallopts_()
1252 getallopts(struct display *dp, const char *opt_str, int *value) in getallopts() argument
1254 return getallopts_(dp, option_index(dp, opt_str, strlen(opt_str)), value, 0); in getallopts()
1258 getsearchopts(struct display *dp, const char *opt_str, int *value) in getsearchopts() argument
1262 const png_byte opt = option_index(dp, opt_str, strlen(opt_str)); in getsearchopts()
1269 if (getallopts_(dp, opt, value, record)) in getsearchopts()
1276 istrat = OPTIND(dp, strategy); in getsearchopts()
1280 (void)advance_opt(dp, opt, 0/*iterate*/), record=0; in getsearchopts()
1282 else if (opt == OPTIND(dp, level)) in getsearchopts()
1285 if (dp->value[istrat] == Z_RLE || dp->value[istrat] == Z_HUFFMAN_ONLY) in getsearchopts()
1286 dp->value[opt] = 1; in getsearchopts()
1289 (void)advance_opt(dp, opt, 1/*search*/), record=0; in getsearchopts()
1292 else if (opt == OPTIND(dp, windowBits)) in getsearchopts()
1299 if (dp->value[istrat] == Z_HUFFMAN_ONLY) in getsearchopts()
1300 dp->value[opt] = 8; in getsearchopts()
1302 else if (dp->value[istrat] == Z_RLE) in getsearchopts()
1303 dp->value[opt] = 9; in getsearchopts()
1306 (void)advance_opt(dp, opt, 1/*search*/), record=0; in getsearchopts()
1309 else if (opt == OPTIND(dp, memLevel)) in getsearchopts()
1312 (void)advance_opt(dp, opt, 0/*all*/), record=0; in getsearchopts()
1314 dp->value[opt] = MAX_MEM_LEVEL; in getsearchopts()
1322 record_opt(dp, opt, entry_name); in getsearchopts()
1325 *value = dp->value[opt]; in getsearchopts()
1330 find_val(struct display *dp, png_byte opt, const char *str, size_t len) in find_val() argument
1344 dp->entry[opt] = j; in find_val()
1361 dp->entry[opt] = irange; /* range_lo */ in find_val()
1366 display_log(dp, dp->errset ? INTERNAL_ERROR : USER_ERROR, in find_val()
1373 opt_check(struct display *dp, const char *arg) in opt_check() argument
1375 assert(dp->errset == 0); in opt_check()
1394 j = option_index(dp, arg, i); in opt_check()
1400 dp->entry[j] = (png_byte)/*SAFE*/(negate + 1U); in opt_check()
1413 val = find_val(dp, j, list, strlen(list)); in opt_check()
1422 display_log(dp, USER_ERROR, in opt_check()
1452 v = find_val(dp, j, list, iv); in opt_check()
1468 dp->value[j] = val; in opt_check()
1474 dp->options = (dp->options & ~LEVEL_MASK) | options[j].opt; in opt_check()
1477 display_log(dp, USER_ERROR, in opt_check()
1485 dp->options |= options[j].opt; in opt_check()
1488 dp->options &= ~options[j].opt; in opt_check()
1500 set_timer(struct display *dp, struct timespec *timer) in set_timer() argument
1505 display_log(dp, APP_ERROR, in set_timer()
1507 dp->value[OPTIND(dp,time)] = 0; /* i.e. off */ in set_timer()
1512 start_timer(struct display *dp, int what) in start_timer() argument
1514 if ((dp->value[OPTIND(dp,time)] & what) != 0) in start_timer()
1515 set_timer(dp, what == PNGCP_TIME_READ ? &dp->read_time : &dp->write_time); in start_timer()
1519 end_timer(struct display *dp, int what) in end_timer() argument
1521 if ((dp->value[OPTIND(dp,time)] & what) != 0) in end_timer()
1525 set_timer(dp, &t); in end_timer()
1528 tmp = dp->read_time; in end_timer()
1531 tmp = dp->write_time; in end_timer()
1543 dp->read_time = t, tmp = dp->read_time_total; in end_timer()
1546 dp->write_time = t, tmp = dp->write_time_total; in end_timer()
1558 dp->read_time_total = tmp; in end_timer()
1561 dp->write_time_total = tmp; in end_timer()
1571 #define start_timer(dp, what) ((void)0) argument
1572 #define end_timer(dp, what) ((void)0) argument
1591 isdir(struct display *dp, const char *pathname) in isdir() argument
1611 display_log(dp, USER_ERROR, "%s: cannot be written (%s)", pathname, in isdir()
1621 display_log(dp, USER_ERROR, "%s: invalid output name (%s)", in isdir()
1630 makename(struct display *dp, const char *dir, const char *infile) in makename() argument
1633 dp->namebuf[0] = 0; in makename()
1636 display_log(dp, INTERNAL_ERROR, "NULL name to makename"); in makename()
1642 if (dsize <= (sizeof dp->namebuf)-2) /* Allow for name + '/' + '\0' */ in makename()
1649 display_log(dp, INTERNAL_ERROR, "infile with trailing /"); in makename()
1651 memcpy(dp->namebuf, dir, dsize); in makename()
1652 if (dsize > 0 && dp->namebuf[dsize-1] != '/') in makename()
1653 dp->namebuf[dsize++] = '/'; in makename()
1662 if (dsize+isize < (sizeof dp->namebuf)) /* dsize + infile + '\0' */ in makename()
1664 memcpy(dp->namebuf+dsize, infile, isize+1); in makename()
1666 if (isdir(dp, dp->namebuf)) in makename()
1667 display_log(dp, USER_ERROR, "%s: output file is a directory", in makename()
1668 dp->namebuf); in makename()
1673 dp->namebuf[dsize] = 0; /* allowed for: -2 at start */ in makename()
1674 display_log(dp, USER_ERROR, "%s%s: output file name too long", in makename()
1675 dp->namebuf, infile); in makename()
1680 display_log(dp, USER_ERROR, "%s: output directory name too long", dir); in makename()
1688 struct display *dp = get_dp(pp); in display_warning() local
1691 if (!dp->no_warnings) in display_warning()
1698 struct display *dp = get_dp(pp); in display_error() local
1700 display_log(dp, LIBPNG_ERROR, "%s", error); in display_error()
1704 display_start_read(struct display *dp, const char *filename) in display_start_read() argument
1708 dp->filename = filename; in display_start_read()
1709 dp->fp = fopen(filename, "rb"); in display_start_read()
1714 dp->filename = "<stdin>"; in display_start_read()
1715 dp->fp = stdin; in display_start_read()
1718 dp->w = dp->h = 0U; in display_start_read()
1719 dp->bpp = 0U; in display_start_read()
1720 dp->size = 0U; in display_start_read()
1721 dp->read_size = 0U; in display_start_read()
1723 if (dp->fp == NULL) in display_start_read()
1724 display_log(dp, USER_ERROR, "file open failed (%s)", strerror(errno)); in display_start_read()
1730 struct display *dp = get_dp(pp); in read_function() local
1732 if (size == 0U || fread(data, size, 1U, dp->fp) == 1U) in read_function()
1733 dp->read_size += size; in read_function()
1737 if (feof(dp->fp)) in read_function()
1738 display_log(dp, LIBPNG_ERROR, "PNG file truncated"); in read_function()
1740 display_log(dp, LIBPNG_ERROR, "PNG file read failed (%s)", in read_function()
1746 read_png(struct display *dp, const char *filename) in read_png() argument
1748 display_clean_read(dp); /* safety */ in read_png()
1749 display_start_read(dp, filename); in read_png()
1751 dp->read_pp = png_create_read_struct(PNG_LIBPNG_VER_STRING, dp, in read_png()
1753 if (dp->read_pp == NULL) in read_png()
1754 display_log(dp, LIBPNG_ERROR, "failed to create read struct"); in read_png()
1757 png_set_benign_errors(dp->read_pp, 1/*allowed*/); in read_png()
1761 if ((dp->options & FIX_INDEX) != 0) in read_png()
1762 png_set_check_for_invalid_index(dp->read_pp, 1/*on, no warning*/); in read_png()
1768 if ((dp->options & IGNORE_INDEX) != 0) /* DANGEROUS */ in read_png()
1769 png_set_check_for_invalid_index(dp->read_pp, -1/*off completely*/); in read_png()
1775 dp->ip = png_create_info_struct(dp->read_pp); in read_png()
1776 if (dp->ip == NULL) in read_png()
1777 png_error(dp->read_pp, "failed to create info struct"); in read_png()
1780 png_set_read_fn(dp->read_pp, dp, read_function); in read_png()
1783 png_set_keep_unknown_chunks(dp->read_pp, PNG_HANDLE_CHUNK_ALWAYS, NULL, in read_png()
1789 png_set_user_limits(dp->read_pp, 0x7fffffff, 0x7fffffff); in read_png()
1793 start_timer(dp, PNGCP_TIME_READ); in read_png()
1794 png_read_png(dp->read_pp, dp->ip, 0U/*transforms*/, NULL/*params*/); in read_png()
1795 end_timer(dp, PNGCP_TIME_READ); in read_png()
1796 dp->w = png_get_image_width(dp->read_pp, dp->ip); in read_png()
1797 dp->h = png_get_image_height(dp->read_pp, dp->ip); in read_png()
1798 dp->ct = png_get_color_type(dp->read_pp, dp->ip); in read_png()
1799 dp->bpp = png_get_bit_depth(dp->read_pp, dp->ip) * in read_png()
1800 png_get_channels(dp->read_pp, dp->ip); in read_png()
1806 png_alloc_size_t rb = png_get_rowbytes(dp->read_pp, dp->ip); in read_png()
1809 png_error(dp->read_pp, "invalid row byte count from libpng"); in read_png()
1812 if ((MAX_SIZE-dp->h)/rb < dp->h) in read_png()
1813 png_error(dp->read_pp, "image too large"); in read_png()
1815 dp->size = rb * dp->h + dp->h/*filter byte*/; in read_png()
1819 if (dp->ct == PNG_COLOR_TYPE_PALETTE && (dp->options & FIX_INDEX) != 0) in read_png()
1821 int max = png_get_palette_max(dp->read_pp, dp->ip); in read_png()
1825 if (png_get_PLTE(dp->read_pp, dp->ip, &palette, &num) != PNG_INFO_PLTE in read_png()
1827 display_log(dp, LIBPNG_ERROR, "invalid png_get_PLTE result"); in read_png()
1846 png_set_PLTE(dp->read_pp, dp->ip, newpal, i); in read_png()
1851 display_clean_read(dp); in read_png()
1852 dp->operation = "none"; in read_png()
1856 display_start_write(struct display *dp, const char *filename) in display_start_write() argument
1858 assert(dp->fp == NULL); in display_start_write()
1860 if ((dp->options & NOWRITE) != 0) in display_start_write()
1861 dp->output_file = "<no write>"; in display_start_write()
1867 dp->output_file = filename; in display_start_write()
1868 dp->fp = fopen(filename, "wb"); in display_start_write()
1873 dp->output_file = "<stdout>"; in display_start_write()
1874 dp->fp = stdout; in display_start_write()
1877 if (dp->fp == NULL) in display_start_write()
1878 display_log(dp, USER_ERROR, "%s: file open failed (%s)", in display_start_write()
1879 dp->output_file, strerror(errno)); in display_start_write()
1886 struct display *dp = get_dp(pp); in write_function() local
1891 if (dp->fp == NULL || fwrite(data, size, 1U, dp->fp) == 1U) in write_function()
1893 dp->write_size += size; in write_function()
1894 if (dp->write_size < size || dp->write_size == MAX_SIZE) in write_function()
1899 display_log(dp, USER_ERROR, "%s: PNG file write failed (%s)", in write_function()
1900 dp->output_file, strerror(errno)); in write_function()
1918 search_compression(struct display *dp) in search_compression() argument
1923 # define SET(name, func) if (getsearchopts(dp, #name, &val))\ in search_compression()
1924 png_set_compression_ ## func(dp->write_pp, val); in search_compression()
1930 set_compression(struct display *dp) in set_compression() argument
1934 # define SET(name, func) if (getallopts(dp, #name, &val))\ in set_compression()
1935 png_set_compression_ ## func(dp->write_pp, val); in set_compression()
1942 set_ICC_profile_compression(struct display *dp) in set_ICC_profile_compression() argument
1946 # define SET(name, func) if (getallopts(dp, "ICC-profile-" #name, &val))\ in set_ICC_profile_compression()
1947 png_set_ICC_profile_compression_ ## func(dp->write_pp, val); in set_ICC_profile_compression()
1952 # define set_ICC_profile_compression(dp) ((void)0) argument
1955 # define search_compression(dp) ((void)0) argument
1956 # define set_compression(dp) ((void)0) argument
1957 # define set_ICC_profile_compression(dp) ((void)0) argument
1962 set_text_compression(struct display *dp) in set_text_compression() argument
1966 # define SET(name, func) if (getallopts(dp, "text-" #name, &val))\ in set_text_compression()
1967 png_set_text_compression_ ## func(dp->write_pp, val); in set_text_compression()
1972 # define set_text_compression(dp) ((void)0) argument
1976 write_png(struct display *dp, const char *destname) in write_png() argument
1978 display_clean_write(dp); /* safety */ in write_png()
1979 display_start_write(dp, destname); in write_png()
1981 dp->write_pp = png_create_write_struct(PNG_LIBPNG_VER_STRING, dp, in write_png()
1984 if (dp->write_pp == NULL) in write_png()
1985 display_log(dp, LIBPNG_ERROR, "failed to create write png_struct"); in write_png()
1988 png_set_benign_errors(dp->write_pp, 1/*allowed*/); in write_png()
1991 png_set_write_fn(dp->write_pp, dp, write_function, NULL/*flush*/); in write_png()
1994 if ((dp->options & IGNORE_INDEX) != 0) /* DANGEROUS */ in write_png()
1995 png_set_check_for_invalid_index(dp->write_pp, -1/*off completely*/); in write_png()
2002 text_restore(dp); in write_png()
2005 png_set_keep_unknown_chunks(dp->write_pp, PNG_HANDLE_CHUNK_ALWAYS, NULL, in write_png()
2011 png_set_user_limits(dp->write_pp, 0x7fffffff, 0x7fffffff); in write_png()
2016 dp->tsp = dp->nsp; in write_png()
2017 dp->nsp = dp->csp = 0; in write_png()
2025 if (getallopts(dp, "compression", &val)) in write_png()
2026 png_set_compression(dp->write_pp, val); in write_png()
2028 if (getallopts(dp, "ICC-profile-compression", &val)) in write_png()
2029 png_set_ICC_profile_compression(dp->write_pp, val); in write_png()
2031 if (getallopts(dp, "text-compression", &val)) in write_png()
2032 png_set_text_compression(dp->write_pp, val); in write_png()
2035 if (dp->options & SEARCH) in write_png()
2036 search_compression(dp); in write_png()
2038 set_compression(dp); in write_png()
2039 set_ICC_profile_compression(dp); in write_png()
2040 set_text_compression(dp); in write_png()
2046 if (get_option(dp, "IDAT-size", &val)) in write_png()
2047 png_set_IDAT_size(dp->write_pp, val); in write_png()
2055 if (get_option(dp, "filter", &val)) in write_png()
2056 png_set_filter(dp->write_pp, PNG_FILTER_TYPE_BASE, val); in write_png()
2061 dp->write_size = 0U; in write_png()
2062 start_timer(dp, PNGCP_TIME_WRITE); in write_png()
2063 png_write_png(dp->write_pp, dp->ip, 0U/*transforms*/, NULL/*params*/); in write_png()
2064 end_timer(dp, PNGCP_TIME_WRITE); in write_png()
2067 if (dp->fp != NULL) in write_png()
2069 FILE *fp = dp->fp; in write_png()
2070 dp->fp = NULL; in write_png()
2072 display_log(dp, APP_ERROR, "%s: write failed (%s)", in write_png()
2079 display_clean_write(dp); in write_png()
2080 dp->operation = "none"; in write_png()
2084 set_windowBits_hi(struct display *dp) in set_windowBits_hi() argument
2092 while (wb > 8 && dp->size <= 1U<<(wb-1)) --wb; in set_windowBits_hi()
2107 dp->min_windowBits = OPTIND(dp, windowBits); in set_windowBits_hi()
2111 better_options(const struct display *dp) in better_options() argument
2129 for (sp=0; sp<dp->csp; ++sp) in better_options()
2131 int c = compare_option(dp, sp); in better_options()
2144 print_search_results(struct display *dp) in print_search_results() argument
2146 assert(dp->filename != NULL); in print_search_results()
2148 dp->filename, (unsigned long)dp->w, (unsigned long)dp->h, dp->bpp, in print_search_results()
2149 cts(dp->ct), (unsigned long)dp->size, (unsigned long)dp->read_size, in print_search_results()
2150 (unsigned long)dp->best_size, dp->best); in print_search_results()
2155 log_search(struct display *dp, unsigned int log_depth) in log_search() argument
2158 if (dp->nsp/*next entry to change*/ <= log_depth) in log_search()
2160 print_search_results(dp); in log_search()
2162 dp->best_size = MAX_SIZE; in log_search()
2167 cp_one_file(struct display *dp, const char *filename, const char *destname) in cp_one_file() argument
2171 dp->filename = filename; in cp_one_file()
2172 dp->operation = "read"; in cp_one_file()
2173 dp->no_warnings = 0; in cp_one_file()
2177 display_log(dp, USER_ERROR, "%s: invalid file name (%s)", in cp_one_file()
2180 read_png(dp, filename); in cp_one_file()
2183 dp->operation = "write"; in cp_one_file()
2186 set_windowBits_hi(dp); in cp_one_file()
2192 if (get_option(dp, "log-depth", &val) && val >= 0) in cp_one_file()
2201 if (isdir(dp, destname)) in cp_one_file()
2203 makename(dp, destname, filename); in cp_one_file()
2204 destname = dp->namebuf; in cp_one_file()
2208 display_log(dp, USER_ERROR, "%s: invalid output name (%s)", destname, in cp_one_file()
2212 dp->nsp = 0; in cp_one_file()
2213 dp->curr[0] = 0; /* acts as a flag for the caller */ in cp_one_file()
2214 dp->opt_string_start = 0; in cp_one_file()
2215 dp->best[0] = 0; /* safety */ in cp_one_file()
2216 dp->best_size = MAX_SIZE; in cp_one_file()
2217 write_png(dp, destname); in cp_one_file()
2220 strcpy(dp->best, dp->curr); in cp_one_file()
2221 dp->best_size = dp->write_size; in cp_one_file()
2223 if (dp->nsp > 0) /* interating over lists */ in cp_one_file()
2225 char *tmpname, tmpbuf[(sizeof dp->namebuf) + 4]; in cp_one_file()
2226 assert(dp->curr[0] == ' ' && dp->tsp > 0); in cp_one_file()
2229 log_search(dp, log_depth); in cp_one_file()
2230 dp->no_warnings = 1; in cp_one_file()
2246 write_png(dp, tmpname); in cp_one_file()
2251 assert(dp->csp > 0); in cp_one_file()
2253 if (dp->write_size < dp->best_size || in cp_one_file()
2254 (dp->write_size == dp->best_size && better_options(dp))) in cp_one_file()
2257 display_log(dp, APP_ERROR, "rename %s %s failed (%s)", tmpname, in cp_one_file()
2260 strcpy(dp->best, dp->curr); in cp_one_file()
2261 dp->best_size = dp->write_size; in cp_one_file()
2265 display_log(dp, APP_WARNING, "unlink %s failed (%s)", tmpname, in cp_one_file()
2268 log_search(dp, log_depth); in cp_one_file()
2270 while (dp->nsp > 0); in cp_one_file()
2273 dp->write_size = dp->best_size; in cp_one_file()
2278 cppng(struct display *dp, const char *file, const char *gv dest) in cppng() argument
2283 int ret = setjmp(dp->error_return); in cppng()
2287 dp->errset = 1; in cppng()
2288 cp_one_file(dp, file, dest); in cppng()
2289 dp->errset = 0; in cppng()
2295 dp->errset = 0; in cppng()
2298 display_log(dp, INTERNAL_ERROR, "unexpected return code %d", ret); in cppng()