Author Topic: What about XMP inside TIFF???  (Read 2147 times)

Offline jcarlos

  • Imaging User
  • *
  • Posts: 7
    • View Profile
What about XMP inside TIFF???
« on: 30 January 2009, 15:35:50 »
Hi.
Some body are thinking about include XMP label inside the Image .tiff????
Best Regard.
JCarlos

Offline Galfar

  • Administrator
  • Imaging User
  • *****
  • Posts: 312
    • View Profile
    • Galfar's Homepage
Re: What about XMP inside TIFF???
« Reply #1 on: 31 January 2009, 13:47:35 »
Hi, do you have some info about XMP labels? A link?

Offline jcarlos

  • Imaging User
  • *
  • Posts: 7
    • View Profile
Re: What about XMP inside TIFF???
« Reply #2 on: 2 February 2009, 17:47:41 »
Hi.
I have a PDF file with description about how use the XML packet in order to insert it inside the several image file. Include Tiff file.
If you wish I can send it to you.
JCarlos

Offline Galfar

  • Administrator
  • Imaging User
  • *****
  • Posts: 312
    • View Profile
    • Galfar's Homepage
Re: What about XMP inside TIFF???
« Reply #3 on: 9 February 2009, 13:48:18 »
Ok send it please, I'll have a look.
But it mainly depends on whether LibTiff which Imaging uses can load/save these into files.

Offline jcarlos

  • Imaging User
  • *
  • Posts: 7
    • View Profile
Re: What about XMP inside TIFF???
« Reply #4 on: 11 February 2009, 00:04:55 »
XMP Specification Part1

Offline jcarlos

  • Imaging User
  • *
  • Posts: 7
    • View Profile
Re: What about XMP inside TIFF???
« Reply #5 on: 11 February 2009, 00:10:33 »
XMP Specification Part2

Offline jcarlos

  • Imaging User
  • *
  • Posts: 7
    • View Profile
Re: What about XMP inside TIFF???
« Reply #6 on: 11 February 2009, 00:12:28 »
XMP Specification Part3

Offline jcarlos

  • Imaging User
  • *
  • Posts: 7
    • View Profile
Re: What about XMP inside TIFF???
« Reply #7 on: 11 February 2009, 00:15:40 »
We make a function to insert a XMP file inside a tiff file.
This function work very good, But we think that this function is not a good example of profesional code. :=))
We was trying to use the libtiff, but we have not good documentation about libtiff library and finally we don't use the funtion of libtiff for it.
May be we can colaborate with you in order add the functionality of insert XMP inside the image to several image file type.


Well the example code is the following.
The main function is:
Bmp2Tiff(pSource:String; pTarget: string);//pTarget, and pSource must be the path and file name of image tiff file. For example: "C:\IMG_In.tif"   and "C:\IMG_Out.tif"
 
 

