Skip to content

Instantly share code, notes, and snippets.

@tangentsoft
Last active August 29, 2015 14:17
Show Gist options
  • Save tangentsoft/57ce984f768e77bacb30 to your computer and use it in GitHub Desktop.
Save tangentsoft/57ce984f768e77bacb30 to your computer and use it in GitHub Desktop.
A wild hack at making [jpegtran](http://jpegclub.org/jpegtran/) white-pad images when extending them, instead of using middle gray
--- transupp.c.orig 2015-03-16 11:34:25.000000000 -0600
+++ transupp.c 2015-03-16 11:39:12.000000000 -0600
@@ -130,6 +130,9 @@
JBLOCKARRAY src_buffer, dst_buffer;
jpeg_component_info *compptr;
+ JCOEF pad = 1023; /* max for 8-bit JPEG = white; use 16383 for 12-bit JPEG */
+ int pio, pii; /* padding indices for custom FMEMZERO() replacments */
+
MCU_cols = srcinfo->output_width /
(dstinfo->max_h_samp_factor * dstinfo->min_DCT_h_scaled_size);
MCU_rows = srcinfo->output_height /
@@ -150,8 +153,11 @@
if (dst_blk_y < y_crop_blocks ||
dst_blk_y >= comp_height + y_crop_blocks) {
for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
- FMEMZERO(dst_buffer[offset_y],
- compptr->width_in_blocks * SIZEOF(JBLOCK));
+ for (pio = 0; pio < compptr->width_in_blocks; ++pio) {
+ for (pii = 0; pio < SIZEOF(JBLOCK); ++pii) {
+ dst_buffer[offset_y][pio][pii] = pad;
+ }
+ }
}
continue;
}
@@ -168,17 +174,22 @@
for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
if (dstinfo->jpeg_width > srcinfo->output_width) {
if (x_crop_blocks > 0) {
- FMEMZERO(dst_buffer[offset_y],
- x_crop_blocks * SIZEOF(JBLOCK));
+ for (pio = 0; pio < x_crop_blocks; ++pio) {
+ for (pii = 0; pio < SIZEOF(JBLOCK); ++pii) {
+ dst_buffer[offset_y][pio][pii] = pad;
+ }
+ }
}
jcopy_block_row(src_buffer[offset_y],
dst_buffer[offset_y] + x_crop_blocks,
comp_width);
if (compptr->width_in_blocks > comp_width + x_crop_blocks) {
- FMEMZERO(dst_buffer[offset_y] +
- comp_width + x_crop_blocks,
- (compptr->width_in_blocks -
- comp_width - x_crop_blocks) * SIZEOF(JBLOCK));
+ int count = compptr->width_in_blocks - comp_width - x_crop_blocks;
+ for (pio = 0; pio < count; ++pio) {
+ for (pii = 0; pio < SIZEOF(JBLOCK); ++pii) {
+ dst_buffer[offset_y][pio + comp_width + x_crop_blocks][pii] = pad;
+ }
+ }
}
} else {
jcopy_block_row(src_buffer[offset_y] + x_crop_blocks,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment