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

Post reply

Other options

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

Topic summary

Posted by Galfar
 -  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.
Posted by jcarlos
 - 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) 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
Posted by jcarlos
 - 11 February 2009, 00:12:28
XMP Specification Part3
Posted by jcarlos
 - 11 February 2009, 00:10:33
XMP Specification Part2
Posted by jcarlos
 - 11 February 2009, 00:04:55
XMP Specification Part1
Posted by Galfar
 -  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.
Posted by jcarlos
 -  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
Posted by Galfar
 - 31 January 2009, 13:47:35
Hi, do you have some info about XMP labels? A link?
Posted by jcarlos
 - 30 January 2009, 15:35:50
Hi.
Some body are thinking about include XMP label inside the Image .tiff????
Best Regard.
JCarlos
SMF spam blocked by CleanTalk