Solved

Delphi Programming question

Posted on 1997-08-31
14
179 Views
Last Modified: 2010-04-04
Can anybody out there in Delphi-Land please give me a clear explanation of the significance of the highest order byte in a TColor? The TColor entry in Delphi help does not really explain what this means in practical terms at all (at least, not to a graphics dumb-ass like me).

I've tried FloodFill(ing) the canvas of a bitmap with
various TColors and then changing only the highest order
byte: in 256 color graphics mode a highest order byte value
of $00 or $02 seems to result in the same color, except when the $00 color was a dithered color, in which case changing it to $02 seems to result in a solid color with little
resemblance to the $00 dithered color. In high color or true
color graphics modes $00 or $02 seems always to result in
the same color. In all graphics modes setting the highest
order byte of a TColor to $01 seems always to result in pure
black (!?).

Can anyone tell me what the actual practical implications of
these highest order byte values are? Under what
circumstances would you specify $00 or $01 or $02 in a
TColor, and WHY??

Thankyou in advance to anyone with the patience to clarify
this for me.
0
Comment
Question by:SteveMG
  • 6
  • 5
  • 2
  • +1
14 Comments
 
LVL 1

Expert Comment

by:sassas081597
Comment Utility

If the highest-order byte is zero ($00), the color obtained is the closest matching color in the system palette. If the highest-order byte is one ($01), the color obtained is the closest matching color in the currently realized palette. If the highest-order byte is two ($02), the value is matched with the nearest color in the logical palette of the current device context.
So if your Video Card (or other Device i.e. Printer ect.) cannot realize TrueColor with current resolution then and only then this first byty will play a role. It says the Card which of the nearest colors the Card can realize with current resolution and color Depth to show.
0
 

Author Comment

by:SteveMG
Comment Utility
The first part of this answer just restates the relevant Delphi help system help on TColor. My question makes it abundantly clear that I have already read this help topic and found it NOT to be an adequate explanation.

The second part of this answer is simply no answer either: the results of my little 'experiment' with the bitmap already make it clear that the highest order byte makes no difference in TrueColor mode, there is no point in re-stating this. The last sentence of this answer simply makes no sense whatsoever.

Let me restate:

 firstly I would like a clear explanation of the results of my bitmap 'experiment' for each highest-order byte value, including the puzzling results for $01;

secondly, and most importantly, I would like the last part of my question clearly answered, that is:

"Under what circumstances would you specify $00 or $01 or $02 in a TColor, and WHY??".

I do not need to know what Delphi help says on the subject or what my own question says on the subject.

Thanks very much for the attempt, sassas. Would someone else like to have a go at this one?  
0
 
LVL 3

Expert Comment

by:mirek071497
Comment Utility
I think so no good answer for you'r question in the world.
When i programming in colors i never need to know how high bute of TColor is used.
Tell me what you need to programming then mayby i can help you.
0
 

Author Comment

by:SteveMG
Comment Utility
Sorry Mirek; the Highest order byte specifier is there for a reason: what is that reason??
0
 
LVL 1

Expert Comment

by:AJFleming
Comment Utility
Hi Steve,

   I'm not going to reiterate what you and everyone else seems to
have already said so I'll assume you already know the significance of the various palettes you can choose from.

   I've never actually made use of the hibyte of TColor myself, and I'd like to hear from anyone who has. But so far as I can figure out, the idea of being able to specify which palette you want to pick a color from is probably to try and prevent palette clashes (you know that cool effect where your backdrop goes a really nasty shade of flourescent pink when you view an image.) Exactly how it goes about doing this I don't know and I'm not willing to guess.

   As I say, I'm not 100% sure that this is what you're looking for, but I can't think of any other reason why you'd need to specify a palette to grab from.

   good luck,
   Adam...
0
 

Author Comment

by:SteveMG
Comment Utility
Thanks, AJFleming, for your constructive input. This may have something to do with to my question, as you suggest; at least it seems a promising idea. If no-one out there really knows for sure  what this specifier really is, or how you really use it, I may have to end up writing to Borland or something to get them to explain! (Would anyone out there know a Borland email address I could use for such a question?)
0
 
LVL 1

Expert Comment

by:AJFleming
Comment Utility
Borland don't do support by email (according to their website) which sounds a little backwards to me, but I suppose they have to make their support money somewhere...

Having thought a little more carefully about it and done some checking around, I came accross the following:
    according to the Win32 SDK, colors are stored as 'RGBQUADS' which use 3 BYTEs to store the color and have a 1 BYTE reserved field which must be 0. So it's almost certainly a Borland thing.

Adam
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 3

Expert Comment

by:mirek071497
Comment Utility
Hi SteveMG i think so you'r problem is not in TColor but in understand what is System Palette, Logical Palette and Current Realized Palette.

Tell me what you can't understand mayby i can help you.
0
 

Author Comment

by:SteveMG
Comment Utility
Look, Mirek, my question is VERY clear, I've already repeated it twice, and at least one other person has understood what I'm asking (AJFleming). Read my question again if you need to, if you can't answer it then stop wasting everone's time.
0
 
LVL 3

Expert Comment

by:mirek071497
Comment Utility
Ok then i think so you know about palettes, but i don't understand why you ask this if you know. Mayby if you use this the result is not as described in HLP - I must try this.
Now i will try if all works fine, but tell me what version of Delphi, because between Delphi2 and Delphi3 is some differences for use of palettes.
0
 

Author Comment

by:SteveMG
Comment Utility
Thanks mirek. Yes, the results do not seem to make sense based on the help system's description of the pallettes. Maybe you could repeat my experiment and explain what's happenning and WHY (especially for $01).

