Page 1 of 1

Convert YUV2 to JPEG

Posted: 2011-02-08T07:02:29-07:00
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);
			}
       }




Re: Convert YUV2 to JPEG

Posted: 2011-02-08T07:22:04-07:00
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.

Re: Convert YUV2 to JPEG

Posted: 2011-02-08T07:27:24-07:00
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?

Re: Convert YUV2 to JPEG

Posted: 2011-02-08T07:30:47-07:00
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

Re: Convert YUV2 to JPEG

Posted: 2011-02-08T07:44:44-07:00
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.

Re: Convert YUV2 to JPEG

Posted: 2011-02-08T07:47:43-07:00
by abeckers
it is 16 bits per pixel

Re: Convert YUV2 to JPEG

Posted: 2011-02-08T07:49:19-07:00
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.

Re: Convert YUV2 to JPEG

Posted: 2011-02-08T07:51:41-07:00
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'

Re: Convert YUV2 to JPEG

Posted: 2011-02-08T07:55:27-07:00
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?

Re: Convert YUV2 to JPEG

Posted: 2011-02-08T07:59:34-07:00
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

Re: Convert YUV2 to JPEG

Posted: 2011-02-08T10:42:14-07:00
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.

Re: Convert YUV2 to JPEG

Posted: 2011-02-09T00:19:28-07:00
by abeckers
Thanks for the information. I will test the new version!