ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 PixelFormat with TImageEnMIO
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

JonMRobertson

USA
32 Posts

Posted - Aug 18 2023 :  10:44:08  Show Profile  Reply
I have been trying to reduce the size of the images that my code is creating/saving. In particular, we only work with documents and not images, so there is no need to save in 24 bit format. I just added code to convert to 8-bit by setting PixelFormat. But I am doing something wrong.

If I try to save the image to PDF, an AV occurs. However, saving the image as TIFF reveals there is definitely something I should be doing differently. See the attached TIFF. The relevant code is below. I have omitted some code for briefity. The actual code contains a loop that is loading multiple images from a collection of memory streams, which is why I am using TImageEnMIO.
var
  mio:    TImageEnMIO;  // Holds all merged images/pages.
  enView: TImageEnView; // Used to merge image & layers into single bitmap

begin
  mio := TImageEnMIO.Create(nil);
  try
    enView := TImageEnView.Create(nil);
    try
      enView.ClearAll();
      enView.IO.LoadFromStream(msStream);
      enView.LayersMergeAll();

      case enView.IEBitmap.PixelFormat of
        ie16g,
        ie24RGB,
        ie32f,
        ieCMYK,
        ie48RGB,
        ieCIELab,
        ie32RGB: begin
          enView.IEBitmap.PixelFormat := ie8p;
        end;
      end;

      iIndex := mio.AttachedIEMBitmap.AppendImage;
      mio.AttachedIEMBitmap.SetImage(iIndex, enView.IEBitmap);

      mio.Params[0].TIFF_Compression:=ioTIFF_LZW;
	  mio.DuplicateCompressionInfo();

      mio.SaveToStream(aStream, aFileType);

If it helps at all, here is the stack trace of the AV when saving as ioPDF:
System.Move(???,???,???)
imageenproc._CopyBGR_RGB($A6F9818,$11A9F728,2550)
iepdf.TIEPDFBuilder.AddImage(0,0,612,792,$A3622B0,0,1,$A287950,$25EF6DC)
iepdf.TIEPDFBuilder.AddPageWithImage($A3622B0,$A287950,$25EF6DC)
iepdf.TIEPDFBuilder.AddPageWithImage($A3622B0,$A287950)
iemio._SaveImg(0,0)
iemio.TImageEnMIO.SaveToStreamPDF($A274AC8,False)
iemio.TImageEnMIO.SaveToStream($A274AC8,18,False)
Thank you for any assistance provided! :-)

Edit: I neglected to attach the image earlier.

attach/JonMRobertson/2023818141136_TestImage.tiff

JonMRobertson

USA
32 Posts

Posted - Aug 18 2023 :  15:23:12  Show Profile  Reply
I am attaching a test project that demonstrates the issue that I am having with my code. If the PixelFormat checkbox is checked, the resulting images are corrupted. If unchecked, the images are not corrupted.

What am I doing wrong?

Thanks

attach/JonMRobertson/2023818152226_PixelFormatTest.zip
746.45 KB
Go to Top of Page

xequte

38613 Posts

Posted - Aug 18 2023 :  19:01:26  Show Profile  Reply
Hi Jon

By default, setting PixelFormat does not update the BitsPerSample/SamplesPerPixel properties (this was the original design model of ImageEn).

Generally, then you should enable IEGlobalSettings().AutoSetBitDepth which makes PixelFormat the authoritative source of bit depth:

https://www.imageen.com/help/TIEGlobalSettings.AutoSetBitDepth.html

Unfortunately this is not implemented in TImageEnMIO until the upcoming 12.3.0, so presently, if you are setting:

PixelFormat := ie8p;

You must also set:

mio.Params[0].BitsPerSample := 8;
mio.Params[0].SamplesPerPixel := 1;

Note: PDF only supports ie1g and ie24RGB

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

JonMRobertson

USA
32 Posts

Posted - Aug 18 2023 :  21:35:18  Show Profile  Reply
Thanks Nigel. My application does enable IEGlobalSettings().AutoSetBitDepth. I accidently left that out of the test project. However, I am relieved to know why it still occurred with AutoSetBitDepth enabled.

Relating to PDF, is that the PDF standard or the ImageEn implementation? The PDFs that I am generating are around 6MB per page. I suppose I will try ie1g and see if the quality is good enough.

Jon
Go to Top of Page

xequte

38613 Posts

Posted - Aug 18 2023 :  21:57:22  Show Profile  Reply
Hi Jon

TImageEnMIO does not presently support AutoSetBitDepth, but you can email me for the beta that does support it.

Other pixel formats should be supported by the PDF standard, depending on the compression, but ImageEn only supports ie1g and ie24RGB.

The default compression format for PDF images is uncompressed, so you should change that:

http://www.imageen.com/help/TIOParams.PDF_Compression.html



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

JonMRobertson

USA
32 Posts

Posted - Aug 18 2023 :  22:30:36  Show Profile  Reply
I just tried a few changes, and found the options below do a rather nice job, considering the bit depth:

  enView.Proc.ConvertToBW_FloydSteinberg();
  enView.IEBitmap.PixelFormat := ie1g;

  mio.Params[0].BitsPerSample   := 1;
  mio.Params[0].SamplesPerPixel := 1;
  mio.Params[0].PDF_Compression := ioPDF_G4FAX;

  mio.DuplicateCompressionInfo();

I am doing the same for TIFF, except using ie8g for PixelFormat. 6 page TIFF is 4MB. Same images saved as PDF is 2MB.

Thanks for your guidance and this forum. There is a full knowledge base buried here. ;)
Go to Top of Page

JonMRobertson

USA
32 Posts

Posted - Aug 20 2023 :  22:08:38  Show Profile  Reply
I have confirmed that setting PixelFormat in the beta updates BitsPerSample/SamplesPerPixel in TImageEnMIO.

Jon
Go to Top of Page

xequte

38613 Posts

Posted - Aug 21 2023 :  17:34:15  Show Profile  Reply
Thanks for confirming, Jon

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: