Recent

Author Topic: Multi-page TIFF file and FPImage  (Read 14326 times)

Girlbrush

  • Jr. Member
  • **
  • Posts: 65
Multi-page TIFF file and FPImage
« on: December 05, 2016, 03:57:21 pm »
Trying to make a viewer for multi page TIFF files.

Using TFPReaderTiff, TFPCustomImage and TImage

reader.ImageCount gives me the right number of contained pages, but I can not figure out how to get to the images after the first one.

Code: Pascal  [Select][+][-]
  1. reader.Images[i].Img
is always unassigned?

Some snippets
Code: Pascal  [Select][+][-]
  1.       FBild.LoadFromFile(filename, reader);
  2.  
  3.       FGesamtSeiten := reader.ImageCount;
  4.       FAktuelleSeite:=0;
  5.       lbl_Seiten.Caption:=IntToStr(FGesamtSeiten);
  6.  
  7.       Image1.Picture.Assign(reader.firstImg().Img);
  8.  
Code: Pascal  [Select][+][-]
  1. procedure TWnd_OpenTIFF.sb_RechtsClick(Sender: TObject);
  2. var neu: integer;
  3.   status: String;
  4. begin
  5.   // Seite danach
  6.   if (FAktuelleSeite < (FGesamtSeiten-1)) then
  7.   begin
  8.     neu:=FAktuelleSeite+1;
  9.     lbl_Seite.Caption:=IntToStr(neu+1);
  10.     Image1.Picture.Assign(reader.Images[neu].Img);
  11.     FAktuelleSeite:=neu;
  12.   end;
  13. end;
  14.  

EDIT: I have found that reader[index] contains other data, such as ImageHeight, ImageWidth and IFDStart. Can I use that to obtain the image itself somehow?
« Last Edit: December 06, 2016, 12:49:58 pm by Girlbrush »
Getting back into programming after 8+ years.

Girlbrush

  • Jr. Member
  • **
  • Posts: 65
