Re: Problem with DirectX6 -> DDSURFACEDESC2 structure and lpSurface

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Fabian Schmied (REMOVETHISfabianDOTschmied_at_fhs-hagenbergDOTacDOTat)
Date: 12/02/04


Date: Thu, 02 Dec 2004 11:09:11 +0100


> i've got one little problem with copying my own data acquired from custom
> image file format into the lpSurface.
> I've tried almost everything, but i simply don't know how to setup
> DDSURFACEDESC2.
> I copied 24-bit RAW RGB image into the lpSurface and there was some sort
> of
> graphics corruption in the loaded image, i think it's all in
> DDSURFACEDESC2......
> So i am interested...what's the problem......???

When locking a surface, you do not yourself setup the DDSURFACEDESC2
(apart from setting its size). It gets filled by the Lock method.

You are probably not doing any color conversion. When you copy anything
onto a locked DirectDraw surface, you need to make sure that you use the
right data format. Writing raw 24-bit RGB data to the surface pointer only
works if the surface has a pixel format of 24-bit RGB (in this order, that
is red first, then green, then blue). Many graphics cards do not have
24-bit surface formats, but actually use 32 bits, with an additional alpha
byte (which may not be used at all).

So, what you need to do is take a look at the surfaceDesc.ddpfPixelFormat
information. It has a dwRGBBitCount member, which tells you, how many bits
each pixel takes (4, 8, 16, 24, or 32). And you need to take a look at the
color masks (dwRBitMask, etc), which tell you how many bits each color (R,
G, B) takes and and where it is located in the pixel value.

Then you need to truncate (or scale) the original 8-bit red, green, and
blue values so that they only take the right amount of bits for the target
surface (for example 5 bits red, 6 bits green, 5 bits blue for a 16-bit
surface with "RGB565" pixel format; note that other formats are also
possible, e.g. BGR and similar). Now you shift the truncated values to
their positions in the new pixel value and combine them using bitwise OR.

Take a look at this [1] tutorial by Michael Fötsch, he explains all of
this very well.

Fabian

[1] http://www.geocities.com/foetsch/locking/locking.htm



Relevant Pages

  • Re: Representing image data
    ... any application that uses raster image data. ... row and store it in a format appropriate for the application. ... With ImageMagick the only way to change the pixel format is to ... interface to return a pointer to an array of pixels; ...
    (comp.lang.ada)
  • Re: [PATCH 2/3] mx3_camera: Support correctly the YUV222 and BAYER configurations of CSI
    ... The YUV422 format is managed to be converted in IPU internal YUV444 format ... That's why there is a first handshake of the pixel format in mx3_camera_get_formats ... This translation is not needed with the tools I introduce in this patch ...
    (Linux-Kernel)
  • Re: colors are slightly off importing gifs and bmps
    ... Since the problem is clearly in pixel format not matching what you have on ... >> If you tried to bit shift each pixel in your image, on demand, then this ... >> Tim Wilson ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Pixel format conversion
    ... > I want to convert one pixel format to another pixel format. ... > and from 8bit RGB to 16 RGB is ... and then shift them so they cover the most significant (i.e. left ...
    (comp.graphics.algorithms)
  • RE: How to copy YUV planar formats data(YV12,I420,YVU9 ) to Direct
    ... Sir, It's true, to transform Planer into Packed format when DirectDraw ... Planer YUV pixel format DirectDraw surface. ...
    (microsoft.public.win32.programmer.directx.video)