Ok, I've finally snapped

    I was just writing some code to manipulate a bitmap, something I need to do for my PhD (specifically, I'm converting YUV420P to RGB24). Anyhoo, the image isn't looking right, so before I go to sleep on it I thought I would dump the YUV values next to the RGB ones and see if I could eyeball the problem.

    I swear that as I was writing this I was thinking -- "I'll let the compiler optimise and write for readability". Do you think I succeeded?

      
      for(x = 0; x < 320; x++)
      
          {
      
            for(y = 0; y < 240; y++)
      
      	{
      
      	  raster[((y + 480) * 640 * 2 + x + 640) * 3] = 
      
      	    realfile[640 * 480 + (y * 320 + x)];
      
      	  raster[((y + 480) * 640 * 2 + x + 640) * 3 + 1] = 
      
      	    realfile[640 * 480 + (y * 320 + x)];
      
      	  raster[((y + 480) * 640 * 2 + x + 640) * 3 + 2] = 
      
      	    realfile[640 * 480 + (y * 320 + x)];
      
      
      
      	  raster[((y + 480) * 640 * 2 + x + 640 + 320) * 3] = 
      
      	    realfile[640 * 480 + (320 * 240) + (y * 320 + x)];
      
      	  raster[((y + 480) * 640 * 2 + x + 640 + 320) * 3 + 1] = 
      
      	    realfile[640 * 480 + (320 * 240) + (y * 320 + x)];
      
      	  raster[((y + 480) * 640 * 2 + x + 640 + 320) * 3 + 2] = 
      
      	    realfile[640 * 480 + (320 * 240) + (y * 320 + x)];
      
      	}
      
          }
      
      


    Here's the image I get at the moment:



    See how the RGB image on the left isn't colorful enough? That pen there is lime green. Anyways, if anyone can see the problem and wants to give me a hint, that would be cool too.

    Update: It would seem that the terms YUV420, YUV420P, iYUV, and I420 are all interchangeable, to add to the fun. [tags: yuv rgb color space convert code]

posted at: 17:46 | path: /phd | permanent link to this entry

    Add a comment to this post:

    Your name:

    Your email: Email me new comments on this post
      (Your email will not be published on this site, and will only be used to contact you directly with a reply to your comment if needed. Oh, and we'll use it to send you new comments on this post it you selected that checkbox.)


    Your website:

    Comments: