]> git.sesse.net Git - pr0n/blobdiff - perl/Sesse/pr0n/Common.pm
Don't use YCbCr if we need to draw an info box; ImageMagick is too broken
[pr0n] / perl / Sesse / pr0n / Common.pm
index e339fd3ab596026f33390cdefa97579ecce2a249..8ae68396e4c7795a4f412cbff55a5106783f47e6 100644 (file)
@@ -401,6 +401,15 @@ sub ensure_cached {
                        $err = $magick->Read(file => \*DCRAW);
                        close(DCRAW);
                } else {
+                       # We always want YCbCr JPEGs. Setting this explicitly here instead of using
+                       # RGB is slightly faster (no colorspace conversion needed) and works equally
+                       # well for our uses, as long as we don't need to draw an information box,
+                       # which trickles several ImageMagick bugs related to colorspace handling.
+                       # (Ideally we'd be able to keep the image subsampled and
+                       # planar, but that would probably be difficult for ImageMagick to expose.)
+                       if (!$infobox) {
+                               $magick->Set(colorspace=>'YCbCr');
+                       }
                        $err = $magick->Read($fname);
                }
                
@@ -425,11 +434,6 @@ sub ensure_cached {
                        update_image_info($r, $id, $width, $height);
                }
                        
-               # We always want RGB JPEGs
-               if ($img->Get('Colorspace') eq "CMYK") {
-                       $img->Set(colorspace=>'RGB');
-               }
-
                while (defined($xres) && defined($yres)) {
                        my ($nxres, $nyres) = (shift @otherres, shift @otherres);
                        my $cachename = get_cache_location($r, $id, $xres, $yres, $infobox);