Convert YUV2 to JPEG

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
abeckers
Posts: 8
Joined: 2011-02-08T06:51:15-07:00
Authentication code: 8675308

Convert YUV2 to JPEG

Post by abeckers »

Hello together,

i have a problem to convert a yuv2 file to jpeg with the magicwand api.
Ich want to convert the image but the result is always wrong. The color or brightness is wrong.
In my opinion, the image has YUV2 Format knows as YUYV.

When ich convert the image first witrh a c function to rgb, than i can convert it to jpeg.
Is threre a way to convert the YUV2 image direkt to JPEG?

Code:

Code: Select all

	

	double factors211[3] = {2.0,1.0,1.0};
        double factors422[3] = {4.0,2.0,2.0};

        wand = NewMagickWand();
	dwand = NewDrawingWand();


	status = MagickSetFormat(wand, "yuv");
	if(status != MagickTrue) {
		ThrowWandException(wand);
	}

	status = MagickSetSize(wand, 768, 288);
	if(status != MagickTrue) {
		ThrowWandException(wand);
	}

	status = MagickSetDepth(wand, 16);
	if(status != MagickTrue) {
		ThrowWandException(wand);
	}

	status = MagickSetSamplingFactors(wand, 3, factors422);
	if(status != MagickTrue) {
		ThrowWandException(wand);
	}

	status = MagickReadImageBlob(wand, pic, picsize);
	if(status == MagickTrue) {

			size_t compression = 70;

			status = MagickSetFormat(wand, "JPG");
			if(status != MagickTrue) {
				ThrowWandException(wand);
			}

			status = MagickSetImageDepth(wand, 8);
			if(status != MagickTrue) {
				ThrowWandException(wand);
			}

			status = MagickSetSamplingFactors(wand, 3, factors211);
			if(status != MagickTrue) {
				ThrowWandException(wand);
			}

			status = MagickSetImageCompressionQuality(wand, compression);
			if(status != MagickTrue) {
				ThrowWandException(wand);
			}

			status = MagickWriteImage(wand, filename2);
			if(status != MagickTrue) {
				ThrowWandException(wand);
			}
       }



User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Convert YUV2 to JPEG

Post by magick »

YUV is responsive to the interlace and sampling factor parameters. By default, YUV is 4:2:2. If you instead want to read CCIR 601 4:1:1, use the MagickSetSamplingFactors() method before you read your YUV image file.
abeckers
Posts: 8
Joined: 2011-02-08T06:51:15-07:00
Authentication code: 8675308

Re: Convert YUV2 to JPEG

Post by abeckers »

No the YUV is 422. When i use MagickSetSamplingFactors with 411 the function MagickReadImageBlob has an exception.
Can i upload the testimage here?
abeckers
Posts: 8
Joined: 2011-02-08T06:51:15-07:00
Authentication code: 8675308

Re: Convert YUV2 to JPEG

Post by abeckers »

Here ist my testimage:
http://www.abeckers.de/testpic.yuv

If i use a tool such as YUVTools, i can load the image an see it correct with the following setup:
YUYV , YUV422, Progressive, Packed
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Convert YUV2 to JPEG

Post by magick »

ImageMagick can't read the image at all. Try
  • convert -size 768x288 testpic.yuv -colorspace rgb testpic.png
It returns an exception. Is this image 8 or 16-bits per pixel? If its 16, we'll need to add a patch to the YUV coder to support it.
abeckers
Posts: 8
Joined: 2011-02-08T06:51:15-07:00
Authentication code: 8675308

Re: Convert YUV2 to JPEG

Post by abeckers »

it is 16 bits per pixel
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Convert YUV2 to JPEG

Post by magick »

Is there a standard for 16-bit YUV? Is 16-bit YUV in MSB or LSB word order or is support for both orders required (with -endian option)?

Look for a patch in ImageMagick 6.6.7-7 Beta by this weekend to support 16-bit YUV 4:2:2 and YUV 4:1:1.
abeckers
Posts: 8
Joined: 2011-02-08T06:51:15-07:00
Authentication code: 8675308

Re: Convert YUV2 to JPEG

Post by abeckers »

magick wrote:ImageMagick can't read the image at all. Try
  • convert -size 768x288 testpic.yuv -colorspace rgb testpic.png
It returns an exception. Is this image 8 or 16-bits per pixel? If its 16, we'll need to add a patch to the YUV coder to support it.
The answer is: Magick: unexpected end-of-file `d:\testpic.yuv'
abeckers
Posts: 8
Joined: 2011-02-08T06:51:15-07:00
Authentication code: 8675308

Re: Convert YUV2 to JPEG

Post by abeckers »

magick wrote:Is there a standard for 16-bit YUV? Is 16-bit YUV in MSB or LSB word order or is support for both orders required (with -endian option)?

Look for a patch in ImageMagick 6.6.7-7 Beta by this weekend to support 16-bit YUV 4:2:2 and YUV 4:1:1.
is there any compiled binary beta release for windows?
abeckers
Posts: 8
Joined: 2011-02-08T06:51:15-07:00
Authentication code: 8675308

Re: Convert YUV2 to JPEG

Post by abeckers »

When i use :
convert -size 768x288 -sampling-factor 4:2:2 yuv:d:\testpic.yuv -colorspace rgb png:d:\testpic.png

the png image is green, such as the jpg with the same command:
convert -size 768x288 -sampling-factor 4:2:2 yuv:d:\testpic.yuv jpg:d:\testpic.jpg
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Convert YUV2 to JPEG

Post by magick »

ImageMagick does not currently support 16-bit YUV images so an exception is expected. We'll have a patch for the problem in ImageMagick 6.6.7-7 Beta within a few days.
abeckers
Posts: 8
Joined: 2011-02-08T06:51:15-07:00
Authentication code: 8675308

Re: Convert YUV2 to JPEG

Post by abeckers »

Thanks for the information. I will test the new version!
Post Reply