Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Traducción de C a Delphi (https://www.clubdelphi.com/foros/showthread.php?t=58825)

madiazg 02-08-2008 12:49:43

Traducción de C a Delphi
 
Hola,
a ver si alguien me puede ayudar.
Resulta que estoy programando una aplicación para realizar imágenes en 3D (anaglifas, Side-by-Side y Gif)(http://imagen3d.site88.net/) y quiero obtener los datos EXIF de los ficheros que cargo. Utilizo una librería denominada gflLib utilizada en el programa XnView (http://www.xnview.com/).
Por lo visto, para mostrar los datos, en C se utilizaría el siguiente código:
Código:

exif = gflBitmapGetEXIF(bitmap, 0);
  if (exif)
  {
      for ( i=0; i<exif->NumberOfItems; i++)
        printf("EXIF %x %x <%s> = %s\n", exif->ItemsList[i].Flag, exif->ItemsList[i].Tag, exif->ItemsList[i].Name, exif->ItemsList[i].Value );
      gflFreeEXIF(exif);
  }

En gflLib.pas aparece:

Código:

// EXIF
const
  GFL_EXIF_MAIN_IFD            = $0001;
  GFL_EXIF_IFD_0                = $0002;
  GFL_EXIF_INTEROPERABILITY_IFD = $0004;
  GFL_EXIF_IFD_THUMBNAIL        = $0008;
  GFL_EXIF_GPS_IFD              = $0010;
  GFL_EXIF_MAKERNOTE_IFD        = $0020;

  GFL_EXIF_MAKER                = $010F;
  GFL_EXIF_MODEL                = $0110;
  GFL_EXIF_ORIENTATION                = $0112;
  GFL_EXIF_EXPOSURETIME                = $829A;
  GFL_EXIF_FNUMBER                = $829D;
  GFL_EXIF_DATETIME_ORIGINAL        = $9003;
  GFL_EXIF_SHUTTERSPEED                = $9201;
  GFL_EXIF_APERTURE                = $9202;
  GFL_EXIF_MAXAPERTURE                = $9205;
  GFL_EXIF_FOCALLENGTH              = $920A;


type
  PGFL_EXIF_ENTRY = ^TGFL_EXIF_ENTRY;
  TGFL_EXIF_ENTRY  = packed record
    Flag  : GFL_UINT32; // EXIF_...IFD
    Tag  : GFL_UINT32;
    Name  : PChar;
    Value : PChar;
  end;

  PTTabGFL_EXIF_ENTRY = ^TTabGFL_EXIF_ENTRY;
  TTabGFL_EXIF_ENTRY = array [0..0] of TGFL_EXIF_ENTRY;

  PGFL_EXIF_DATA = ^TGFL_EXIF_DATA;
  TGFL_EXIF_DATA  = packed record
    NumberOfItems : GFL_UINT32;
    ItemsList    : PTTabGFL_EXIF_ENTRY; // PGFL_EXIF_ENTRY;
  end;

function gflBitmapHasEXIF(src: PGFL_BITMAP): GFL_BOOL; stdcall;
function gflBitmapGetEXIF(src: PGFL_BITMAP; flags: GFL_UINT32): PGFL_EXIF_DATA; stdcall;
procedure gflFreeEXIF(exif: PGFL_EXIF_DATA); stdcall;
procedure gflBitmapRemoveEXIFThumbnail(src: PGFL_BITMAP); stdcall;

No se si con estos datos es suficiente.
Pueden ayudarme a traducir este código a Delphi ya que no conozco C.
Saludos...
Miguel Angel

seoane 02-08-2008 12:57:52

Parece que la función gflBitmapGetEXIF devuelve un puntero a una estructura. Necesitas saber como esta definida esa estructura.

madiazg 02-08-2008 13:01:01

He editado el mensaje con el código que aparece en gflLib.pas
Saludos...
Miguel Angel

coso 02-08-2008 13:24:42

Hola, solo tienes que sustituir {} por begin, end; el if exif por if assigned(exif) o exif <> nil, el for i;;i++ por for i := 0 to exif.Numbers, las -> por ., el printf() ... pues no se, con ShowMessage(format(...)), alla el printf es solo para sacar datos a pantalla, sino esta redireccionada cout..si va para un archivo o algo, Format('..',[array]) se comporta de manera similar. exif probablemente sera TGFL_EXIF_ENTRY, aunque tambien es posible que sea puntero a esto, PGLF_EXIF_ENTRY

PD :
Código:

TTabGFL_EXIF_ENTRY = array [0..0] of TGFL_EXIF_ENTRY;
¿esto ya es correcto? ¿no serà array dinamico, esto es, array of TGFL_EXIT_ENTRY?

madiazg 02-08-2008 15:00:24

Hola, he implementado este código:
Código:

var
  EXIF : PGFL_EXIF_DATA;
  NItems : integer;
  gfl_bmp1b: PGFL_BITMAP; // Estructura que contiene todas la información sobre una imagen cargada en memoria

...
begin
......
    if gflBitMapHasEXIF(gfl_bmp1b) = gfl_no_error then
    begin
      LabelEXIF.Enabled := True;
      Exif := gflLoadExif(Pchar(FileName1),0);
      NItems := Exif.NumberOfItems;
      for i := 0 to NItems-1 do
      begin
        FormPrincipal.ListBox1.Items.Add(Exif.ItemsList[i].Name + ': ' + Exif.ItemsList[i].Value);
    end;

      gflFreeEXIF(Exif);
    end else MessageDlg('File not readable: ' + string(gflGetErrorString(e1)), mtError, [mbOK], 0);

Funciona correctamente. Gracias!!!!


La franja horaria es GMT +2. Ahora son las 20:15:01.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi