Logo

רד-בורד: ארכיון

ראשי > תיכנות > לא מצליח להציג BMP מזורגג

19/02/2008 22:36:18 T4uSBaZ
למדתי על הפאקינג מבנה שלו .. ( 2 הידרים, פלאטה והקובץ עצמו )
אני עובד בC במהדר של DOS, יעני אני רוצה במצב של VGA 320*200
על 256 צבעים ( זה איזה מצב ב10h) להציג את ה BMP.
וכן יש לי BMP באורך והרוחב המבוקש, ב256 צבעים, בלי דחיסה או משהו.

עברתי על הכל ..לא פועל.
אני כותב פיקסל למסך בשיטה הכי מהירה שיש בבורלנד של C
קוד:
unsigned char far *vga=MK_FP(0xA000,0);
vga[0]=2;

מציג לי פיקסל על המסך.

ועכשיו, הנה שני קוד שלא פועל לי.. [ עושה מה שבא לו. פעם יוצא, פעם לא מציג שום דבר, פעם מציג לי איזה תמונה עם רווחים שחורים על המסך.. ( וזה "תמונה" - יעני סתם פיקסלים צבעוניים ) ..

הערות: לפעמים זה יוצא לי מפונקציית FCLOSE.
את הבקרה של ה i=fread בכדי לבדוק שזה אכן קרא כמה שביקשתי ממנו העפתי כי זה גם לא עובד לי משום מה.

בכלל כל החרטא הזה לא פועל, הורדתי איזה קוד מהאינטרנט ושיניתי אותו כך שיפעל בקומפיילר, גם לא פועל.
(http://www.cprogramming.com/faq/cgi-bin/smartfaq.cgi?id=1043284392&answer=1044665557)

עזרו לי אני נואש! אני רוצה לבנות פה איזה סנייק, אם תעזרו לי אני אבנה פה גרסת רד בוארד =] לנחש יקראו הלל והתפוחים יהיו באייקון של רד בוארד מוהאהא

צוחק

קחו ת’קוד:

למי שרוצה זה פה, אבל למי שרוצה העלתי גם גרסה
יותר מסודרת .. פה:
http://pastebin.com/f1707b79d
יש שמה גם הערה שלי של למה ואיך חישבתי
שBM הוא ב short יהיה 19778.. אז אתם יכולים להתעלם

קוד:
#include <stdio.h>
#include <dos.h>
#include <malloc.h>
#include <conio.h>

typedef unsigned char byte;
void set256mode()
{
union REGS regs;
regs.h.ah=0;
regs.h.al=0x13;
int86(0x10,&regs,&regs);
}

void settextmode()
{
union REGS regs;
regs.h.ah=0;
regs.h.al=0x03;
int86(0x10,&regs,&regs);
}


byte far *vga;

struct BITMAPFILEHEADER{
short bmsign; //has to be "BM".. ( 19778 )
unsigned long int file_size; //file size in bytes.
long int reserved; //2 shorts reserved.
long int offset_data; //specifies the offset to the bitmap
long int info_size; //specifies this struct’s size.( 40 bytes )
long int width; //image width, in pixels
long int height; //image height, in pixels.
short planes; //number of planes in target device.. ( WTF? let it be zero.
short bitcount; //bumer of bits per pixel. actually the resoultion.
//cuz if it’s 8 bit = 1 byte per pixel, means there is 256 different colors in the pic.
long int compression; //type of compression. usually zero.
long int size_of_data ; //size of image data, if no compression. it’s also valid to set it zero. ( the program will calculate on her own)
long int ho_pixel_per_meter; //horizontal pixels per meter in target device. -> nonsense = usually set to zero.
long int ve_pixel_per_meter; //same but vertical
long int color_used; //specifies color used. if it’s zero we just calculate it by bitcount. ( 8 bits = 256 colors )
long int color_important; //more nonsense. number of color that are important. if set to zero, all important.

//so much nonsense in one struct
};

struct RGBQUAD {
char b;
char g;
char r;
char reserved;
};

int loadBmp(char *name,unsigned int offset)
{
struct BITMAPFILEHEADER test;
FILE *s;
struct RGBQUAD pallate[256];
byte *data;
int i,j;
if(!(s=fopen(name,"rb")))
{
return 0; //File not found or cannot be opened
}
//Let’s first get the infoo..
fseek(s,offset,SEEK_SET); //i wanna start from a specific offset cuz this function will be used in a program
//in which there is bunch of pictures in one file ( like pic.bin or somethin )


i=fread(&test,sizeof(struct BITMAPFILEHEADER),1,s);
// if(i!=sizeof(struct BITMAPFILEHEADER)) return -1; //file damaged
if(test.bmsign!=19778) return -1; //if it isn’t "BM" .. ( 19778 = in binary "MB" -> (in memory, but in reality it’s BM)
if(test.bitcount!=8) return -2; //donot support non-256 colored
i=fread(&pallate,sizeof(struct RGBQUAD),1,s);
// if(i!=sizeof(struct RGBQUAD)) return -1;
for(i=0;i<256;i++) //Reducing the power so it will fit to our prog
{
pallate.b>>=2;
pallate.g>>=2;
pallate.r>>=2;
}
if(test.height>200 || test.width>320) return -3; //image too big

data=(unsigned char*) malloc ( (test.width)*(test.height) );

if(!data) return -4; //no memory!
i=fread(&data,(test.height)*(test.width),1,s); //reading the image
// if(i!=sizeof(struct RGBQUAD)) return -1;
fclose(s); //yead i know we were suppous to close it on errors too.
for(i=0;i<256;i++) //updating the pallate
{
outp(0x03C8,i);
outp(0x03C9,pallate.r);
outp(0x03C9,pallate.g);
outp(0x03C9,pallate.b);
}
set256mode();
for(i=0;i<test.height;i++)
for(j=0;j<test.width;j++)
{

vga[i*(test.width)+j]=data[j+((test.height)-1)*(test.width)];

}
free(data);
return 1;
}

int main()
{
vga = (byte *) MK_FP(0xA000,0);
FILE *s;
int i;
if((i=loadBmp("abc.bmp",0))<1)
{
// settextmode();
printf("Error... %d",i);
getch();
return 0;
}
getch();
settextmode();

return 0;
}


[ההודעה נערכה על-ידי T4uSBaZ ב-19/02/2008 22:39:12]

[ההודעה נערכה על-ידי T4uSBaZ ב-19/02/2008 22:39:36][ההודעה נערכה על-ידי T4uSBaZ ב-22/02/2008 20:06:44]
21/02/2008 20:22:48 T4uSBaZ
עוד דבר: יש מצב שאיכשהו זה קשור למודל.. ( SMALL,MEDIUM,LARGE,TINY,HUGE.. )
24/02/2008 20:46:24 HLL
**שים לב ל 2 אני מאמין שזו הבעייה*

אמממ לעולם לא ניסיתי לעשות את זה ככה
אבל אני יכול להגיד לך שהאלג’ בספר להצגת BITMAP עובד מצויין.

כמה דברים שאתה צריך לוודא
1. כן הייתי רוצה שתשאיר את הבדיקה לגבי כמות הבתים שהצלחת לקרוא, מומלץ תמיד, תודיע לעצמך אם יש בעייה בכל נק’ בתהליך (לא ברור לי למה זה נופל)
2. יש סיבה למה קראת רק רשומה אחת מה Pallate???
קוד:i=fread(&pallate,sizeof(struct RGBQUAD),1,s);

עוד כמה טיפים זה להשתמש בכפל כמה שפחות, הייתי ממליץ לך להשתמש במצביע שמתקדם כל פעם במקום לעשות אינדקס למערך (VGA)
עמודים: 1