The challenge is as follows:

There is a generic system (most likely an embedded one) that has a buffer of images (frames of a video), attached to a screen (resolution of [640 x 480] on both screen and buffer):

 

 

The buffer is a 2D set of pixels, and the first pixel is the top-left most of the image. Each pixel has 16 Bits and it is stored as follows:

 

[Red | Green | Blue]

00000 000000  00000

 

Red has 5 BitsGreen has 6 Bits, and Blue has 5 Bits. This is how a single pixel stores the 3 colors (right part is least significant). The objective is to overlay another image on the buffer (like the subtitles of a movie, or a mouse cursor on top of a background image). This image is a [32 x 32] pixels, and it will be put on a given coordinate (X,Y) of the buffer. A slight drawback is that this smaller image has its pixels stored with 32 Bits as follows, so you will have to have this fact taken into account later:

[Red       |     Green    |     Blue      |     Alpha]

  00000000    00000000     00000000    00000000   

 

Every channel has 8 Bits this time. This is how a single pixel stores the 3 colors (right part is the least significant). The Alpha is the opacity of the pixel. Will Alpha be used in this problem? Yes. How? If Alpha is 100%, the pixel of the smaller image will be completely opaque; if it is 0%, the color will be fully transparent (values in between will fade the color accordingly). The solution would be:

 

 

This is a challenge to be accomplished with any programming language and any type of implementation (that is, how you structure it, which data types you choose, totaly up to you as long as you do the task in an efficient way).

 

Function signature:

overlayImageBuffer ([IN/OUT] buffer, [IN] img2Mix, [IN]  xCoord, [IN]  yCoord)

 

 

Solution: overlayImageInBuffer.cpp

I coded my interpretation of the solution in C++. I used 2D buffer arrays of type char (because C does not provide native data types of neither 16 nor 32 Bits). There is a point that, because the [32 x 32] image has pixels of 32 Bits and not just 16 Bits, I had to choose how to fit those 8 Bit [R|G|B] values into [R|G|B] of 5 and 6 Bits. I chose to use the least significant digits, hence making it an implementation choice.

 

 

Anyhow, above is the complete code. 

 

 

Published By fxsf às 03:02