Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 22

Thread: Bitmap images

  1. #11

    Bitmap images

    Ok, and can Netpbm convert .bmp to what I need? If so, I'm having trouble getting that whole mess running... Sorry for all the questions, but I'm not very experienced with file formats etc.

    Edit: And also, what is the correct syntax for writing, and reading at Offset?

  2. #12

    Bitmap images

    Not directly, because it cannot pack pixels in 4 bit nibbles. The easiest way is to read the ppm file, use bmptoppm to convert the bmp to a ppm file (which is basically a raw RGB file), read the ppm in memory and convert the individual pixels to nibbles.

    To read at a specific offset you must construct a pointer to it, i.e.:

    [pascal]
    var p,qbyte;

    begin
    getmem(p,1006); {Allocate buffer.}
    q:=p;
    inc(ptrrec(q).ofs,6); {q:=p+6 bytes}
    blockread(f,q^,1000);
    end;
    [/pascal]

  3. #13

    Bitmap images

    Ok, I've got everything, except how do you convert the pixels to nibbles?

  4. #14

    Bitmap images

    The raw RGB data is an array of rgb pixels. Each pixel is 3 bytes, first byte red, second byte green, third byte blue. Assuming the BMP picture was already 16 colours (otherwise you can reduce the amount of colours with with pnmremap), there are only 16 possibilities.

    These are the 16 values of the CGA colour palette, see:

    http://en.wikipedia.org/wiki/Color_G..._color_palette

    So, determine which colour you have, and the colour number is the pixel value.

    Now you need to convert the colours to nibbles:

    You have 16 colours, numbered from 0 to 15. So two pixels fit in one byte. The byte is calculated by:

    [pascal]
    var b:byte;

    begin
    b:=16*left_pixel + right_pixel;
    [/pascal]

  5. #15

    Bitmap images

    Thank you for all your help. But it's looking like I don't have all the resources to do most of this work. So... until I do, I hope I can get 1 more answer from you.
    The other method I've been trying to use for this type of thing is saving GetImage data. I have made an editing program that lets me draw pixel by pixel whatever I want. Then, it lets me get the image size that I want and (maybe) saves the GetImage Data to a file. I have been able to load the data back and use it with PutImage later, but only if:
    1. I haven't restarted the computer
    2. It is the most recently saved file (by my program).
    The problem I think is the way I'm trying to save it. I think I may be only saving the pointer variable to the file and it is still able to access the buffer for a while. I also am getting a garbled image if I try to access older image files.

    So my question is, what is the CORRECT way to save the data?
    Thanks in advance and for everything else.

  6. #16

    Bitmap images

    Something like this:
    [pascal]
    var bufferbyte;
    size:word;

    begin
    size:=imagesize(x1,y1,x2,y2);
    getmem(buffer,size);
    getimage(x1,y1,x2,y2,buffer^);
    blockwrite(f,buffer^,size);
    freemem(buffer,imagesize(x1,y1,x2,y2));
    [/pascal]

  7. #17

    Bitmap images

    Oh, ok, I was declaring buffer as a pointer. Could that be what messed it all up?

  8. #18

    Bitmap images

    That should be okay. You didn' t forget to getmem it?

  9. #19

    Bitmap images

    No, but maybe I'm having trouble because of the way I'm reading the file. What is the correct syntax to read it in, and then PutImage?

  10. #20

    Bitmap images

    Something like this:
    [pascal]
    var bufferointer;
    size:word;

    begin
    size:=imagesize(x1,y1,x2,y2);
    getmem(buffer,size);
    blockread(f,buffer^,size);
    putimage(x,y,buffer^);
    freemem(buffer,size);
    [/pascal]

Page 2 of 3 FirstFirst 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •