Solved

Reading RGB Palette Information

Posted on 1998-12-10
10
345 Views
Last Modified: 2012-05-04
I would like to be able to read in the RGB palette information for all 256 colours in turbo pascal 7.0 for dos. I would like to store the Red, Green, and Blue values for each colour to an array so that i may save it to a file.  I would rather not use asembly language do to this for this is myfinal prodject for computer class.  If someone knows who to do this or knows of a function or procedure to do this, it would be greatly appreciate if you droped me a line.
0
Comment
Question by:Corey080698
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
  • 2
10 Comments
 
LVL 2

Expert Comment

by:VIBESPRO
ID: 1216438
What do you mean?  Do you want to put the colour to the screen or into a variable, or something else? I don't exactly understand what you want to do.
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1216439
You have to use ports, but you do not necessarily have to use assembly language.  Pascal has the Port array to allow you to access the ports.
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1216440
Port[$3C8]:= ColourNumber;
Port[$3C9]:= R;
Port[$3C9]:= G;
Port[$3C9]:= B;

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Expert Comment

by:VIBESPRO
ID: 1216441
Hey SCRAPDOG, read the question again.  He 'rather not use asembly language or ports'!
0
 

Author Comment

by:Corey080698
ID: 1216442
Edited text of question
0
 

Author Comment

by:Corey080698
ID: 1216443
Your right VIBESPRO, I would rather not use asembly language or ports...but if thats the best way...i guess i'd have to...
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1216444
VIBESPRO:  I read the question.  

You CAN'T.
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1216445
If you want, I can write a function that will make it easier for you.
0
 
LVL 5

Accepted Solution

by:
scrapdog earned 100 total points
ID: 1216446
uses crt;   {only for the delay procedure}

type
  TRGBColor = record
                red, green, blue :byte;
              end;
  TRGBArray = array[0..255] of TRGBColor;

procedure SetPaletteColor(index :byte; color :TRGBColor);
begin
  Port[$3c6] := $ff;  {sets palette mask}
  Port[$3c8] := color; {set palette index}
  Port[$3c9] := color.r;  
  Port[$3c9] := color.g;
  Port[$3c9] := color.b;
end;

function GetPaletteColor(index :byte) :TRGBColor;
var
  Color :TRGBColor;
begin
  Port[$3c6] := $ff;
  Port[$3c8] := index;
  Color.Red := Port[$3c9];
  Color.Green := Port[$3c9];
  Color.Blue := Port[$3c9];
  Result := Color;
end;


procedure GetColorArray(var RGBArray :TRGBArray);
var i :byte;
begin
  for i := 0 to 255 do begin
    RGBArray[i] := GetPaletteColor(i);
    Delay(1);        {a short delay to wait for video card}
  end;
end;



To set a palette register:

var
  RGBColor :TRGBColor;

RGBColor.Red := RedComponent;
RGBColor.Green := GreenComponent;
RGBColor.Blue := BlueComponent;

SetPaletteColor(ColorNumber, RGBColor);


To retrieve a palette register and store it in a variable of type TRGBColor:

RGBColor := GetPaletteColor(ColorNumber);


To retrieve the entire palette and store it in an array of type TRGBArray:

GetColorArray(RGBArray);


I inserted the Delay(1) in the GetColorArray procedure because the palette registers will be written to many times in succession.  The Delay(1) is just for safety...it allows the video card to update the registers before you send it anoter value.


By the way, it is NOT cheating to get external help on a question like this, even if it is for a homework assignment.  It is not like anyone is writing your whole program...you did it yourself, and I presume that this is only a improvement on your basic requirements.  This uses no assembly language, however using the ports is inevitable.  You can look in the TP help file on the Port array if you need more info.

Just say that you found out how to do this by searching the internet...you wouldn't be lying.  Your teacher will admire your resourcefulness.
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1216447
By the way, change color.r, color.g, and color.b to color.red, color.green, and color.blue.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Exiting edit and insert into firebird table gives Dynamic SQL Error 9 1,025
Delphi - What Does "F" Symbolize? 2 488
printers log data 3 372
Converting a Windows Bitmap Stream to TIcon 2 809
When using a search centre, I'm going to show you how to configure Sharepoint's search to only return results from the current site collection. Very useful when using Office 365 with multiple site collections.
Deploying our service is a grudge match between customer benefits and customer pain. In one corner, rolling out fixes (yay!) and delivering new features (double yay!). In the other corner, training on new features (boo – sounds like work), and chan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 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