PDA

View Full Version : Bitmap images



Dragoneyes718
10-08-2006, 08:54 PM
Does anybody know of a program that can convert to .raw, or if there is an editor that will allow you to save a bitmap as .raw?

dmantione
10-08-2006, 09:02 PM
Netpbm is your friend: http://netpbm.sourceforge.net/

Dragoneyes718
10-08-2006, 09:37 PM
Thats alot of stuff to sort through. I'm not entirely wure which to use. I am wanting .raw format because of the compatibility with PutImage in TP7.

jdarling
11-08-2006, 02:07 AM
http://www.irfanview.com/

Best app I've found for this type of thing. Also works in batch mode, and is free. Now if you have money, then buy PSCS2 (PhotoShop CS2), its actually the best, but only a few of us developer geeks want to drop the cash on it :).

Dragoneyes718
11-08-2006, 02:21 PM
Thanks! Now if someone could help me get the syntax right for using BlockRead in conjunction with .raw files for use with Putimage.

Anybocy know how to do this?

dmantione
11-08-2006, 02:52 PM
Which graphics mode do you use?

Dragoneyes718
11-08-2006, 03:33 PM
VGA 640x480
16 color

dmantione
11-08-2006, 04:44 PM
For 16 colour modes you need to use 16 bpp packed pixel format. So, convert you image to such a format. Then, getmem a buffer with 6 bytes plus the size of the raw image. Then:

* At offset 0, write a word containing the width.
* At offset 2, write a word containing the height

Then blockread the image at offset 6. Now you should be able to use putimage.

Dragoneyes718
11-08-2006, 04:48 PM
How should I define the buffer?

dmantione
11-08-2006, 05:07 PM
I think an untyped pointer is the best solution. A pointer to a byte can also be usefull.

Dragoneyes718
11-08-2006, 05:14 PM
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?

dmantione
11-08-2006, 06:54 PM
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.:


var p,q:Pbyte;

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

Dragoneyes718
11-08-2006, 07:39 PM
Ok, I've got everything, except how do you convert the pixels to nibbles?

dmantione
11-08-2006, 07:49 PM
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_Graphics_Adapter#The_CGA_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:


var b:byte;

begin
b:=16*left_pixel + right_pixel;

Dragoneyes718
11-08-2006, 08:08 PM
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. :)

dmantione
11-08-2006, 08:15 PM
Something like this:

var buffer:Pbyte;
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));

Dragoneyes718
11-08-2006, 09:15 PM
Oh, ok, I was declaring buffer as a pointer. Could that be what messed it all up?

dmantione
11-08-2006, 10:15 PM
That should be okay. You didn' t forget to getmem it?

Dragoneyes718
12-08-2006, 01:13 AM
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?

dmantione
12-08-2006, 06:01 AM
Something like this:

var buffer:pointer;
size:word;

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

Dragoneyes718
12-08-2006, 04:18 PM
I just get a disk read error. :?

Dragoneyes718
12-08-2006, 10:49 PM
nevermind i figured it out!!!
Thank you very much for the help! :P