Re: Problem with ATLs CImage and SetPixelIndexed

Tech-Archive recommends: Fix windows errors by optimizing your registry



OK, thanks Scot. It looks like I have got to do a bit more
experimenting to properly understand. At least I am a bit further on
with your information. Cheers

Simon


On 24 May, 08:50, "Scot T Brennecke" <Sc...@xxxxxxxxxxxxxxxxxx> wrote:
The trap you've fallen into is assuming that the color table in the DIB section is the same as the
palette selected into the DC.  When you call SetPixelIndexed, you are telling it to use the index of
a palette entry, which is not the same as an index into the color table.  To get the results you are
expecting, you will need to do this:

SetPixel(0, 0, DIBINDEX(0));
SetPixel(0, 1, DIBINDEX(1));
SetPixel(1, 0, DIBINDEX(2));
SetPixel(1, 1, DIBINDEX(3));

The world of bitmaps, palettes, DIBs, DDBs, etc. can be very complicated and confusing.  This is
partly because of a need to support a long legacy of ancient formats and techniques, as well as to
provide numerous ways to provide efficient abstractions so that color schemes can be swapped out
easily.  I'm sure there are other reasons why it has become a "mess".  I suggest that if you need to
get into this world, you do some more intense reading of the myriad of articles "out there" on these
topics.

<renegade_master_12...@xxxxxxxxxxx> wrote in message

news:d36908a6-93ff-44fa-b833-53f1da186c3f@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Hi,

I want to do the following using the ATL CImage class.  (This is a
stripped down version of what I really need)...  Create a 4 bits per
pixel bitamp which is 2 pixels by 2 pixels Set a color table
(palette).  Set the pixels (via palette index).   I just can't get it
to work. Either I am missing the point or this stuff is bugged.
Here's my example code

#include <atlimage.h>

......

CImage image;
image.Create(2, 2, 4, 0);

RGBQUAD colors[16];
ZeroMemory(&colors, sizeof(colors));
colors[0].rgbBlue = 0xAA;
colors[0].rgbGreen = 0xBB;
colors[0].rgbRed = 0xCC;
colors[0].rgbReserved = 0;

colors[1].rgbBlue = 0xDD;
colors[1].rgbGreen = 0xEE;
colors[1].rgbRed = 0xFF;
colors[1].rgbReserved = 0;

colors[2].rgbBlue = 0xAB;
colors[2].rgbGreen = 0xCD;
colors[2].rgbRed = 0xEF;
colors[2].rgbReserved = 0;

colors[3].rgbBlue = 0xBC;
colors[3].rgbGreen = 0xBA;
colors[3].rgbRed = 0xBD;
colors[3].rgbReserved = 0;

colors[4].rgbBlue = 0x12;
colors[4].rgbGreen = 0x12;
colors[4].rgbRed = 0x12;
colors[4].rgbReserved = 0;

colors[5].rgbBlue = 0x22;
colors[5].rgbGreen = 0x22;
colors[5].rgbRed = 0x22;
colors[5].rgbReserved = 0;

colors[6].rgbBlue = 0x33;
colors[6].rgbGreen = 0x33;
colors[6].rgbRed = 0x33;
colors[6].rgbReserved = 0;

      ....

image.SetColorTable(0, 16, colors);

image.SetPixelIndexed(0,0,0);
image.SetPixelIndexed(0,1,1);
image.SetPixelIndexed(1,0,2);
image.SetPixelIndexed(1,1,3);

COLORREF c00 = image.GetPixel(0,0); //returns 0x00000000 (expecting
AABBCC...)
COLORREF c01 = image.GetPixel(0,1); //returns 0x33333333 (expecting
DDEEFF...)
COLORREF c10 = image.GetPixel(1,0); //returns 0x33333333
COLORREF c11 = image.GetPixel(1,1); //returns 0x33333333

Can anyone help?  I am at my wits end with this :-(

.



Relevant Pages

  • Re: Questions on GS/OS Icon ($CA) files
    ... this area of IIgs programming) but my functioning IIgs is at work (where ... Most IIgs icon files are created with an icon editor application running ... pixels are encoded. ... palette rather than RGB values. ...
    (comp.sys.apple2)
  • Re: What am I doing wrong here? Trying to draw 10 lines, multiple colors
    ... Therefore you change the color of the palette entry 1 and then plot ... the new pixels with color 1. ... Saves the current video mode, ... the video mode to its original value. ...
    (alt.lang.asm)
  • Re: can anyone tell me why I get an error at line 19 with NASM?
    ... could be 'inc di' followed by 'inc cx' causing this ... I usually find that when the sun rises and the glare makes the monitor ... Maybe we can alter the palette to something prettier, ... Anyway, dream of pretty pixels! ...
    (alt.lang.asm)
  • Re: creating a .bmp file
    ... ie i have 256 color pallete of RGBquads and array of 8bit pixels, ... but it doesnt seem to let me set the color palette, ... the Microsoft knowledge base includes this suggestion to create a dummy bitmap and grab the palette from that before disposing the dummy bitmap: ... And barring either of those methods working out for you, it's not like it's really all that difficult to write the BMP file from scratch, even if it is annoying. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: STATISTIC:how many megapixels enough for you?
    ... (now experimenting with changing from scanned 4x5 ... film to digital mosaics). ... million pixels from scanned 4x5" film. ... The incremental number of pixels per frame would be a lot larger, ...
    (rec.photo.digital)