Product Ideas

Improve compression selection in sample project (ImageGear Pro)

As a developer, I would like to make the ImageGear Pro sample, PDF/AddNewPageWithImage, better. In the code at AddNewPageWithImage.cpp:497, the following snippet is used to select an image compression algorithm based on the image's properties:

// Set image compression.
enumIGCompressions nCompression = IG_COMPRESSION_NONE;
if (1 == bpp)
{

nCompression = IG_COMPRESSION_CCITT_G4;

}
else if (2 <= bpp && bpp <= 8)
{

nCompression = IG_COMPRESSION_DEFLATE;

}
else if (24 == bpp || 32 == bpp)
{

nCompression = IG_COMPRESSION_DEFLATE;

}
else
{

nCompression = IG_COMPRESSION_NONE;

}

 

Compression can be improved by using:

else if (24 == bpp || 32 == bpp)
{

nCompression = IG_COMPRESSION_JPEG;

}

 

Additionally, the last else statement is redundant, as nCompression would already be IG_COMPRESSION_NONE.

 

So the improved snippet would look like:

// Set image compression.
enumIGCompressions nCompression = IG_COMPRESSION_NONE;
if (1 == bpp)
{

nCompression = IG_COMPRESSION_CCITT_G4;

}
else if (2 <= bpp && bpp <= 8)
{

nCompression = IG_COMPRESSION_DEFLATE;

}
else if (24 == bpp || 32 == bpp)
{

nCompression = IG_COMPRESSION_JPEG;

}

  • Guest
  • Jul 25 2017
  • Attach files