d2520682cc7cac8838925cf1c9f7d9159a82df92 braney Sun Aug 16 10:44:02 2026 -0700 pngwrite: replace leftover experiment marker with a real comment, refs #38107 The png_set_filter call in 443dc863b48 kept a scratch comment that said "EXPERIMENT ONLY, refs #38094 - do not commit". The code is correct and intended, and the justification is #38107, not #38094. Comment only, no code change. diff --git src/lib/pngwrite.c src/lib/pngwrite.c index d49d508ce46..10d52e7ec28 100644 --- src/lib/pngwrite.c +++ src/lib/pngwrite.c @@ -50,31 +50,34 @@ // But that should not happen because png_error should call pngAbort which calls errAbort. if (setjmp(png_jmpbuf(png))) { png_destroy_write_struct(&png, &info); fclose(png_file); errAbort("pngwrite: setjmp nonzero. " "why didn't png_error..pngAbort..errAbort stop execution before this errAbort?"); return FALSE; } // Configure PNG output params: png_init_io(png, png_file); png_set_IHDR(png, info, mg->width, mg->height, 8, // 8=bit_depth PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); -// EXPERIMENT ONLY, refs #38094 - do not commit +// Pin the row filter to UP instead of letting libpng try all five filters on +// every row. UP was picked by measuring speed and output size on real browser +// images (refs #38107). A row filter is a lossless per-row transform, so the +// decoded image is unchanged. png_set_filter(png, PNG_FILTER_TYPE_BASE, PNG_FILTER_UP); // Write header/params, write pixels, close and clean up. // PNG wants a 2D array of pointers to byte offsets into palette/colorMap. // mg has a 1D array of byte offsets. Make row pointers for PNG: png_byte **row_pointers = needMem(mg->height * sizeof(png_byte *)); int i; for (i = 0; i < mg->height; i++) row_pointers[i] = (unsigned char *)&(mg->pixels[i*mg->width]); png_set_rows(png, info, row_pointers); png_write_png(png, info, PNG_TRANSFORM_IDENTITY, // no transform NULL); // unused as of PNG 1.2 png_destroy_write_struct(&png, &info); return TRUE;