Re: displaying BMP Files

new topic     » goto parent     » topic index » view thread      » older message » newer message

At 08:17 PM 3/27/98 +0530, Abhimanyu Lad wrote:

>Hi everybody
>I've a problem to which I couldn't find a good solution.
>Is it possible to display text and bitmap file at the same time with the
>correct colors? Bcos, once you have displayed some colorful text on the
>screen and then want a small BMP file to be displayed in a corner,
>either it will lose its true paintbrush colors(by not doing all_palette)
>or if you do a all_palette, your text will lose its original colors.
>Does anybody have a solution for me??

Yes..I had the same problem. The BMP file usually has a
different palette from the standard svga. The way to solve
this is as follows:
1. Copy the standard svga palette into a file
2. Open the BMP in an image editor (PaintShopPro is
    an excellent shareware editor)
3. Change the BMP's palette (in PSP, the menu options
    Color/Load Palette)
4. Save the BMP

Instead of the standard vga palette, you can load a
BMP and use it's palette as the standard for all BMP's
used in your program. That will change the meaning
of the standard color declarations, however.

How do you do step 1? I wrote a small Euphoria program
to view and capture the standard mode 256 color palette:

---------------------------------------------------------------
-- TESTPAL.EX     Show the colors availble in mode 256       --
-- and save the screen to a BMP file (or load palette from   --
-- a bitmap.                                                 --

include graphics.e
include image.e
include file.e
include putsxy.e -- David Alan Gay's excellent text management tool
include get.e

constant X = 1, Y = 2, START = 1, END = 2        -- for coords

object fn, finished
           finished = 0

function rect(object coords) -- convert topleft/botright coords to polygon
  return {{coords[START][X], coords[START][Y]}}
       & {{coords[END]  [X], coords[START][Y]}}
       & {{coords[END]  [X], coords[END]  [Y]}}
       & {{coords[START][X], coords[END]  [Y]}}
       & {{coords[START][X], coords[START][Y]}}
end function

-----------------------
procedure ShowPalette()
-----------------------
 fn = {{80,40},{130,50}}          -- display 2 cols of colors 0..31
 for color = 0 to 31 do
  if color = 16 then fn = {{220,40},{270,50}} -- move to second col
  end if
  putsxy(fn[1]-{78,0},sprintf("COLOR %d ",color),15,0,0)   -- label
  polygon(color,1,rect(fn))               -- draw colored rectangle
  fn = fn + {{0,16},{0,16}}
 end for -- color

fn = {{340,3},{390,6}}        -- display rainbow of all 256 colors
for color = 0 to 255 do
  if color = 128 then fn = {{450,3},{500,6}} -- move to second col
  end if
  polygon(color,1,rect(fn))
  if remainder(color,8) = 0 then    -- every 8 colors, show value
    putsxy(fn[1]-{45,2},sprintf("%d->",color),YELLOW,BLACK,0)
  end if
  fn = fn + {{0,3},{0,3}}
end for

end procedure

------------------------
procedure CheckOptions()
------------------------
  text_color(YELLOW)
  polygon(YELLOW,0,rect({{2,300},{270,375}}))
  position(20,2) puts(1,"X to end,")
  position(21,2) puts(1,"S to save EUPAL.BMP")
  position(22,2) puts(1,"L to load a .BMP file's palette")

  if check_break() then finished = 1    -- provide a way out
  end if
  fn = wait_key()                      -- get keyboard input

  if fn = 'S' or fn = 's' then          -- save the screen palette
     fn = save_screen(0,"EUPAL.BMP")

  elsif fn = 'L' or fn = 'l' then     -- load palette from a bitmap
     position(23,2) puts(1,"                                ")
     position(23,2) puts(1,"FILENAME:")
     fn = gets(0)
     fn = fn[1..length(fn)-1]
     if length(fn) > 0 then
       fn = read_bitmap(fn)
       if atom(fn) then puts(1,"ERROR            ")
       else all_palette(fn[1]/4)
       end if
     end if

  elsif fn = 'x' or fn = 'X' then finished = 1 -- exit the program
  end if

end procedure

--------------------------< MAIN >-------------------------------

  use_vesa(1)              -- set up graphics mode
  fn = graphics_mode(256)
  allow_break(1)

  polygon(YELLOW,1,rect({{1,1},{270,25}}))
  putsxy({25,6},"Color test of VESA mode 256", BLACK,YELLOW,0)

  while not finished do
    ShowPalette()
    CheckOptions()
  end while

  fn = graphics_mode(-1)


----------------------------------------------------------
--Visit my Euphoria programming web site:--
--http://www.mindspring.com/~mountains   --
----------------------------------------------------------

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu