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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 PixelFormat with TImageEnMIO

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
JonMRobertson Posted - Aug 18 2023 : 10:44:08
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
7   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Aug 21 2023 : 17:34:15
Thanks for confirming, Jon

Nigel
Xequte Software
www.imageen.com
JonMRobertson Posted - Aug 20 2023 : 22:08:38
I have confirmed that setting PixelFormat in the beta updates BitsPerSample/SamplesPerPixel in TImageEnMIO.

Jon
JonMRobertson Posted - Aug 18 2023 : 22:30:36
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. ;)
xequte Posted - Aug 18 2023 : 21:57:22
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
JonMRobertson Posted - Aug 18 2023 : 21:35:18
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
xequte Posted - Aug 18 2023 : 19:01:26
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
JonMRobertson Posted - Aug 18 2023 : 15:23:12
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