Board index » delphi » CopyRect/cmSrcInvert different with 16 and 256 colours

CopyRect/cmSrcInvert different with 16 and 256 colours

I am creating an application where I need to do XOR copying of bitmaps
from one canvas to another. I have been developing on a machine using 256
colours and have just gone to test on a standard 16 colour VGA machine.
The copyrect function using the cmSrcInvert gives different results with
the different colour depths.

Using the code below, I get what I consider to be the correct result on
the 256 colour machine, ie the text turns out blue, but on the 16 colour
machine it turns out yellow.

Can anybody point me towards the cause of this?

var
  rc: TRect;
begin
  with image1.canvas do begin
    brush.style := bsSolid;
    brush.color := clBlack;
    rc := Rect(0,0,Width,Height);
    fillrect(rc);
    font.color := clOlive;
    textout(10,10,'Sample text');
  end;
  with image2.canvas do begin
    brush.style := bsSolid;
    brush.color := clSilver;
    fillrect(Rect(0,0,Width,Height));
    copymode := cmSrcInvert;
    CopyRect(rc, image1.canvas, rc);
  end;

end;

--
David Willis

 

Re:CopyRect/cmSrcInvert different with 16 and 256 colours


Quote
>I am creating an application where I need to do XOR copying of bitmaps
>from one canvas to another. I have been developing on a machine using 256
>colours and have just gone to test on a standard 16 colour VGA machine.
>The copyrect function using the cmSrcInvert gives different results with
>the different colour depths.
>Using the code below, I get what I consider to be the correct result on
>the 256 colour machine, ie the text turns out blue, but on the 16 colour
>machine it turns out yellow.
>Can anybody point me towards the cause of this?

 . . .<snip>
I think I ran into this problem a few time, when you use a different
driver/color depth windows has a different palette so it maps the colors to
the closes color in the palette . . .
solution, create your own palette ( how you say, I don't know since my video
driver is screwed up, I get incosisten results and limited color depth,
although there are a couple of win API's CreatePalette, RealizePalette .. .)
cpm

Re:CopyRect/cmSrcInvert different with 16 and 256 colours


In article: <cmasgras.60.30390...@postbox.acs.ohio-state.edu>  

Quote
cmasg...@postbox.acs.ohio-state.edu (Cris Masgras) writes:

> >I am creating an application where I need to do XOR copying of bitmaps
> >from one canvas to another. I have been developing on a machine using 256
> >colours and have just gone to test on a standard 16 colour VGA machine.
> >The copyrect function using the cmSrcInvert gives different results with
> >the different colour depths.

> >Using the code below, I get what I consider to be the correct result on
> >the 256 colour machine, ie the text turns out blue, but on the 16 colour
> >machine it turns out yellow.

> >Can anybody point me towards the cause of this?

>  . . .<snip>
> I think I ran into this problem a few time, when you use a different
> driver/color depth windows has a different palette so it maps the colors to
> the closes color in the palette . . .
> solution, create your own palette ( how you say, I don't know since my video
> driver is screwed up, I get incosisten results and limited color depth,
> although there are a couple of win API's CreatePalette, RealizePalette .. .)
> cpm

Yes, I thought that might be the case, that was why I tried the code given which
does not load any bitmaps, it purely uses the standard system colours to produce a
bitmap at run-time. The implication is that although clSilver and clOlive both
exist in the standard VGA palette, the XORed value does not.

IE, clSilver is $C0C0C0, clOlive is $008080, the XORed value is $C04040 which I
guess is approximated under VGA giving a different result than under 256 colour
SVGA.

Is there any way to realise palettes to get around this?

--
David Willis

Re:CopyRect/cmSrcInvert different with 16 and 256 colours


Well my workaround for this is to realize the palette in the source
in the destination. Ie if the source is a bitmap canvas (I assume it
is), the get the bitmap palette and select that into the destination
palette, call RealizePalette in the target palette.
Here is very quick code cut out of a program..

   DC := Canvas.Handle;
   OldPaletteD := SelectPalette(DC, bitmap.Palette,false);
   RealizePalette(DC);
   Canvas.CopyRect(cliprect,bitmap.canvas,p);
   SelectPalette(DC, OldPaletteD,false);

--------------------------------------------------------------------
Phil Scadden, Scadden Research, P.Scad...@gns.cri.nz
55 Buick St, Petone, Lower Hutt
New Zealand, Ph ++64 4 5687190, fax ++64 4 5695016

Other Threads