ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: areohbee on September 27, 2011, 09:47:58 PM

Title: jpgFromRaw
Post by: areohbee on September 27, 2011, 09:47:58 PM
-jpgFromRaw works great most of the time, but about 10% of the time, for at least one user's Nikon D80 shots, the extracted jpeg is small, dark, and dull (not correct). I can post a raw if anyone wants.

I'm working around the problem now by using dcraw for the extractions and exiftool for everything else, but I'd like to go back to an "all exiftool" solution, as soon as possible.

Please advise...

Rob


Title: Re: jpgFromRaw
Post by: Phil Harvey on September 28, 2011, 07:09:05 AM
Hi Rob,

If you can email me the NEF image or post a URL here I'll take a look.  My email is philharvey66 at gmail.com

- Phil
Title: Re: jpgFromRaw
Post by: areohbee on September 28, 2011, 08:21:01 AM
Thanks Phil - an 18MB zipped NEF is on its way via email - hope it makes it...
Title: Re: jpgFromRaw
Post by: Phil Harvey on September 28, 2011, 09:02:07 AM
I got the NEF, thanks.

This NEF has been modified by Nikon Capture NX.  For some reason, it looks like this software stores a smaller, dimmer JPEG in place of the JpgFromRaw.  But it adds another image to the NEF which is bigger and brighter -- ExifTool extracts this as OtherImage.  I will look at this in more detail to figure out if there is a way I can recognize when this is happening, but for now you could just extract the OtherImage if it is available.

- Phil
Title: Re: jpgFromRaw
Post by: Phil Harvey on September 28, 2011, 10:13:37 AM
I took closer look at this.  Unfortunately the current behaviour is difficult to change.  So checking for the existence of the OtherImage in NEF files is the way to go.

- Phil
Title: Re: jpgFromRaw
Post by: areohbee on September 28, 2011, 05:05:44 PM
Thank you so much Phil - I really appreciate it!  :)
Rob
Title: Re: jpgFromRaw
Post by: Phil Harvey on September 29, 2011, 07:37:06 AM
Hi Rob,

I just checked a number of NEF samples.  In some, the PreviewImage is the largest embedded JPEG.  Here is a config file that may make this easier for you -- it extracts the largest JPEG image as BigImage:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        # [advanced] select largest JPEG preview image
        BigImage => {
            Desire => {
                0 => 'JpgFromRaw',
                1 => 'PreviewImage',
                2 => 'OtherImage',
                # (DNG and A100 ARW may be have 2 PreviewImage's)
                3 => 'PreviewImage (1)',
            },
            # ValueConv code reference
            # Inputs: 0) reference to list of values, 1) ExifTool object
            ValueConv => sub {
                my $val = shift;
                my ($image, $bigImage, $len, $bigLen);
                foreach $image (@$val) {
                    next unless ref $image eq 'SCALAR';
                    # check for JPEG image (or binary data if -b not used)
                    next unless $$image =~ /^(\xff\xd8\xff|Binary data (\d+))/;
                    $len = $2 || length $$image; # get image length
                    # save largest image
                    next if defined $bigLen and $bigLen >= $len;
                    $bigLen = $len;
                    $bigImage = $image;
                }
                return $bigImage;
            },
        },
    },
);
1; #end


- Phil

Edit: Added ability to handle 2 PreviewImage's
Title: Re: jpgFromRaw
Post by: areohbee on September 29, 2011, 09:19:39 AM
Works perfectly! - thanks again Phil.
Rob