TPW: loading 256 color bitmaps? 
Author Message
 TPW: loading 256 color bitmaps?

We're using TPW 1.5 and we like to use a 256 color palette to display bitmaps.

I've included the code. When leaving the function Create256Pal, the program
crashes -- General Protection Fault ...

Any ideas?

Thanks in advance

Stefan

-----------------------------------------------------------------------------
function Create256Pal (bmi : TBitmapInfo) : HPalette;
var
  logPal : TLogPalette;
  i : Integer;
  hPal : THandle;
begin
  if bmi.bmiHeader.biSize <> SizeOf(TBitmapInfoHeader) then
  begin
     MessageBox(0, 'Bitmap info header not of correct structure',
               'IO-Error', MB_ICONSTOP + MB_OK);
     Exit;
  end;
  with logPal do
  begin
    palVersion := $0300;
    palNumEntries := 256;
     for i := 0 to 255 do
    begin
      palPalEntry[i].peRed   := bmi.bmiColors[i].rgbRed;
      palPalEntry[i].peGreen := bmi.bmiColors[i].rgbGreen;
      palPalEntry[i].peBlue  := bmi.bmiColors[i].rgbBlue;
      palPalEntry[i].peFlags := Byte(0);
    end;
  end;
  Create256Pal := CreatePalette(logPal);
end;

-------------------------------------------------------------------------------

Other parts of `interest' include:
(we've placed HugeIO in the bitmaps unit to the interface part)

 raw_ptr := GlobalLock(h);        { Lock it down }
  if (HugeIO(_LRead, f, raw_ptr, size) = 0) then
   begin
    _LClose(f);
    MessageBox(0, 'Unable to read complete bitmap',
               'IO-Error', MB_ICONSTOP + MB_OK);
    Exit;
  end;
  bmp_info_ptr := PBitmapInfo(raw_ptr);

-------------------------------------------------------------------------------

        hDevC := BeginPaint(hWindow, ps);
        hPal := Create256Pal(bmp_info_ptr^);
        hPal := SelectPalette(hDevC, hPal, false);
        RealizePalette(hDevC);

-------------------------------------------------------------------------------



Wed, 18 Jun 1902 08:00:00 GMT  
 TPW: loading 256 color bitmaps?

Quote:

>We're using TPW 1.5 and we like to use a 256 color palette to display bitmaps.

>I've included the code. When leaving the function Create256Pal, the program
>crashes -- General Protection Fault ...

Some stuff deleted

Quote:
>function Create256Pal (bmi : TBitmapInfo) : HPalette;
>var
>  logPal : TLogPalette;
>  i : Integer;
>  hPal : THandle;
>begin
>  if bmi.bmiHeader.biSize <> SizeOf(TBitmapInfoHeader) then
>  begin
>     MessageBox(0, 'Bitmap info header not of correct structure',
>               'IO-Error', MB_ICONSTOP + MB_OK);
>     Exit;
>  end;
>  with logPal do
>  begin
>    palVersion := $0300;
>    palNumEntries := 256;
>     for i := 0 to 255 do
>    begin
>      palPalEntry[i].peRed   := bmi.bmiColors[i].rgbRed;
>      palPalEntry[i].peGreen := bmi.bmiColors[i].rgbGreen;
>      palPalEntry[i].peBlue  := bmi.bmiColors[i].rgbBlue;
>      palPalEntry[i].peFlags := Byte(0);

TLogPalette.palPalEntry is an array [0..0] of TPalet{*filter*}try.
You are going out of the bonds here, hence a probable GPF !

Use rather something like that:
var  plogPal : PLogPalette ;
     logPalSize : Word ;
     ...
begin
   ...
   ...
   logPalSize := SizeOf(TLogPalette) + 255*SizeOf(TPalet{*filter*}try) ;
   GetMem(plogPal,logPalSize) ;
   if plogPal <> Nil  then
   with plogPal^  do  begin
      palVersion := $0300 ;
and your stuff here

Do not forget to FreeMem after the CreatePalette call

Regards

  _____   Dominique LOVY, Dept. de Chimie-Physique, Universite  de  GENEVE

__/__/___ Tel: ++41 22 7026525  Fax: ++41 22 7026518



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. WANTED: A Simple unit for loading 256 color bitmaps using TPW 1.5

2. TDBImage & 256 color bitmaps

3. 256 color image on a 16 color screen?

4. 24-bit color to 256 color's source

5. How do I print 256 color graphics?

6. Please Help : 256 color and Mouse

7. 256 color turbo pascal .tpi

8. RGB and 256-color palette matching

9. 256 Color Mode

10. RGB 256-color palette problem

11. Mouse in 256 color mode PROBLEM

12. 256 color text mode

 

 
Powered by phpBB® Forum Software