cdew / ccr-exif

Automatically exported from code.google.com/p/ccr-exif
0 stars 0 forks source link

Resolution is not read for attached JPEG image #5

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Load attached JPEG and read resolution

What is the expected output? What do you see instead?

resolution should be 300 dpi (Windows properties/details shows these values)

What version of the product are you using? On what operating system?
Latest SVN resion

Please provide any additional information below.

Original issue reported on code.google.com by dirk.car...@gmail.com on 4 Nov 2013 at 9:01

Attachments:

GoogleCodeExporter commented 9 years ago
Hi Chris, 
it's been a while, now i found a way to read DPI from image. 

In App13 marker there is the Photoshop resolution tag, see 
http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Photoshop.html

This is my code:

    AStream.Seek(0, soFromBeginning);
    for Segment in JPEGHeader(AStream) do
      case Segment.MarkerNum of
        ..
        jmApp13:
          begin
            AdobeEnumerator:= Segment.GetEnumerator;
            while Assigned(AdobeEnumerator) and AdobeEnumerator.MoveNext do
              begin
                AdobeResourceBlock:= AdobeEnumerator.Current;
                // $3ED is Photoshop resolution tag, see http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Photoshop.html
                if (AdobeResourceBlock.Signature = '8BIM') and (AdobeResourceBlock.TypeID = $3ED) then
                  begin
                    ResolutionStream:= AdobeResourceBlock.Data;
                    if Assigned(ResolutionStream) and (ResolutionStream.Size >= 14) then
                      begin
                        ResolutionStream.Position:= 0;
                        ResolutionStream.Read(XRes, SizeOf(Integer));
                        XRes:= Swap(XRes);
                        ResolutionStream.Read(ResolutionUnit, SizeOf(Word));
                        ResolutionUnit:= Swap(ResolutionUnit);
                        // 1 = inch, 2 = cm
                        if ResolutionUnit = 2 then
                          XRes:= Round(XRes * 2.54);
                        // 2 Bytes padding?
                        ResolutionStream.Position:= ResolutionStream.Position + 2;
                        ResolutionStream.Read(YRes, SizeOf(Integer));
                        YRes:= Swap(YRes);
                        ResolutionStream.Read(ResolutionUnit, SizeOf(Word));
                        ResolutionUnit:= Swap(ResolutionUnit);
                        // 1 = inch, 2 = cm
                        if ResolutionUnit = 2 then
                          YRes:= Round(YRes * 2.54);
                      end;
                  end;
              end;
          end; // end case

Maybe there is a better way like wrapping up in class? Is it possible that you 
integrate it into CCR.EXIF classes?

Thanks and best regards
Dirk Carstensen

Original comment by dirk.car...@gmail.com on 27 May 2014 at 2:25