Board index » delphi » How can I convert bitmap to rgb (urgent)

How can I convert bitmap to rgb (urgent)

Sorry for this a bit off-topic post, but I do need to generate a rgb file
from a bitmap.

Is there any freeware that does this job?

Rafael

 

Re:How can I convert bitmap to rgb (urgent)


Hi

    If you have 24 or 32 bit bitmap then just go through scanlines and save
RGB values to stream.

Tomaz

Quote
"Rafael Cotta" <rcotta.nos...@ig.com.br> wrote in message

news:3d669e2b@newsgroups.borland.com...
Quote
> Sorry for this a bit off-topic post, but I do need to generate a rgb file
> from a bitmap.

> Is there any freeware that does this job?

> Rafael

Re:How can I convert bitmap to rgb (urgent)


I think that's not enough. There are some header information.

http://astronomy.swin.edu.au/~pbourke/dataformats/sgirgb/

Rafael

"Tomaz Koritnik" <tomaz.koritn...@guest.arnes.si> escreveu na mensagem
news:3d66b5b9@newsgroups.borland.com...

Quote
> Hi

>     If you have 24 or 32 bit bitmap then just go through scanlines and
save
> RGB values to stream.

> Tomaz

> "Rafael Cotta" <rcotta.nos...@ig.com.br> wrote in message
> news:3d669e2b@newsgroups.borland.com...
> > Sorry for this a bit off-topic post, but I do need to generate a rgb
file
> > from a bitmap.

> > Is there any freeware that does this job?

> > Rafael

Re:How can I convert bitmap to rgb (urgent)


Quote
"Rafael Cotta" <rcotta.nos...@ig.com.br> wrote in message

news:3d66d113@newsgroups.borland.com...

Quote
> I think that's not enough. There are some header information.

Bitmap.PixelFormat := pf24Bit;
Bitmap.SaveToFile(FileName);

Will create 24Bit RGB encoded DIB.

PixelFormat := pf32Bit,  is the same but has extra byte per pixel (RGBA)
which can be used for whatever you like.

Regards

Re:How can I convert bitmap to rgb (urgent)


If on the other hand,  you are talking about saving raw 24bit pixel data
then the header needs only to contain Width and height of bitmap so you can
correctly decode scanline boundaries.

TFileStream should be perfect for doing this.
Just output width and height and then start writing pixel data.

Regards

Re:How can I convert bitmap to rgb (urgent)


Hi Rafael,

Just take this info:

      2 bytes  short   MAGIC      IRIS image file magic number
                                  This should be decimal 474
      1 byte   char    STORAGE    Storage format
                                  0 for uncompressed
                                  1 for RLE compression
      1 byte   char    BPC        Number of bytes per pixel channel
                                  Legally 1 or 2
      2 bytes  ushort  DIMENSION  Number of dimensions
                                  Legally 1, 2, or 3
                                  1 means a single row, XSIZE long
                                  2 means a single 2D image
                                  3 means multiple 2D images
      2 bytes  ushort  XSIZE      X size in pixels
      2 bytes  ushort  YSIZE      Y size in pixels
      2 bytes  ushort  ZSIZE      Number of channels
                                  1 indicates greyscale
                                  3 indicates RGB
                                  4 indicates RGB and Alpha
      4 bytes  long    PIXMIN     Minimum pixel value
                                  This is the lowest pixel value in the
image
      4 bytes  long    PIXMAX     Maximum pixel value
                                  This is the highest pixel value in the
image
      4 bytes  char    DUMMY      Ignored
                                  Normally set to 0
     80 bytes  char    IMAGENAME  Image name
                                  Must be null terminated, therefore at most
79 bytes
      4 bytes  long    COLORMAP   Colormap ID
                                  0 - normal mode
                                  1 - dithered, 3 mits for red and green, 2
for blue, obsolete
                                  2 - index colour, obsolete
                                  3 - not an image but a colourmap
    404 bytes  char    DUMMY      Ignored
                                  Should be set to 0, makes the header 512
bytes

And make it into a record, like this (please check the length to see if it
is 512 bytes).

type
  TSgiRgbHeader = packed record
    MAGIC: word;                    // IRIS image file magic number
    STORAGE: byte;                  // Storage format
    BPC: byte;                      // Number of bytes per pixel channel
    DIMENSION: word;                // Number of dimensions
    XSIZE: word;                    // X size in pixels
    YSIZE: word;                    // Y size in pixels
    ZSIZE: word;                    // Number of channels
    PIXMIN: integer;                // Minimum pixel value
    PIXMAX: integer;                // Maximum pixel value
    DUMMY: array[1..4] of char;     // Ignored
    IMAGENAME: array[1..80] of char;// Image name
    COLORMAP: integer;              // Colormap ID
    DUMMY: array[1..404] of byte;   // Ignored
  end;

Then, create your file like this

procedure SaveBitmapAsSgiRgbFile(ABitmap: TBitmap, AFileName: string);
var
  H: TSgiRgbHeader;
begin
  Fillchar(H, SizeOf(H), 0); // to clear the header
  with H do begin
    MAGIC := 474;
    STORAGE := 0;
    BPC := 1;
    DIMENSION := 2;
    XSIZE := ABitmap.Width;
    YSIZE := ABitmap.Height;
    case ABitmap.PixelFormat of
    pf24bit:
      ZSIZE := 3;
    pf32bit:
      ZSIZE := 4;
    end;
    PIXMIN := 0;
    PIXMAX := 255;
    copy(AFileName[1], IMAGENAME, min(Length(AFileName), 79));
  end;
  // Create the file
  S := TFileStream.Create(AFileName, fmOpencreate or fmSharedenynone);
  try
    // Save header
    S.Write(H, SizeOf(H));

    // Save image
    // Do this conform what is described on the website

  finally
    S.Free;
  end;
end;

Hope this helps, just wrote it down, no guarantees :)

Nils
www.abc-view.com

Quote
Rafael Cotta <rcotta.nos...@ig.com.br> wrote in message

news:3d66d113@newsgroups.borland.com...
Quote
> I think that's not enough. There are some header information.

> http://astronomy.swin.edu.au/~pbourke/dataformats/sgirgb/

> Rafael

> "Tomaz Koritnik" <tomaz.koritn...@guest.arnes.si> escreveu na mensagem
> news:3d66b5b9@newsgroups.borland.com...
> > Hi

> >     If you have 24 or 32 bit bitmap then just go through scanlines and
> save
> > RGB values to stream.

> > Tomaz

> > "Rafael Cotta" <rcotta.nos...@ig.com.br> wrote in message
> > news:3d669e2b@newsgroups.borland.com...
> > > Sorry for this a bit off-topic post, but I do need to generate a rgb
> file
> > > from a bitmap.

> > > Is there any freeware that does this job?

> > > Rafael

Other Threads