]> git.sesse.net Git - pr0n/blobdiff - perl/Sesse/pr0n/Common.pm
Keep JPEGs in the YCbCr colorspace instead of going between YCbCr and RGB
[pr0n] / perl / Sesse / pr0n / Common.pm
index 987463548ed3c19d79104891111b67e9874f1eef..000b3511464291baa52f76c35195bdd6b58da21b 100644 (file)
@@ -401,6 +401,11 @@ 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. (Ideally we'd be able to keep the image subsampled and
+                       # planar, but that would probably be difficult for ImageMagick to expose.)
+                       $magick->Set(colorspace=>'YCbCr');
                        $err = $magick->Read($fname);
                }
                
@@ -425,11 +430,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);
@@ -557,12 +557,16 @@ sub make_infobox {
 
 #      Apache2::ServerUtil->server->log_error(join(':', keys %$info));
 
+       my $iso = undef;
        if (defined($info->{'NikonD1-ISOSetting'})) {
-               push @classic_fields, [ $info->{'NikonD1-ISOSetting'}->[1] . " ISO", 0 ];
-       } elsif (defined($info->{'ISOSetting'})) {
-               push @classic_fields, [ $info->{'ISOSetting'} . " ISO" ];
+               $iso = $info->{'NikonD1-ISOSetting'};
        } elsif (defined($info->{'ISO'})) {
-               push @classic_fields, [ $info->{'ISO'} . " ISO" ];
+               $iso = $info->{'ISO'};
+       } elsif (defined($info->{'ISOSetting'})) {
+               $iso = $info->{'ISOSetting'};
+       }
+       if (defined($iso) && $iso =~ /(\d+)/) {
+               push @classic_fields, [ $1 . " ISO", 0 ];
        }
 
        if (defined($info->{'ExposureBiasValue'}) && $info->{'ExposureBiasValue'} ne "0") {