Make your own Palette for MapInfo 

with MAKE_PAL.MBX

 

Jacques Paris

jacques@paris-pc-gis.com

April 2002

 

I have written this MapBasic application to demonstrate that is not too difficult to generate files that can be used as replacements for the MapInfoW.CLR palette definition file. The editing function is very limited and not too exciting (anyone willing to improve it is welcome); I have put the emphasis rather on the generation of binary files of the appropriate format.

Installation

 Make_Pal can be installed in the directory of your choice. When loaded, a menu is added to the menu bar and an icon (Traffic Light) to the Tools toolpad.

 

MAKE_PAL.MBX input

The application can read two different kinds of files, one with the CLR type format, one in a plain DBF format.

CLR type file is a simple sequence of RGB codes; it can be read and written in MapBasic using the get and put instructions with a simple integer variable to hold the RGB codes. There is a small catch, the first record seems to be a kind of key, but as it is also a 4-byte integer, it can be handled without problem.

The DBF file should contain a certain number of columns as identified in the image of a Excel view of such a file; the cases must be in the order of the rows and within a row of columns. Only the RGB column is read in, the other columns are there to facilitate more detailed identification. They can also be used in the preparation of the file (see preparing a DBF file)

As soon as the input is identified, the application generates a MI table with all the needed information to display a color chart and the tabular values corresponding to each cell of that chart.

 

Editing a color

To open the Edit Color requester, use the “Editor Color” menu item or the “traffic light” button added to the Tolls toolpad. That operation launches the SelChangedHandler and if a cell of the chart or a row of the browser is selected, the corresponding color will be open for edition.

The values for RGB, R,G, B, H, S or V can be modified. Enter a value, select which type has to be modified, then what you want to do with it (“Reset” restores the values of the original color, “View Color” displays the new color, Save Color” writes the new values to the table) then click on “Do It”.

 

Saving the changes

Once all the changes have been made if any are required, the table can be saved in two formats: CLR type (there is no control on the extension name) that can be used right after having replaced and renamed the file correctly, and DBF type (must have a DBF extension) that can be used for further development on Excel for example.

 

Preparing a DBF file

The nu_template.xls is a simple way to prepare a new file. It consists of two worksheets Nu and Work. Nu is automatically filled with the values contained in Work at the corresponding cells. Prepare the data using Work, but never alter the first 2 columns, or the column headings; they are keys for a proper identification of the data.

   

When the preparation is finished, complete the important columns:

- If working with the R, G, B values, fill the rgb column with the formula

Col_for RGB   =65536*(col_for_R) + 256*(col_for_G) + (col_for_B)

- If working with the rgb codes, fill the r, g, b columns with the formulas

col_for_R        = quotient(col_for_RGB, 65536)

col_for_G        = quotient(col_for_RGB – col_for_R*65536 , 256)

col_for_B         = col_for_RGB – col_for_R*65536 – col_for_G*256

Then switch to the Nu worksheet and save it as a DBF file; only the Nu page will be exported with all the data (and not the formulas).

The “Work” sheet in the nu_template.xls included in the zip for download was setup in few minutes with a series of copy/paste for the 216 “Browser safe colors” (first row and column were not changed, new colors are added as 2*2 blocks of 6*6 cells, plus 2 blocks split one horizontally, the other vertically. A 3*3 block at the bottom right is left undefined, i.e. black). The organization of the colors is not a success but considering the work involved, the resulting palette is a good beginning.