PXC_SetCompression and PXC_AddImageFromHBITMAP

This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's PDF-Tools SDK of Library DLL functions(only) - Please use the PDF-XChange Drivers API SDK Forum for assistance with all PDF Print Driver related topics or PDF-XChange Viewer SDK if appropriate.

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan

Post Reply
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

PXC_SetCompression and PXC_AddImageFromHBITMAP

Post by jeffp »

I'm creating a PDF document using the Dibs coming in from a scanner. Since I use Delphi, I'm converting the DIBs to a TBitmap.Handle to pass to your PXC_AddImageFromHBITMAP function.

I'm having an issue with file sizes. The scanner is set to B&W with a DPI of 300. If I scan to TIF, the TIF file size for one page is 55K. When I scan to PDF and create the PDF doc using PXC_AddImageFromHBITMAP and PXC_SetCompression, my file size is 90K or about double.

Is there something else I need to be doing when I create a PDF page using PXC_AddImageFromHBITMAP to get my file size smaller? Is the order in which I call the functions correct?

Below is the relevant code I'm using so you can see what I'm setting for AddImageFromHBITMAP. This code is call each time as I get a DIB from the scanner. When I'm done, I just Save the document out using SaveDocument.

By the way, the TIF is using CCITTFAX4 compression on the BW image.

Code: Select all

if (FDocID = 0) then
begin
  hr := PXC_NewDocument(@FDocID, FRegKey, FDevCode);
  if IS_DS_FAILED(hr) or (FDocID = 0) then exit;
end;

PXC_SetCompression(FDocID, True, False, ComprType_C_Deflate, 75, ComprType_I_Deflate, ComprType_M_Deflate);

PXC_AddPage(FDocID, W, H, @hPage);
PXC_AddImageFromHBITMAP(FDocID, B.Handle, 0, @hImg);
PXC_PlaceImage(hPage, hImg, 0, H, W, H);
User avatar
Lzcat - Tracker Supp
Site Admin
Posts: 677
Joined: Thu Jun 28, 2007 8:42 am

Re: PXC_SetCompression and PXC_AddImageFromHBITMAP

Post by Lzcat - Tracker Supp »

You should set last parameter of PXC_SetCompression to ComprType_M_CCITT3, ComprType_M_CCITT4 or ComprType_M_JBIG2. In your sample you forced pxclib40 to use deflate compression for 1bp images, which is not effective.
Victor
Tracker Software
Project manager

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: PXC_SetCompression and PXC_AddImageFromHBITMAP

Post by jeffp »

Ok. That make sense.

Also, what are "Indexed" images? and what compression do you believe is the best default for Color/Grayscale images? Does the "Auto" setting do a good job?
User avatar
Lzcat - Tracker Supp
Site Admin
Posts: 677
Joined: Thu Jun 28, 2007 8:42 am

Re: PXC_SetCompression and PXC_AddImageFromHBITMAP

Post by Lzcat - Tracker Supp »

pxclib40 support four kind of images: TrueColor (24-bit RGB, each byte represent color component), Grayscale (8-bit gray, each byte represent gray level), Indexed (color image, up to 256 different colors, use indexes in color palette), and Monochrome (1-bit black and white images).
For TrueColor and Grayscale images best compression depends on image content - JPEG/JPEG2000 is good for a photos and similar pictures, but not for screenshots/diagrams Deflate compression gives much better quality and in many cases better compression ratio.
For Indexed images only LZW and Deflate compressions are acceptable, and Deflate almost always gives better compression ratio.
For Monochrome images best compression method also depends on image. For scanned "paper" documetns CCITT3 and CCITT4 almost always produces the best results (maybe in combination with deflate compression), for other (like photos in newspapers) - JBIG2 compression is better.
Auto setting tries to select the better method depending on the image type, and for now for TrueColor/Grayscale images it is equal to ComprType_C_JPEG_Deflate (compress using JPEG algorithm and than use deflate - in most cases this will give better result that single JPEG), for Indexed - ComprType_I_Deflate, and for Monochrome - ComprType_M_CCITT4 | ComprType_M_Deflate (use CCITT4 and deflate later). So in most cases you do not need to change compression type to get good results.
HTH.
Victor
Tracker Software
Project manager

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: PXC_SetCompression and PXC_AddImageFromHBITMAP

Post by jeffp »

I have a follow up question on this thread.

If the image that I'm giving you to compress is always coming from a scanner and being added using the PXC_AddImageFromHBITMAP function, does the information in the HBITMAP that I pass give the information to determine what type of image it is and therefore what compression method you use.

For example, in the scanner settings, a user can select to scan as B&W, Grayscale, Color, etc. As such, does the resulting HBITMAP then tell you whether you have a Color/Grayscale, Indexed, or Monochrome image? Can you have an Indexed image coming from a Scanner? Or is that just for existing files?

Thanks.
User avatar
Lzcat - Tracker Supp
Site Admin
Posts: 677
Joined: Thu Jun 28, 2007 8:42 am

Re: PXC_SetCompression and PXC_AddImageFromHBITMAP

Post by Lzcat - Tracker Supp »

Yes, Image compression is dependant on the HBITMAP format, but if the scanner produce 24-bit HBITMAP even when a user selects B&W mode - we can do nothing with this.

From an HBITMAP we can create indexed (1 and 8 bit per pixel) and 24-bit images, later they may be converted to monochrome/gray-scale/indexed if this can be done without loosing any color information.

If you want to have more control over conversion you may use IMG_PageCreateFromHBITMAP and PXC_AddImageFromImageXChangePage functions to get the same/similar results. But such code will allow you to transform _XCPage before calling the PXC_AddImageFromImageXChangePage function (using our Image-XChange API), so you can always "correct" images if needed.

HTH.
Victor
Tracker Software
Project manager

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
Post Reply