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

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - jcarlos

1
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
2
XMP Specification Part3
3
XMP Specification Part2
4
XMP Specification Part1
5
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
6
Hi.
Some body are thinking about include XMP label inside the Image .tiff????
Best Regard.
JCarlos
7
Hi.
I think maybe could be included other filter to the file
ImagingCanvases.pas
I was needed to do it and I include 3 new filter, realy maybe two because the average filter for 3x3 and 5x5 is alredy included.

I send here the code for you. (I only send the segment of code that must to be put inside ImagingCanvases.pas like a methods of the "TImagingCanvas"  class)

You are free to use this code like you want. (The code is in the attach).
The code was tested in Lazarus for windows.

For make a test you can include it in the example named
LCLImager

And use the following code to call this methods.

procedure TMainForm.mnPromedioClick(Sender: TObject);
begin
if FImage.Format in FImageCanvas.GetSupportedFormats
      then Begin
              FImageCanvas.CreateForImage(FImage);
              FImageCanvas.ApplyAverage(3);
              UpdateView;
            End;

end;
SMF spam blocked by CleanTalk