-
-
Notifications
You must be signed in to change notification settings - Fork 649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add force subsample argument to JPEG save #1552
Conversation
Merge from main
Merge master
Hello @Elad-Laufer, We already have |
If there's a plan to offer more fine-grained control over subsampling, perhaps we should consider allowing 4:2:2 as well as 4:4:4 ("no-subsample") and 4:2:0 ("force-subsample")? |
I looked into this when we added http://poynton.ca/PDFs/Chroma_subsampling_notation.pdf edit: of course there are CMYK JPG too, but they never have subsampled K, so the full set of chroma subsample settings are: 4:2:0:4 |
(or that's my understanding from that useful PDF) |
@jcupitt Thanks for the info, no worries, let's keep this as simple as possible. |
…EIGN_JPEG_SUBSAMPLE_OFF when no_subsample=1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks great! Thank you very much for doing this work.
I think we should deprecate no_subsample
, otherwise it's just nitpicks.
libvips/foreign/jpegsave.c
Outdated
@@ -230,7 +241,7 @@ vips_foreign_save_jpeg_target_build( VipsObject *object ) | |||
jpeg->Q, jpeg->profile, jpeg->optimize_coding, | |||
jpeg->interlace, save->strip, jpeg->no_subsample, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not pass no_subsample. Instead, a little higher up, have something like:
if arg-set("no_subsample") && !arg_set("subsample_mode")
subsample_mode = no_subsample ? OFF : ON
ie. old code using the no_subsample
arg is able to set the default for the new subsample_mode
value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I add the check to each _build(...)
function? currently I only check once at vips__jpeg_write_target(...)
.
Is there a way to perform the check in single point without code duplication?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, add a build method to the base class for jpegsave and do the test after chaining up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tiffsave has something a little like this:
https://github.com/libvips/libvips/blob/master/libvips/foreign/tiffsave.c#L153
A _build
method on the base class and use of isset
to set defaults.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
libvips/foreign/jpegsave.c
Outdated
@@ -297,7 +307,7 @@ vips_foreign_save_jpeg_file_build( VipsObject *object ) | |||
jpeg->Q, jpeg->profile, jpeg->optimize_coding, | |||
jpeg->interlace, save->strip, jpeg->no_subsample, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, remove no_subsample
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
libvips/foreign/jpegsave.c
Outdated
@@ -367,7 +377,7 @@ vips_foreign_save_jpeg_buffer_build( VipsObject *object ) | |||
jpeg->Q, jpeg->profile, jpeg->optimize_coding, | |||
jpeg->interlace, save->strip, jpeg->no_subsample, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove 'no_subsample`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
libvips/foreign/jpegsave.c
Outdated
@@ -440,7 +450,7 @@ vips_foreign_save_jpeg_mime_build( VipsObject *object ) | |||
jpeg->Q, jpeg->profile, jpeg->optimize_coding, | |||
jpeg->interlace, save->strip, jpeg->no_subsample, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
libvips/foreign/vips2jpeg.c
Outdated
break; | ||
case VIPS_FOREIGN_JPEG_SUBSAMPLE_AUTO: | ||
/* Turn off chroma subsampling. Follow IM and do it automatically for | ||
* high Q. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Asterisks should line up.
/* Like
* this.
*/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
libvips/foreign/vips2jpeg.c
Outdated
break; | ||
} | ||
case VIPS_FOREIGN_JPEG_SUBSAMPLE_OFF: | ||
default: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Newline before {
, like a func definition, and for
formatted as:
for( i = 0; i < xxx; i++ ) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
libvips/foreign/vips2jpeg.c
Outdated
if( no_subsample ) { | ||
subsample_mode = VIPS_FOREIGN_JPEG_SUBSAMPLE_OFF; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This if()
can go if we have the extra logic in _build()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
test/test-suite/test_foreign.py
Outdated
|
||
# higher Q should mean a bigger buffer | ||
q10 = im.jpegsave_buffer(Q=10) | ||
q10_subsample_off = im.jpegsave_buffer(Q=10, subsample_mode=2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use the string value here, ie. "off"
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
test/test-suite/test_foreign.py
Outdated
# higher Q should mean a bigger buffer | ||
q10 = im.jpegsave_buffer(Q=10) | ||
q10_subsample_off = im.jpegsave_buffer(Q=10, subsample_mode=2) | ||
q10_subsample_no = im.jpegsave_buffer(Q=10, no_subsample=1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should have deprecated API being tested in the test suite, let's remove this.
Same for the case below. Just test on
, off
, auto
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look great! Thanks again, I'll merge.
fix up some formatting from #1552 plus some other small changes
I revised the formatting slightly and added some docs. |
If Q >= 90 then subsampling is disabled, this argument forces it