Read 1 bit tiff file lazarus / 39-Graphics ---------------------------------------------------------------------- SteenJorgensen · 2019-10-20 07:48 I have a problem reading a 1.bit compress tiff file. Using IntfGraphics, FPReadTiff, FPWriteTiff units. My code is: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     img := TLazIntfImage.Create(0,0);    img.DataDescription := GetDescriptionFromDevice(0);    rt := TFPReaderTiff.create;    img.LoadFromFile(FileName,rt);    Image2.Picture.Bitmap.LoadFromIntfImage(img);    rt.free;    img.free;  I get this excpetion: compression CCITT Group 4 fax encoding not supported yet at position 59222 How to read this??? ---------------------------------------------------------------------- trev · 2019-10-20 08:00 > compression CCITT Group 4 fax encoding not supported yet I suspect it means what it says. ---------------------------------------------------------------------- circular · 2019-10-20 10:05 There is no support for it in BGRABitmap and as far as I can see Vampyre Imagine Library doesn't either. On the other hand LibTIFF seem to read it. Or you can try and write the decoding function from the documentation. I guess I found the specifications: https://www.itu.int/rec/T-REC-T.6-198811-I/en The decoding function basically would take a memory block as parameter (pointer and size) and return a new memory block. ---------------------------------------------------------------------- winni · 2019-10-20 10:40 Hi! Use the ImageMagick package. You don't need to download anything. It is installed in the fpc sources in /packages/imagemagick/ Documentation at https://wiki.freepascal.org/PascalMagick Winni ---------------------------------------------------------------------- circular · 2019-10-20 19:50 Hmm it seems that only the headers (PascalMagick) are included in fpc, you still need to download/install the ImageMagick library. And in fact this library itself depends on LibTiff. https://imagemagick.org/script/formats.php ---------------------------------------------------------------------- winni · 2019-10-20 20:36 @circular I have already converted Faxes with ImageMagick. And indeed: exactly on the ImageMagick page you linked is also the format FAX which is a shortcut for TIFF with a lot of parameters.FAX is Fax Group 3. I don't know if they meanwhile implemented Fax Group 4. Winni ---------------------------------------------------------------------- circular · 2019-10-20 21:59 Yes LibTiff handles fax group 4 as well and ImageMagick use LibTiff. Si you never installed ImageMagick but used it? ---------------------------------------------------------------------- winni · 2019-10-20 22:41 Yes. At the linux command line and in shell scripts. ---------------------------------------------------------------------- circular · 2019-10-21 14:02 Hmm ok. Well it is then part of the Linux distribution. Though on Windows, that wouldn't be the case. How do you call it from the command line? Even though the package is installed on my distro (Linux Mint Xfce), the command "magick" is not recognized. ---------------------------------------------------------------------- circular · 2019-10-21 14:21 Hmm apparently, it is because I have version 6 in my distro. The other commands like display, identify etc. seem to work though. There's a nice tutorial here for ImageMagick: https://www.youtube.com/watch?v=LWwdNoh2aIA ---------------------------------------------------------------------- winni · 2019-10-21 15:07 Hi! ImageMagick at the command line for linux and little bit later for windows exist since the beginning of the 90s. The package is called ImageMagick. On the command line you call it with magick and a lot of parameters. But there are a lot of commands more like animate, composite and montage. See the "Tools" page at https://imagemagick.org On Suse and on Apple it is included in the standard instalation. One reason to put magick into a shell script is the horrible amount of possible parameters. So you can write a script for your special needs. The other reason is doing some loop stuff  for great quantity of images. "Please help me to downsize these 600 photos for the web" - asked me a friend. She owns a Graphic Studio. 5 Minutes searching the terminal on an Apple (unknown OS!), 10 minutes writing a script including magick. Then you can go smoking. While the computer works. The pascal interface  came a lot of time later than the command line version - I think. Winni ---------------------------------------------------------------------- circular · 2019-10-21 20:27 That's all great. Well, maybe I'd rather eat some vegetables than smoke.  Though I am not sure you read what I wrote. On my distro "magick" is not recognized as a command. But to go back to the first query, SteenJorgensen, it depends what you want to do. Is it a Linux program or cross-platform? Is it ok using an external library in the case of Windows? Because of course, one simple solution would be to convert it using an external program, like ImageMagick command line for example. ---------------------------------------------------------------------- winni · 2019-10-21 21:45 Hi! Just tested magick on a terminal - no problems. Reinstall the package?? And what distro?? Or: Is the path to the magick binary set? And: Has the binary enough rights??? Hmmm. ImageMagick was developed with Linux, but a year later the delivered the first windows version. But I never worked on windows with it. I don't know what dll are used. 1-Bit-Tiff to another file format: On the job I made 10 years ago (or more) a little script for faxes: Hylafax delivers a 1Bit Class 3 Tif. My script converts it to Postscript and sends it to the printer. Never had problems in all those years. Nearly forgot it. Winni ---------------------------------------------------------------------- winni · 2019-10-21 21:59 HI ImageMagick without magic!? There are some versions of ImageMagick delivered without magick! You should use convert ! For whatever  reasons. See discussion at: http://www.imagemagick.org/discourse- server/viewtopic.php?t=31986 Strange. Winni ---------------------------------------------------------------------- circular · 2019-10-22 07:58 Relax. In this discussion you linked they seem to say that it is in version 6 that magick command doesn't exist as I supposed earlier. To be precise I have version 6.9.7. Again my distro is Linux Mint Xfce, nothing too fancy. convert and identify do work though. What's surprising as well is that python command points to version 2.7.15+ but there is python3 as well which points to version 3.6.7. ---------------------------------------------------------------------- winni · 2019-10-22 08:44 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 · 2019-10-22 16:15 Ok thanks for the information. ---------------------------------------------------------------------- hrayon · 2019-10-22 20:58 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  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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, GR32_Image, LibTiffDelphi, BGRABitmap; type   { TForm1 }   TForm1 = class(TForm)  Image_test: TImage32;    procedure FormShow(Sender: TObject);  private   public   end; var  Form1: TForm1; implementation {$R *.lfm} procedure TIFFReadRGBAImageSwapRB(Width,Height: Cardinal; Memory: Pointer);{$IFDEF DELPHI_5}type  PCardinal = ^Cardinal;{$ENDIF}var  m: PCardinal;  n: Cardinal;  o: Cardinal;begin  m:=Memory;  for n:=0 to (Int64(Width))*(Int64(Height))-1 do  begin    o:=m^;    m^:= (o and $FF00FF00) or                {G and A}        ((o and $00FF0000) shr 16) or        {B}        ((o and $000000FF) shl 16);          {R}    Inc(m);  end;end;  function fn_PutTiffInImage32(p_string_file: String; p_TImage32_aux: TImage32):boolean;var  OpenTiff: PTIFF;  FirstPageWidth,FirstPageHeight,Compression,Photometric: Cardinal;  l_TBGRABitmap_aux: TBGRABitmap;  l_TBitmap_Aux : TBitmap;  l_boolean_ok : boolean;begin  l_boolean_ok := true;  OpenTiff:=TIFFOpen(p_string_file,'r');  if OpenTiff=nil then l_boolean_ok := false;  TIFFGetField(OpenTiff,TIFFTAG_IMAGEWIDTH,@FirstPageWidth);  TIFFGetField(OpenTiff,TIFFTAG_IMAGELENGTH,@FirstPageHeight);  TIFFGetField(OpenTiff,TIFFTAG_COMPRESSION,@Compression);  TIFFGetField(OpenTiff,TIFFTAG_PHOTOMETRIC,@Photometric);  if (Photometric = PHOTOMETRIC_YCBCR) then  begin    l_boolean_ok := false; //Not handled this subtype  end  else  begin    l_TBGRABitmap_aux := nil;    try      l_TBGRABitmap_aux:=TBGRABitmap.C reate(FirstPageWidth,FirstPageHeight);    except      l_boolean_ok := false;      if l_TBGRABitmap_aux <> nil then l_TBGRABitmap_aux.Destroy;      TIFFClose(OpenTiff);    end;    try    try        TIFFReadRGBAImage(OpenTiff,FirstPageWidth,FirstPageHeight, PInteger(l_TBGRABitmap_aux.ScanLine[FirstPageHeight-1]),0);        TIFFReadRGBAImageSwapRB(FirstPageWidth,FirstPageHeight, PInteger(l_TBGRABitmap_aux.ScanLine[FirstPageHeight-1]));      except        l_boolean_ok := false;      end;    finally      TIFFClose(OpenTiff);    end;    if l_boolean_ok then    begin      l_TBitmap_Aux := TBitmap.Create;      l_TBitmap_Aux.Width:=FirstPageWidth;      l_TBitmap_Aux.Height:=FirstPageHeight;      l_TBitmap_Aux.PixelFormat:=pf32bit;      l_TBGRABitmap_aux.Draw(l_TBitmap_Aux.Canvas,0,0,true);      p_TImage32_aux.Bitmap.Assign(l_TBitmap_Aux);      l_TBitmap_Aux.Free;      l_TBGRABitmap_aux.Free;    end;  end;  Result := l_boolean_ok;end; { TForm1 } procedure TForm1.FormShow(Sender: TObject);begin  if not fn_PutTiffInImage32('lazarus.tif',Image_test) then  begin    //put your message error here  end;end; end. ---------------------------------------------------------------------- circular · 2019-10-23 16:48 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? ---------------------------------------------------------------------- hrayon · 2019-10-24 12:15 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 · 2019-10-24 14:43 Yep, that's what I wanted to say by "statically linked".