Code: Delphi
  1. uses
  2. ImagingTypes,
  3.   Imaging,
  4.   ImagingClasses,
  5.   LibTiffDelphi;
  6. :
  7. :
  8. :
  9.  
  10. //---------------------------------------
  11. Function OpenFile(const FileName: string;  Var pFImage: TMultiImage) : Boolean;
  12. begin
  13.   result := true;
  14.   try
  15.     pFImage.LoadMultiFromFile(FileName);
  16.   except
  17.     result := false;
  18.     Exit;
  19.   end;
  20.   pFImage.ActiveImage := pFImage.ActiveImage + 1;
  21. end;
  22.  
  23.  
  24. //-------------------------------
  25. Function SaveFile(const FileName: string; Var pFImage: TMultiImage): Boolean;
  26. begin
  27.   result := true;
  28.   try
  29.     pFImage.SaveMultiToFile(FileName);
  30.   except
  31.     result := false;
  32.   end;
  33. end;
  34.  
  35.  
  36. //-----------------------------------
  37. procedure Bmp2Tiff(pSource:String; pTarget: string);
  38.     {$R-}
  39.     {$RANGECHECKS OFF}
  40.  
  41.  
  42. var
  43.     XMP_Size, XMP_Offset: cardinal;
  44.     Texto: string;
  45.  
  46.     FImage: TMultiImage;
  47.  
  48.     F: TFileStream;
  49.     OffSetInicioDelDirectorio, NewDirOffset : LongWord;
  50.     NumeroDeEntradasEnElDirectorio : Word;
  51.  
  52.    // Entry: TDirEntry;
  53.     DirArray : array [0..30] of TDirEntry;
  54.     i : Integer;
  55.  begin
  56.  
  57.  
  58.  
  59. Texto := GetXMPString(); //This function get the XMP String. In this funciton you can Check if the String is a Valid XMP. But you can insert into the Tiff whatever String text. The string Text can be or not can be a valid XMP. The image viewer  program like Gimp, Photoshop, etc, no make a check about it.
  60.  
  61.     //******************************
  62.     FImage := TMultiImage.Create;
  63.  
  64.     try
  65.      OpenFile(pSource, FImage);
  66.      SaveFile(pTarget, FImage);
  67.  
  68.     finally
  69.       FImage.Free;
  70.     end;
  71.  
  72.     XMP_Size := Length(Texto);
  73.     AddStrToFile(Texto, pTarget);
  74.     XMP_Offset := cuantosbytes(pTarget) -  XMP_Size;
  75.  
  76.  
  77.     F := TFileStream.Create(pTarget, fmOpenRead);
  78.  
  79.     try
  80.       F.Seek(4, soFromBeginning);
  81.  
  82.       F.Read(OffSetInicioDelDirectorio, SizeOf(OffSetInicioDelDirectorio));
  83.       F.Seek(OffSetInicioDelDirectorio, soFromBeginning);
  84.       F.Read(NumeroDeEntradasEnElDirectorio, SizeOf(NumeroDeEntradasEnElDirectorio));
  85.  
  86.       OffSetInicioDelDirectorio := OffSetInicioDelDirectorio + SizeOf(NumeroDeEntradasEnElDirectorio);
  87.  
  88.  
  89.       FillChar(DirArray,  30 * SizeOf(TDirEntry),  0);
  90.       F.Read(DirArray, NumeroDeEntradasEnElDirectorio * SizeOf(TDirEntry));
  91.  
  92.       DirArray[NumeroDeEntradasEnElDirectorio]._Tag     := TIFFTAG_XMLPACKET;
  93.       DirArray[NumeroDeEntradasEnElDirectorio]._Type    := 1;
  94.       DirArray[NumeroDeEntradasEnElDirectorio]._Count   := XMP_Size;
  95.       DirArray[NumeroDeEntradasEnElDirectorio]._Value   := XMP_Offset;
  96.     finally
  97.      F.Free;
  98.     end;
  99.  
  100.     NewDirOffset := cuantosbytes(pTarget);
  101.     F := TFileStream.Create(pTarget, fmOpenWrite);
  102.  
  103.     try
  104.       F.Seek(4, soFromBeginning);
  105.  
  106.       F.Write(NewDirOffset, SizeOf(NewDirOffset));
  107.  
  108.       F.Seek(NewDirOffset, soFromBeginning);
  109.  
  110.       Inc(NumeroDeEntradasEnElDirectorio);
  111.       F.Write(NumeroDeEntradasEnElDirectorio, SizeOf(NumeroDeEntradasEnElDirectorio));
  112.  
  113.       for i := 0 to NumeroDeEntradasEnElDirectorio +1  do
  114.        Begin
  115.         F.Write(DirArray[i], SizeOf(TDirEntry));
  116.        End;
  117.  
  118.      finally
  119.       F.Free;
  120.      End;
  121.  end;  //procedure Bmp2TiffJC(pSource:String; pTarget: string);
  122.  
  123. //*********************************************************** //Fin Funcion
Best Regard
JCarlos
« Last Edit: 28 July 2011, 15:21:28 by Galfar »

Offline Galfar

  • Administrator
  • Imaging User
  • *****
  • Posts: 312
    • View Profile
    • Galfar's Homepage
Re: What about XMP inside TIFF???
« Reply #8 on: 3 March 2009, 02:19:28 »
I've looked at the specification you uploaded.
Adding XMP packets to image formats that are saved using native
Imaging code (like PNG, GIF, and PSD) won't be difficult.
Formats that use 3rd party libraries (like JPEG, JPEG 2000, TIFF) would
be problematic if the libs don't support XMP out of the box.

I'm thinking of adding XMP support to Imaging 0.3x branch where
each image has optional metadata information so managing
XMP on per-image basis could be easy
(like Image.Properties.XMPString := XMLDataString).

Anyway, thanks for the code.