[Magick++], JPEG Sampling Factor

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
Im Jinho

[Magick++], JPEG Sampling Factor

Post by Im Jinho »

Environment
- Visual Studio 2008
- Magick++

Hi, everyone.

I'm using work with Magick++.
I want to change sampling Factor of JPEG format from any image format for output file .

YUV420 : 2x2, 1x1, 1x1
YUV422 : 2x1, 1x1, 1x1

In case Color Space setting, there is colorSpace() Method.
like this, is there any method of Image class for this setting?
If not, how to change sampling Factor of image?

can I get some sample code to change sampling Factor of JPEG format image?

thank you for this question..
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: [Magick++], JPEG Sampling Factor

Post by magick »

Use defineValue() and set the magick to JPEG, key to sampling-factor, and the value to your desired sampling factors (e.g. 1x1,2x2,2x2).
Im Jinho

Re: [Magick++], JPEG Sampling Factor

Post by Im Jinho »

Hi.
First of all thanks for your help
I have been test as your advice, but I can't get any target that I want.

Here is sample code;
================================================================================

Code: Select all

if( m_outputFormat == "jpg" || m_outputFormat == "jpeg" ) {
	ColorspaceType colorSpace;
	std::string key = "sampling-factor";//"sampling_factor";

	if( YUV422 ) {
	//YUV422
	magick = "JPEG";
	samplingFactor = "2x1,1x1,1x1";
	colorSpace = YCbCrColorspace;
}
else {
                  //YUV420
	magick = "JPEG";
	samplingFactor = "2x2,1x1,1x1";
	colorSpace = YCbCrColorspace;
}
					
imageVector[i].magick( magick );
imageVector[i].defineValue( magick, key, samplingFactor );

defineValue   ->   modifyImage()

void Magick::Image::modifyImage()
{
    Lock( &_imgRef->_mutexLock );
    if ( _imgRef->_refCount == 1 )
      {
        // De-register image and return
        _imgRef->id( -1 );
        return;
      }
}
================================================================================

value of _imgRef->_refCount in modifyImage() is 1.
So just return without following step processing, replaceImage().

What is a reason that cause this problem.
And how can I resolve this Image processing.

thanks!!
Im Jinho

Re: [Magick++], JPEG Sampling Factor

Post by Im Jinho »

I have resolved above problem, to set sampling factor of image option, with CloneString().

Code: Select all

imageVector[i].magick( magick );
MagickCore::ImageInfo *info = imageVector[i].options()->imageInfo();
MagickCore::CloneString(&info->sampling_factor, samplingFactor.c_str());
thanks.
Post Reply