• Welcome to Vampyre Imaging Library Forum. Please login or sign up.
 

What about XMP inside TIFF???

Started by jcarlos, 30 January 2009, 15:35:50

Previous topic - Next topic

jcarlos

Hi.
Some body are thinking about include XMP label inside the Image .tiff????
Best Regard.
JCarlos

Galfar

Hi, do you have some info about XMP labels? A link?

jcarlos

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

Galfar

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.

jcarlos


jcarlos


jcarlos


jcarlos

11 February 2009, 00:15:40 #7 Last Edit: 28 July 2011, 15:21:28 by Galfar
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) Select
uses
ImagingTypes,
  Imaging,
  ImagingClasses,
  LibTiffDelphi;
:
:
:

//---------------------------------------
Function OpenFile(const FileName: string;  Var pFImage: TMultiImage) : Boolean;
begin
  result := true;
  try
    pFImage.LoadMultiFromFile(FileName);
  except
    result := false;
    Exit;
  end;
  pFImage.ActiveImage := pFImage.ActiveImage + 1;
end;


//-------------------------------
Function SaveFile(const FileName: string; Var pFImage: TMultiImage): Boolean;
begin
  result := true;
  try
    pFImage.SaveMultiToFile(FileName);
  except
    result := false;
  end;
end;


//-----------------------------------
procedure Bmp2Tiff(pSource:String; pTarget: string);
    {$R-}
    {$RANGECHECKS OFF}


var
    XMP_Size, XMP_Offset: cardinal;
    Texto: string;

    FImage: TMultiImage;

    F: TFileStream;
    OffSetInicioDelDirectorio, NewDirOffset : LongWord;
    NumeroDeEntradasEnElDirectorio : Word;

   // Entry: TDirEntry;
    DirArray : array [0..30] of TDirEntry;
    i : Integer;
begin



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.

    //******************************
    FImage := TMultiImage.Create;

    try
     OpenFile(pSource, FImage);
     SaveFile(pTarget, FImage);

    finally
      FImage.Free;
    end;

    XMP_Size := Length(Texto);
    AddStrToFile(Texto, pTarget);
    XMP_Offset := cuantosbytes(pTarget) -  XMP_Size;


    F := TFileStream.Create(pTarget, fmOpenRead);

    try
      F.Seek(4, soFromBeginning);

      F.Read(OffSetInicioDelDirectorio, SizeOf(OffSetInicioDelDirectorio));
      F.Seek(OffSetInicioDelDirectorio, soFromBeginning);
      F.Read(NumeroDeEntradasEnElDirectorio, SizeOf(NumeroDeEntradasEnElDirectorio));

      OffSetInicioDelDirectorio := OffSetInicioDelDirectorio + SizeOf(NumeroDeEntradasEnElDirectorio);


      FillChar(DirArray,  30 * SizeOf(TDirEntry),  0);
      F.Read(DirArray, NumeroDeEntradasEnElDirectorio * SizeOf(TDirEntry));

      DirArray[NumeroDeEntradasEnElDirectorio]._Tag     := TIFFTAG_XMLPACKET;
      DirArray[NumeroDeEntradasEnElDirectorio]._Type    := 1;
      DirArray[NumeroDeEntradasEnElDirectorio]._Count   := XMP_Size;
      DirArray[NumeroDeEntradasEnElDirectorio]._Value   := XMP_Offset;
    finally
     F.Free;
    end;

    NewDirOffset := cuantosbytes(pTarget);
    F := TFileStream.Create(pTarget, fmOpenWrite);

    try
      F.Seek(4, soFromBeginning);

      F.Write(NewDirOffset, SizeOf(NewDirOffset));

      F.Seek(NewDirOffset, soFromBeginning);

      Inc(NumeroDeEntradasEnElDirectorio);
      F.Write(NumeroDeEntradasEnElDirectorio, SizeOf(NumeroDeEntradasEnElDirectorio));

      for i := 0 to NumeroDeEntradasEnElDirectorio +1  do
       Begin
        F.Write(DirArray[i], SizeOf(TDirEntry));
       End;

     finally
      F.Free;
     End;
end;  //procedure Bmp2TiffJC(pSource:String; pTarget: string);

//*********************************************************** //Fin Funcion

Best Regard
JCarlos

Galfar

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.

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Name:
Email:

Shortcuts: ALT+S save/post or ALT+P preview

SMF spam blocked by CleanTalk