Raw image file format

Started by
13 comments, last by lejno 21 years, 11 months ago
I have my own image format and I am programming a program which will open a BMP and save it as my format. It works OK so far.
Advertisement
lejno,
since u're working in the 256-color mode, u should not forget to take care of the PALETTE


[edited by - remi on May 1, 2002 7:28:24 AM]
"...and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces."----------Scott Meyers, "Effective C++"
quote:Original post by remi
lejno,
since u''re working in the 256-color mode, u should not forget to take care of the PALETTE


[edited by - remi on May 1, 2002 7:28:24 AM]


The palette is already allright to me I guess, there are 256 colors (0-255) and one can vary in that specific range, but I would like to know how I create a palette, I am currently using DOS interrupts to set the video mode i''ve made the following functions myself:

setVideoMode(modeNum) //I use 19 for graph and 3 for text
putPixel(x,y,color)
getPixel(x,y) //returns color

Im kind of prowd over those functions , after all that''s all I have so far to be prowd over as I have not got anything else to work...

Haha, you said mode 19... aka, 13h. (most people refer to the standard 320x200x8 vga mode as mode 13h or 13 hex). What compiler are you using by the way?

To use the palette:


  void SetSingleEntry(unsigned char Index, unsigned char R, unsigned char G, unsigned char B){ outportb(0x3c8,Index); outportb(0x3c9,R); outportb(0x3c9,G); outportb(0x3c9,B);}  


Also, the RGB values are in the range of 0->63 (6 bits). You can simply take a value of 8 bits (0->255) and shift right 2 (or divide by 4)


  void SetSingleEntry8Bit(unsigned char Index, unsigned char R, unsigned char G, unsigned char B){ outportb(0x3c8,Index); outportb(0x3c9,R>>2); outportb(0x3c9,G>>2); outportb(0x3c9,B>>2);}  


You can do fading effects like this to (you can even read in the pallete using inportb:


  void GetSingleEntry(unsigned char Index, unsigned char &R, unsigned char &G, unsigned char &B){ outportb(0x3c8,Index); inportb(0x3c9,R); inportb(0x3c9,G); inportb(0x3c9,B);}  


Or the 8-bit version!


  void GetSingleEntry8Bit(unsigned char Index, unsigned char &R, unsigned char &G, unsigned char &B){ outportb(0x3c8,Index); inportb(0x3c9,R); inportb(0x3c9,G); inportb(0x3c9,B); R<<=2; G<<=2; B<<=2;}  



Hope this helps :D

Billy - BillyB@mrsnj.com
(Hey, I''''m no longer anonymous!)
Oh, and also.. you should use a back-buffer, and memcopy it to the screen buffer, it''s faster than reading/writing to the actual screen, and helps eliminate the tears/rips int he screen. Also, you could wait for vertical refresh to limit the speed, and to eliminate the tears completely (this code works under Turbo C/C++ 3.0 for Dos):


  unsigned char far *screen_ptr = (unsigned char far*)0xa0000000l;unsigned char far virt[64000]; //Our back-bufferstruct Sprite_S{ unsigned short width, height;//an unsigned char far would probably be better for this. unsigned char *Data;};Sprite_S *Sprites;unsigend char NumSprites;char LoadImages(char *fName){ FILE *in; unsigned char ctr; in = fopen(fName,"rb"); if (!in) {  return 1; //File not found! } NumSprites = getc(in); Sprites = new Sprite_S[NumSprites]; for (ctr=0;ctr!=NumSprites;++ctr) {  fread(&Sprites[ctr],2,2,in); //read in width/height  Sprites[ctr].Data = new unsigned char[Sprites[ctr].width*Sprites[ctr].height];  fread(Sprites[ctr].Data,Sprites[ctr].width,Sprites[ctr].height,in); //read in our data! } fclose(in);}void KillImages(void){ unsigned char ctr; for (ctr=0;ctr!=NumSprites;++ctr)  delete Sprites[ctr].Data; //Free each sprites data! delete Sprites; //Delete our sprite array!}void putPixel(short x, short y, unsigned char col){ unsigned long Off=(y<<6)+(y<<8)+x; virt[Off]=col;}unsigned char getPixel(short x, short y){ unsigned long Off=(y<<6)+(y<<8)+x; return virt[Off];}void SetMode(short mode){ asm mov ax, mode; asm int 0x10;}main(void){ unsigned char key; unsigned char done=0; if (LoadImages("Test.raw")) //Load images {  printf("Error loading images!"); //Oops, failed for some reason!  return -1; } SetMode(0x13); //Same thing as 19 while (!done) {  if (kbhit()) //check if there was a key hit!  {   key = getch(); //get the key hit!   if (key==27) //Escape pressed?   {    done=1;   }/*Check for other keys here.I don''t ussually use kbhit & getch, but my own custom keyboard handling routine (via my own interrupt 0x9 handler).*/  }/*Draw stuff here!*/  while (!(inportb(0x3da) & 0x8));  _fmemcpy(screen,virt,64000); //copy our buffer to our screen!  _fmemset(virt,0,64000); //erase the screen to color 0 } SetMode(0x3); KillImages(); return 0;}  


Of course a bit more error checking is in need, and this was all typed up in this window, so possibly a gramatical error or 2, and something overlooked, but it should give you a good idea on what I''m talking about :D

Billy - BillyB@mrsnj.com
(Hey, I''''m no longer anonymous!)

This topic is closed to new replies.

Advertisement