Compare & Compression (C++)
Posted: 2009-04-14T05:53:07-07:00
Hello everybody! I'm new to ImageMagick so I apologize ahead of time if this question is already answered in the documentation, but I was unable to find it. So here it goes...
Right now I'm writing a C++ tool that tries various methods of compression/quality/etc in order to get a small filesize without losing too much quality of the image. Basically I was planning of having a loop that cycles the quality if an Image down one point at a time until the difference between it and the original Image reaches a threshold. ( Just to add, I'm initially loading up a PNG32, but this current compression loop converts it to JPEG ) Here is the problem I'm having. Right now I have a loop that looks something like this...The problem is that compare seems to only update meanErrorPerPixel, normalizedMaxError, and normalizedMeanError, and even then only if the Image has been quantized, never taking into account the current quality of the Image. I ran a few loops with some outputs and it does appear that the filesize of the image is going down, but the compare values stay consistently at 0 unless I call quantize(), where they always stay at the same value depending on how I specify the quantize values.
In the end, I'd like to download the quality of the JPG until the number of pixels that change reaches a certain threshold. This is purely a brute-force approach, nothing fancy. Thanks ahead of time for your help.
Right now I'm writing a C++ tool that tries various methods of compression/quality/etc in order to get a small filesize without losing too much quality of the image. Basically I was planning of having a loop that cycles the quality if an Image down one point at a time until the difference between it and the original Image reaches a threshold. ( Just to add, I'm initially loading up a PNG32, but this current compression loop converts it to JPEG ) Here is the problem I'm having. Right now I have a loop that looks something like this...
Code: Select all
while( /*Check to see if difference threshold is met && imageJPG.quality() > 1*/ )
{
imageJPG.quality( imageJPG.quality() - 1 );
imageBase.compare( imageJPG );
}
In the end, I'd like to download the quality of the JPG until the number of pixels that change reaches a certain threshold. This is purely a brute-force approach, nothing fancy. Thanks ahead of time for your help.