My understanding of the palettes is based on what the VCL help  says about TColor and what the Windows API help says about RGB, PaletteIndex, and PaletteRGB. It could be that I am misinterpreting this information.

I am still using Delphi 2 (hope to upgrade to 3 soon!).

Thanks for troubling youself over this. After I asked about this in the newsgroups a while ago, I got several emails from other programmers who also had a problem with this (so at least it's not just me 8^) , but unfortunaltely I got no actual answer. If I can make sense of this I'll let those other guys know too!

Regards, SteveMG.
0
 
LVL 3

Accepted Solution

by:
mirek071497 earned 0 total points
Comment Utility
Ok. I try this and i found so all works fine i.e. as described in Help. You must be familiar with Palettes to understand this so i have example of how to use TColor.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    PaintBox1: TPaintBox;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

var
  MyPal       : HPalette;
  MyLPal      : PLogPalette;

procedure TForm1.FormCreate(Sender: TObject);
var
  i,j  : longint;
begin
  PaintBox1.Width := 16*10+1;
  PaintBox1.Height:= 16*10+1;
  { create palette }
  GetMem(MyLPal, (SizeOf(TLogPalette) + SizeOf(TPaletteEntry)*256));
  MyLPal^.PalVersion := $0300;
  MyLPal^.palNumEntries:=256;
  for i:=0 to 255 do
  begin
    MyLPal^.palPalEntry[i].peRed   := i;
    MyLPal^.palPalEntry[i].peGreen := i;
    MyLPal^.palPalEntry[i].peBlue  := i;
    MyLPal^.palPalEntry[i].peFlags := 0;
  end;
  MyPal := CreatePalette(MyLPal^);
  FreeMem(MyLPal, (SizeOf(TLogPalette) + SizeOf(TPaletteEntry)*256));
  { this is for omit Delphi algorithm of caching palettes }
  Button3Click( nil );
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  { free palette }
  DeleteObject(MyPal);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  i,j,k : integer;
  lk    : longint;
begin
  { example of Higest byte =01
    This show you current logical palette of PaintBox.
    Entries which is not assigned have
    the color clBlack as default.
    You need to use lk<=Number Of Palette Entries }

  lk := 0;
  PaintBox1.Canvas.Pen.Color := clBlack;
  for j:=0 to 15 do
  for i:=0 to 15 do
  begin
    PaintBox1.Canvas.Pen.Color := PaletteIndex(lk);
    { this line is the same }
    PaintBox1.Canvas.Pen.Color := $01000000 or lk;
    inc(lk);
    for k:=0 to 8 do
    begin
      PaintBox1.Canvas.MoveTo( i*10,      j*10+k);
      PaintBox1.Canvas.LineTo((i+1)*10-1, j*10+k);
    end;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  i,j,k     : integer;
  tmp,r,g,b : longint;
begin
  { example of Higest byte =00
    This try Show you Gray Shades with use
    of current SystemPalette not current realized palette }

  { realize new palette which will not be used }
  DeleteObject(SelectPalette( PaintBox1.Canvas.Handle,MyPal,false));
  RealizePalette( PaintBox1.Canvas.Handle );

  for j:=0 to 15 do
  for i:=0 to 15 do
  begin
    { this lines set color as RGB values }
    r := i*15; g := r; b := r;
    tmp := r+g*256+b*256*256;
    PaintBox1.Canvas.Pen.Color := $00000000 or tmp;
    for k:=0 to 8 do
    begin
      PaintBox1.Canvas.MoveTo( i*10,      j*10+k);
      PaintBox1.Canvas.LineTo((i+1)*10-1, j*10+k);
    end;
  end;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  i,j,k     : integer;
  tmp,r,g,b : longint;
begin
  { example of Higest byte =02
    This try Show you Gray Shades with use
    of current realized palette not SystemPalette }

  { realize new palette which will be now used }
  DeleteObject(SelectPalette( PaintBox1.Canvas.Handle,MyPal,false));
  RealizePalette( PaintBox1.Canvas.Handle );

  for j:=0 to 15 do
  for i:=0 to 15 do
  begin
    { this lines set color as RGB values }
    r := i*15; g := r; b := r;
    tmp := r+g*256+b*256*256;
    PaintBox1.Canvas.Pen.Color := $02000000 or tmp;
    for k:=0 to 8 do
    begin
      PaintBox1.Canvas.MoveTo( i*10,      j*10+k);
      PaintBox1.Canvas.LineTo((i+1)*10-1, j*10+k);
    end;
  end;
end;

end.

1.When you specify Higest byte as 0 you can place to TColor RGB values but you see colors only from system palette.
2.When you specify highest byte as 1 you can place to TColor number of logical palette entry.
3.When you specyfi highest byte as 2 you can place to TColor RGB values but you see colors only from current realized palette.
0
 

Author Comment

by:SteveMG
Comment Utility
Thankyou mirek. Your code made it clear to me that although I did grasp what the 3 palettes were, I had a misunderstanding about the process of realising a palette. Also it was not clear to me that a logical palette might initially contain only 16 non-black values.

An actually useful example in the Delphi 2 help might have helped me avoid my confusion. Is there any improvement in the Delphi 3 help in terms of not having only extremely trivial examples, or no examples at all, for more obscure topics?

Again, thanks to yourself and other contirbutors on this one,
Cheers, SteveMG.
0
 
LVL 3

Expert Comment

by:mirek071497
Comment Utility
When i write this example then i try to read carefully Help.
I found so when I trying understand all i can't understand TColor. However my english is poor and in many examples I understand only the idea and mayby this is the way to use Help system.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now