Re: Multi-page TIFF file and FPImage
« Reply #1 on: December 07, 2016, 10:01:55 am »
I have tried getting TIFF viewing to work with
- PascalMagick (wants a dll that I don't have anywhere)
- BGRABitmap (couldn't find any possibility for multi-page images)

I haven't tried
- Vampyre library, as the website states that better TIFF support hasn't been implemented yet
- FreeImage, no Lazarus package

I don't need editing capabilities, we have an all-in-one viewer for Database BLOBS that can be text, PDF, images etc. that needs to be ported to Lazarus.
Getting back into programming after 8+ years.

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: Multi-page TIFF file and FPImage
« Reply #2 on: December 07, 2016, 10:58:35 am »
I haven't tried to do multi-page TIFF's with FPImage yet. I don't know if it supports it, but could always be added if it doesn't. But thinking about it, that would be another awesome report exporter format for the up-coming fpReport. A nice alternative to PDF or multiple PNG files for a multi-page report.

I'll ask in the FPC mailing list if anybody knows if FPImage support multi-page TIFF's.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

Girlbrush

  • Jr. Member
  • **
  • Posts: 65
Re: Multi-page TIFF file and FPImage
« Reply #3 on: December 07, 2016, 11:23:09 am »
Thank you Graeme.

The FPReadTIFF looks like it should do it. I am currently compiling FPC 3.1.1, to test if it's a bug in FCL-image or something.

EDIT: the IDE will not compile with 3.1.1, so scratch that
« Last Edit: December 07, 2016, 11:42:11 am by Girlbrush »
Getting back into programming after 8+ years.

fred

  • Full Member
  • ***
  • Posts: 201
Re: Multi-page TIFF file and FPImage
« Reply #4 on: December 07, 2016, 11:26:03 am »
About FreeImage, the wiki has a about using FreeImage: http://wiki.lazarus.freepascal.org/Components_and_Code_examples

It links to: http://breakoutbox.de/pascal/applications.html#PicViewer

"PicViewer is a Image Viewer which uses the the FreeImage.dll to be able to load and display several Image File Formats like PNG, BMP, JPEG, TIFF and others. PicViewer is partly based on an example application from the Lazarus demo folder."

Girlbrush

  • Jr. Member
  • **
  • Posts: 65
Re: Multi-page TIFF file and FPImage
« Reply #5 on: December 07, 2016, 11:50:11 am »
fred,

I am looking at the PicViewer application. It doesn't compile for x64 windows, but I will try it out in my own project...
Getting back into programming after 8+ years.

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: Multi-page TIFF file and FPImage
« Reply #6 on: December 07, 2016, 01:21:13 pm »
The FPReadTIFF looks like it should do it. I am currently compiling FPC 3.1.1, to test if it's a bug in FCL-image or something.
I asked on the FPC Users mailing list, and got a confirmation that mult-page TIFF support is there for reading and writing.

  http://www.mail-archive.com/fpc-pascal@lists.freepascal.org/msg44454.html

Quote
EDIT: the IDE will not compile with 3.1.1, so scratch that
You don't need to recompile Lazarus IDE with FPC 3.1.1 just to test 3.1.1's code. Simply go to IDE Options and change the compiler version, but don't recompile your IDE.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

fred

  • Full Member
  • ***
  • Posts: 201
Re: Multi-page TIFF file and FPImage
« Reply #7 on: December 07, 2016, 01:27:10 pm »
Quote
I am looking at the PicViewer application. It doesn't compile for x64 windows, but I will try it out in my own project...
I could compile it using Lazarus 1.6.2 / fpc 3.0.0 32 bit on W7 64 bit with the supplied 2008 FreeImage.dll and a newer 2015 FreeImage.dll
For 64 bit executable I suppose a 64 bit library is needed.
What kind of error do you get?

Girlbrush

  • Jr. Member
  • **
  • Posts: 65
Re: Multi-page TIFF file and FPImage
« Reply #8 on: December 07, 2016, 01:31:42 pm »
Quote
I am looking at the PicViewer application. It doesn't compile for x64 windows, but I will try it out in my own project...
I could compile it using Lazarus 1.6.2 / fpc 3.0.0 32 bit on W7 64 bit with the supplied 2008 FreeImage.dll and a newer 2015 FreeImage.dll
For 64 bit executable I suppose a 64 bit library is needed.
What kind of error do you get?
I found DLLs for FreeImage (http://freeimage.sourceforge.net/download.html), but those new ones need the MS VC++ 2013 redistributable. Which makes FreeImage a poor candidate for our uses... I am now working on making a test project with it.
Getting back into programming after 8+ years.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: Multi-page TIFF file and FPImage
« Reply #9 on: December 07, 2016, 05:56:23 pm »
hello,
success story to read a multipage tiff file :
i have converted to Lazarus, the  multibitmap demo of the delphi wrapper of freemage (attachment).
put the big dll freeimage.dll (> 5mb) in the same directory of the lazarus exe.
Result in attachment
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Girlbrush

  • Jr. Member
  • **
  • Posts: 65
Re: Multi-page TIFF file and FPImage
« Reply #10 on: December 08, 2016, 10:57:42 am »
fred and Jurassic Pork:

I have also successfully integrated FreeImage into my test project.  ;D

Today I am compiling the FreeeImage DLL with mingw. With the resulting dll, the project no longer runs (no errors in IDE, outside see attachment). It would be perfect if I could get rid of the VCredist dependency... Any hints appreciated!
« Last Edit: December 08, 2016, 12:05:52 pm by Girlbrush »
Getting back into programming after 8+ years.

Girlbrush

  • Jr. Member
  • **
  • Posts: 65
Re: Multi-page TIFF file and FPImage
« Reply #11 on: December 08, 2016, 11:01:02 am »
The FPReadTIFF looks like it should do it. I am currently compiling FPC 3.1.1, to test if it's a bug in FCL-image or something.
I asked on the FPC Users mailing list, and got a confirmation that mult-page TIFF support is there for reading and writing.

  http://www.mail-archive.com/fpc-pascal@lists.freepascal.org/msg44454.html

Quote
EDIT: the IDE will not compile with 3.1.1, so scratch that
You don't need to recompile Lazarus IDE with FPC 3.1.1 just to test 3.1.1's code. Simply go to IDE Options and change the compiler version, but don't recompile your IDE.

Graeme,
thank you for checking! So only the event handler is necessary? Some documentation or a tutorial would be good ;)
We might stick with FreeImage after all, since it looks like the same code can display any of the supported formats.
« Last Edit: December 08, 2016, 11:37:02 am by Girlbrush »
Getting back into programming after 8+ years.

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: Multi-page TIFF file and FPImage
« Reply #12 on: December 08, 2016, 01:33:09 pm »
thank you for checking! So only the event handler is necessary? Some documentation or a tutorial would be good ;)
Yes, all I missed was an event handler. And yes, FPImage documentation would be very nice. :)

Here is my test program in action. I use the Unix "convert" command to make 2 PNG images into a single TIFF image. You can do the same with PDF's too (pretty neat).

I've also attached my source code I used. I've only used Free Pascal's FPImage and its TIFF reader unit.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

Girlbrush

  • Jr. Member
  • **
  • Posts: 65
Re: Multi-page TIFF file and FPImage
« Reply #13 on: December 08, 2016, 01:55:11 pm »
Nice one! Have a <beverage> on me  ;D
Getting back into programming after 8+ years.

fred

  • Full Member
  • ***
  • Posts: 201
Re: Multi-page TIFF file and FPImage
« Reply #14 on: December 08, 2016, 05:28:14 pm »
I have never used mingw (only a little TCC and AVR C) so I don't know.
Was the correct version 32/64 bit generated?
But if it works with FPImage is it worth the effort? :)
Everybody has learned something :)

 

TinyPortal © 2005-2018