AWARE [SYSTEMS] Imaging expertise for the Delphi developer
AWare Systems, Imaging expertise for the Delphi developer, Home TIFF and LibTiff Mailing List Archive

LibTiff Mailing List

TIFF and LibTiff Mailing List Archive
May 2006

Previous Thread
Next Thread

Previous by Thread
Next by Thread

Previous by Date
Next by Date

Contact

The TIFF Mailing List Homepage
This list is run by Frank Warmerdam
Archive maintained by AWare Systems



Valid HTML 4.01!



2006.05.05 17:02 "tiff split with delphi", by Andrea Bo

Hi all, 

I have try to traduce the tiffsplitt.c in Delphi, i have a problem
in this function  (C fun)

cpStrips(TIFF* in, TIFF* out)
{
 tsize_t bufsize  = TIFFStripSize(in);
 unsigned char *buf = (unsigned char *)_TIFFmalloc(bufsize);

 if (buf) {
  tstrip_t s, ns = TIFFNumberOfStrips(in);
  uint32 *bytecounts;

  TIFFGetField(in, TIFFTAG_STRIPBYTECOUNTS, &bytecounts);
  for (s = 0; s < ns; s++) {
   if (bytecounts[s] > (uint32)bufsize) {
    buf = (unsigned char *)_TIFFrealloc(buf, bytecounts[s]);
    if (!buf)
     return (0);
    bufsize = bytecounts[s];
   }
   if (TIFFReadRawStrip(in, s, buf, bytecounts[s]) < 0 ||
       TIFFWriteRawStrip(out, s, buf, bytecounts[s]) < 0) {
    _TIFFfree(buf);
    return (0);
   }
  }
  _TIFFfree(buf);
  return (1);
 }
 return (0);
}

Traduce in delphi

procedure TForm1.cpStrips(OpenTiff, Outfile: PTiff);
var
    bufsize : cardinal;
    buf :^char;
    ns : cardinal;
    s : cardinal;
    bytecounts : array of Integer;
begin
     bufsize:= TIFFStripSize(OpenTiff);
     buf:=_TIFFmalloc(bufsize);
     if buf <> nil then
        begin
        ns:= TIFFNumberOfStrips(OpenTiff);
        TIFFGetField(OpenTiff, TIFFTAG_STRIPBYTECOUNTS, @bytecounts);

          for s:= 0 to  ns  do
            begin
               if (bytecounts[s]> bufsize) then       /**this condition  is
               never verified ***/
                begin
                buf := _TIFFrealloc(buf, bytecounts[s]);
                  if (buf)=nil then
                    begin
                Exit;
                bufsize:= bytecounts[s];
                    end;
                  if (TIFFReadRawStrip(OpenTiff, s, buf, bytecounts[s]) < 0
                  )or (TIFFWriteRawStrip(Outfile, s, buf, bytecounts[s]) <
                  0) then
                      begin
                    _TIFFfree(buf);
                     Exit;
                      end;
                end;
             end;
          _TIFFfree(buf);
          Exit;
        end;
    Exit;
end;

I cant Write in output file .
thx Andrea