Recent

Author Topic: Loading TIFF Files in Bgra Bitmap  (Read 830 times)

zxandris

  • Full Member
  • ***
  • Posts: 141
Loading TIFF Files in Bgra Bitmap
« on: January 21, 2025, 06:58:00 am »
I'm trying to load TIFF files with Bgra Bitmap now :-

Code: Pascal  [Select][+][-]
  1.              
  2.              bgrab := TBgraBitmap.create;
  3.              try
  4.                 Bgrab.LoadFromFile(fname);
  5.                 bmp.assign(bgrab);
  6.              finally
  7.                     bgrab.free;
  8.              end;
  9.  

Doesn't appear to work I'm just getting a transparent box of nothing.  What might I be doing wrong please?

CJ

MaxM74

  • New Member
  • *
  • Posts: 24
Re: Loading TIFF Files in Bgra Bitmap
« Reply #1 on: January 21, 2025, 07:49:33 am »
what is bmp?

zxandris

  • Full Member
  • ***
  • Posts: 141
Re: Loading TIFF Files in Bgra Bitmap
« Reply #2 on: January 21, 2025, 09:37:26 am »
BMP is set elsewhere and is another BgraBitmap that is handed around in procedure variables.  Essentially the Bgrab BMP is just a holder temporarily, might not even need it for that.  Do elsewhere so it's become rather a standard.

circular

  • Hero Member
  • *****
  • Posts: 4383
    • Personal webpage
Re: Loading TIFF Files in Bgra Bitmap
« Reply #3 on: January 21, 2025, 12:29:57 pm »
The code seems ok.

Can you provide a sample TIFF? These files can contain multiple entries, maybe the default entry is empty.
Conscience is the debugger of the mind

zxandris

  • Full Member
  • ***
  • Posts: 141
Re: Loading TIFF Files in Bgra Bitmap
« Reply #4 on: January 21, 2025, 12:41:18 pm »
Okay this, I checked, does the same thing.  Is there a way to not use the default image but say the first page?

The code seems ok.

Can you provide a sample TIFF? These files can contain multiple entries, maybe the default entry is empty.

circular

  • Hero Member
  • *****
  • Posts: 4383
    • Personal webpage
Re: Loading TIFF Files in Bgra Bitmap
« Reply #5 on: January 21, 2025, 12:48:13 pm »
Hmmm, the TIFF indeed contains multiple images, but trying to open it with LazPaint, all images seem blank. This may be related to the pixel format or encoding.
Conscience is the debugger of the mind

zxandris

  • Full Member
  • ***
  • Posts: 141
Re: Loading TIFF Files in Bgra Bitmap
« Reply #6 on: January 21, 2025, 12:53:42 pm »
Did some experimentation, it appears JPEG encoding doesn't work as does not G3 and G4FAX, but ZIP and Uncompressed and LZW does, in BgraBitmap.  The original image was a JPEG Encoded TiFF.

Thanks for your help!

CJ

Hmmm, the TIFF indeed contains multiple images, but trying to open it with LazPaint, all images seem blank. This may be related to the pixel format or encoding.

zxandris

  • Full Member
  • ***
  • Posts: 141
Re: Loading TIFF Files in Bgra Bitmap
« Reply #7 on: January 21, 2025, 12:58:05 pm »
As a matter of interest how do you get to the other pages, or know how many there even are?

Please,

CJ

Hmmm, the TIFF indeed contains multiple images, but trying to open it with LazPaint, all images seem blank. This may be related to the pixel format or encoding.

circular

  • Hero Member
  • *****
  • Posts: 4383
    • Personal webpage
Re: Loading TIFF Files in Bgra Bitmap
« Reply #8 on: January 21, 2025, 01:12:27 pm »
Indeed, the image is JPEG encoded. I am not sure how difficult it would be to implement. It could be if it is just like one JPEG file put into the TIFF file. It seems you can use another encoding, so you're not stuck?

To explore the various images, instantiate explicitly a TBGRAReadTiff (of BGRAReadTiff unit) and call LoadFromStream function.

Then you have ImageCount and Images properties. For example reader.Images[0].Img as TBGRABitmap will be the first image.
Conscience is the debugger of the mind

zxandris

  • Full Member
  • ***
  • Posts: 141
Re: Loading TIFF Files in Bgra Bitmap
« Reply #9 on: January 21, 2025, 01:28:23 pm »
Thank you I will give that a go! :)

CJ

Indeed, the image is JPEG encoded. I am not sure how difficult it would be to implement. It could be if it is just like one JPEG file put into the TIFF file. It seems you can use another encoding, so you're not stuck?

To explore the various images, instantiate explicitly a TBGRAReadTiff (of BGRAReadTiff unit) and call LoadFromStream function.

Then you have ImageCount and Images properties. For example reader.Images[0].Img as TBGRABitmap will be the first image.

wp

  • Hero Member
  • *****
  • Posts: 12608
Re: Loading TIFF Files in Bgra Bitmap
« Reply #10 on: January 21, 2025, 05:51:54 pm »
Looking at the file in my hex editor I found that the file contains blocks beginning with a standard jpeg signature. I selected a block from one jpeg signature to the next one and saved it to file - the file is readable as a jpeg, even by the LCL jpeg reader.

circular

  • Hero Member
  • *****
  • Posts: 4383
    • Personal webpage
Re: Loading TIFF Files in Bgra Bitmap
« Reply #11 on: January 22, 2025, 10:02:18 am »
Looking at the file in my hex editor I found that the file contains blocks beginning with a standard jpeg signature. I selected a block from one jpeg signature to the next one and saved it to file - the file is readable as a jpeg, even by the LCL jpeg reader.
Cool. Thank you for checking that. So this could be easily implemented indeed by plugging the TIFF reader with the JPEG reader.

New Github issue: https://github.com/bgrabitmap/bgrabitmap/issues/264
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018