Recent

Author Topic: Read 1 bit tiff file  (Read 5456 times)

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Read 1 bit tiff file
« Reply #15 on: October 22, 2019, 10:44:11 am »
Hi!

I have installed

Version: ImageMagick 7.0.8-68 Q16 x86_64
from 2019/10/07
Automatic installed by the rolling release Tumbleweed.

There are no DEB-packages for the Debian based Linuxes.

So for an update you have to take the source package and compile and install it.

Winni



circular

  • Hero Member
  • *****
  • Posts: 4195
    • Personal webpage
Re: Read 1 bit tiff file
« Reply #16 on: October 22, 2019, 06:15:34 pm »
Ok thanks for the information.  :)
Conscience is the debugger of the mind

hrayon

  • Full Member
  • ***
  • Posts: 118
Re: Read 1 bit tiff file
« Reply #17 on: October 22, 2019, 10:58:28 pm »
Hello everyone!
Don't ask me how it worked, ask mr Circular, he did the hard work and can explain this kind of code. I only succeeded after much trial and error, I'm not as smart as him. Just got something here and there and put it together.
I was able to use BGRABitmap with LibTifDelphi to display this requested tiff file type - without ImageMagick  :D
I am attaching the project.
OBS: I'm using libtiff-imaging-3.9.4 version, but can't upload here. On google you will find it.
I'm using Windows 10, Lazarus 1.8.4.
(This code can be improved, but the main concept is there)
(translated using Google)

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, GR32_Image, LibTiffDelphi, BGRABitmap;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Image_test: TImage32;
  16.     procedure FormShow(Sender: TObject);
  17.   private
  18.  
  19.   public
  20.  
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.  
  26. implementation
  27.  
  28. {$R *.lfm}
  29.  
  30. procedure TIFFReadRGBAImageSwapRB(Width,Height: Cardinal; Memory: Pointer);
  31. {$IFDEF DELPHI_5}
  32. type
  33.   PCardinal = ^Cardinal;
  34. {$ENDIF}
  35. var
  36.   m: PCardinal;
  37.   n: Cardinal;
  38.   o: Cardinal;
  39. begin
  40.   m:=Memory;
  41.   for n:=0 to (Int64(Width))*(Int64(Height))-1 do
  42.   begin
  43.     o:=m^;
  44.     m^:= (o and $FF00FF00) or                {G and A}
  45.         ((o and $00FF0000) shr 16) or        {B}
  46.         ((o and $000000FF) shl 16);          {R}
  47.     Inc(m);
  48.   end;
  49. end;
  50.  
  51.  
  52. function fn_PutTiffInImage32(p_string_file: String; p_TImage32_aux: TImage32):boolean;
  53. var
  54.   OpenTiff: PTIFF;
  55.   FirstPageWidth,FirstPageHeight,Compression,Photometric: Cardinal;
  56.   l_TBGRABitmap_aux: TBGRABitmap;
  57.   l_TBitmap_Aux : TBitmap;
  58.   l_boolean_ok : boolean;
  59. begin
  60.   l_boolean_ok := true;
  61.   OpenTiff:=TIFFOpen(p_string_file,'r');
  62.   if OpenTiff=nil then l_boolean_ok := false;
  63.   TIFFGetField(OpenTiff,TIFFTAG_IMAGEWIDTH,@FirstPageWidth);
  64.   TIFFGetField(OpenTiff,TIFFTAG_IMAGELENGTH,@FirstPageHeight);
  65.   TIFFGetField(OpenTiff,TIFFTAG_COMPRESSION,@Compression);
  66.   TIFFGetField(OpenTiff,TIFFTAG_PHOTOMETRIC,@Photometric);
  67.   if (Photometric = PHOTOMETRIC_YCBCR) then
  68.   begin
  69.     l_boolean_ok := false; //Not handled this subtype
  70.   end
  71.   else
  72.   begin
  73.     l_TBGRABitmap_aux := nil;
  74.     try
  75.       l_TBGRABitmap_aux:=TBGRABitmap.Create(FirstPageWidth,FirstPageHeight);
  76.     except
  77.       l_boolean_ok := false;
  78.       if l_TBGRABitmap_aux <> nil then l_TBGRABitmap_aux.Destroy;
  79.       TIFFClose(OpenTiff);
  80.     end;
  81.     try
  82.       try
  83.         TIFFReadRGBAImage(OpenTiff,FirstPageWidth,FirstPageHeight, PInteger(l_TBGRABitmap_aux.ScanLine[FirstPageHeight-1]),0);
  84.         TIFFReadRGBAImageSwapRB(FirstPageWidth,FirstPageHeight, PInteger(l_TBGRABitmap_aux.ScanLine[FirstPageHeight-1]));
  85.       except
  86.         l_boolean_ok := false;
  87.       end;
  88.     finally
  89.       TIFFClose(OpenTiff);
  90.     end;
  91.     if l_boolean_ok then
  92.     begin
  93.       l_TBitmap_Aux := TBitmap.Create;
  94.       l_TBitmap_Aux.Width:=FirstPageWidth;
  95.       l_TBitmap_Aux.Height:=FirstPageHeight;
  96.       l_TBitmap_Aux.PixelFormat:=pf32bit;
  97.       l_TBGRABitmap_aux.Draw(l_TBitmap_Aux.Canvas,0,0,true);
  98.       p_TImage32_aux.Bitmap.Assign(l_TBitmap_Aux);
  99.       l_TBitmap_Aux.Free;
  100.       l_TBGRABitmap_aux.Free;
  101.     end;
  102.   end;
  103.   Result := l_boolean_ok;
  104. end;
  105.  
  106. { TForm1 }
  107.  
  108. procedure TForm1.FormShow(Sender: TObject);
  109. begin
  110.   if not fn_PutTiffInImage32('lazarus.tif',Image_test) then
  111.   begin
  112.     //put your message error here
  113.   end;
  114. end;
  115.  
  116. end.
  117.  
« Last Edit: October 22, 2019, 11:08:25 pm by hrayon »

circular

  • Hero Member
  • *****
  • Posts: 4195
    • Personal webpage
Re: Read 1 bit tiff file
« Reply #18 on: October 23, 2019, 06:48:29 pm »
That's interesting. So if I understand correctly, that is an object file from LibTiff that is statically linked so that you wouldn't have LibTiff dependency on Windows?
Conscience is the debugger of the mind

hrayon

  • Full Member
  • ***
  • Posts: 118
Re: Read 1 bit tiff file
« Reply #19 on: October 24, 2019, 02:15:28 pm »
Hi @circular!
When you write "dependency" are you telling about dll files?
If yes, you're wright, your single and alone executable file is able to open and show this kind of tiff file (CCITT Group 4 Fax Encoding) and others too.

circular

  • Hero Member
  • *****
  • Posts: 4195
    • Personal webpage
Re: Read 1 bit tiff file
« Reply #20 on: October 24, 2019, 04:43:09 pm »
Yep, that's what I wanted to say by "statically linked".  :)
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018