![]() |
| | #1 |
| Wheres the lesbians? Join Date: Oct 2006 Location: UK
Posts: 1,219
| Bitmasking Problem http://i92.photobucket.com/albums/l1...l/deleteme.png Its partly readable but somethings definitely wrong. The constructor for the class takes a character map, and the data. This is run here in my prog: Code: BitText txt( "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", "mprtxpmckccccmmp`acg~mp`e`pmaeiq~aa~oom`pmego}ppm~``acgomppmppmmppn`ak" "cipp~pp}pp}pp}mpooopm}ppppp}~oo}oo~~oo}ooompoorpnppp~pppmcccccm~aaaqqk" "pqswsqpoooooo~pztppppppxtrppmpppppm}pp}ooomppptrn}pp}sqpmpom`pm~cccccc" "ppppppmpppppicppppttippicipppppiccc~`acgo~" ); Code: BitText::BitText(const char* char_map, const char* char_data)
{
int len = (int)strlen(char_map);
map = new char[len];
strcpy(map, char_map);
len = (int)strlen(char_data);
data = new char[len];
strcpy(data, char_data);
col = 0xFFFFFFFF;
}
Code: void BitText::Print(Uint16 x_pos, Uint16 y_pos, const char* text)
{
int x, y, bit, pos;
char* ptr;
for(int i=0; i<(int)strlen(text); i++)
{
//Get the coresponding character in the character map
for(ptr=map, pos=0; *ptr; ptr++, pos++)
if(*ptr == text[i]) break;
//Get the characters data start point
ptr = data +(pos*7);
//Draw character
for(y=0; y<7; y++)
{
bit=16;
for(x=0; x<5; x++, bit >>= 1)
if(*ptr & bit)
WritePixel(x_pos+x, y_pos+y, this->col);
ptr++; //Move to data byte holding next scanline of the character
}
x_pos+=6;
}
}
Hopefully thats all the relevant code here. Last edited by mike_g; 11-07-2007 at 01:58 PM. |
| mike_g is offline | |
| | #2 |
| Registered User Join Date: Jan 2007 Location: Euless, TX
Posts: 135
| First question --- where does "map" come from in your print function?? |
| kcpilot is offline | |
| | #3 | |
| Frequently Quite Prolix Join Date: Apr 2005 Location: Canada
Posts: 7,629
| [edit] Quote:
Code: BitText::BitText(const char* char_map, const char* char_data)
{
int len = (int)strlen(char_map);
map = new char[len]; /* +1, right? . . . */
strcpy(map, char_map);
In BitText::BitText() . . . Code: map = new char[len]; Code: col = 0xFFFFFFFF; Code: col = (unsigned long)-1; ![]() Code: for(int i=0; i<(int)strlen(text); i++) Code: //Get the coresponding character in the character map for(ptr=map, pos=0; *ptr; ptr++, pos++) if(*ptr == text[i]) break; //Get the characters data start point ptr = data +(pos*7); Code: for(pos = 0; map[pos]; pos ++)
if(map[pos] == text[i]) break;
ptr = data + pos * 7;
__________________ dwk Seek and ye shall find. quaere et invenies. "Simplicity does not precede complexity, but follows it." -- Alan Perlis "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra "The only real mistake is the one from which we learn nothing." -- John Powell Other boards: DaniWeb, TPS Unofficial Wiki FAQ: cpwiki.sf.net My website: http://dwks.theprogrammingsite.com/ Projects: codeform, xuni, atlantis, etc. New project: nort | |
| dwks is offline | |
| | #4 |
| Registered User Join Date: Oct 2001
Posts: 2,936
| Code: map = new char[len]; . . data = new char[len]; Code: map = new char[len+1]; . . data = new char[len+1];
__________________ http://www.freechess.org |
| swoopy is offline | |
| | #5 | |||||
| Wheres the lesbians? Join Date: Oct 2006 Location: UK
Posts: 1,219
| Quote:
Code: class BitText
{
private:
char* data;
char* map;
Uint32 col;
public:
BitText(const char*, const char*);
void Print(Uint16, Uint16, const char*);
};
data holds the mask data. EG: "mprtxpm" is the data to display the number 0. Quote:
Quote:
![]() Quote:
Quote:
Cheers. | |||||
| mike_g is offline | |
| | #6 |
| Frequently Quite Prolix Join Date: Apr 2005 Location: Canada
Posts: 7,629
| What do you mean? i still exists. I'm just saying that you could use my for loop instead of your for loop. Mine makes use of only one counting variable, pos, whilst yours uses pos as well as ptr. You don't need both counters -- one will suffice.
__________________ dwk Seek and ye shall find. quaere et invenies. "Simplicity does not precede complexity, but follows it." -- Alan Perlis "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra "The only real mistake is the one from which we learn nothing." -- John Powell Other boards: DaniWeb, TPS Unofficial Wiki FAQ: cpwiki.sf.net My website: http://dwks.theprogrammingsite.com/ Projects: codeform, xuni, atlantis, etc. New project: nort |
| dwks is offline | |
| | #7 |
| Wheres the lesbians? Join Date: Oct 2006 Location: UK
Posts: 1,219
| >_< oh yeah. dident realize that. I guess I should take more time to think while i type ![]() Still looking for an answer to the original problem tho if anyone can spot it. Cheers. |
| mike_g is offline | |
| | #8 |
| Frequently Quite Prolix Join Date: Apr 2005 Location: Canada
Posts: 7,629
| That buffer overrun could be the source of your problem. Buffer overruns can result in strange things. Fix it and see what happens. You are of course aware that there are plenty of text handling libraries available for the SDL? You can get truetype fonts with SDL_ttf; SDL_gfx has simple bitmap font handling capabilities (with embedded data); and I've heard of sfont as well. Search the SDL libraries page if you're interested. Code: //Get the coresponding character in the character map for(ptr=map, pos=0; *ptr; ptr++, pos++) if(*ptr == text[i]) break; How is your data laid out? Because you seem to be using only the lower-order 4 bits of every byte: Code: //Draw character
for(y=0; y<7; y++)
{
bit=16;
for(x=0; x<5; x++, bit >>= 1)
if(*ptr & bit)
WritePixel(x_pos+x, y_pos+y, this->col);
ptr++; //Move to data byte holding next scanline of the character
}
__________________ dwk Seek and ye shall find. quaere et invenies. "Simplicity does not precede complexity, but follows it." -- Alan Perlis "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra "The only real mistake is the one from which we learn nothing." -- John Powell Other boards: DaniWeb, TPS Unofficial Wiki FAQ: cpwiki.sf.net My website: http://dwks.theprogrammingsite.com/ Projects: codeform, xuni, atlantis, etc. New project: nort |
| dwks is offline | |
| | #9 |
| Registered User Join Date: Oct 2001
Posts: 2,936
| I think there's a problem with your font map. It appears you have a 7x5 grid for every character, is this correct? I printed out the grid for some of the characters, and it almost looks like in some cases part of the character is missing. The number one looks ok, but most look similar to your deleteme.png file. Maybe the grid is supposed to be wider? And Dwks, it's 5 bits, not 4 bits being used.
__________________ http://www.freechess.org |
| swoopy is offline | |
| | #10 |
| Registered User Join Date: Oct 2001
Posts: 2,936
| Speaking of which do you have a file that you can post that shows what the font looks like for each character?
__________________ http://www.freechess.org |
| swoopy is offline | |
| | #11 | |
| Frequently Quite Prolix Join Date: Apr 2005 Location: Canada
Posts: 7,629
| Quote:
Actually, a better way to write the loop would perhaps be Code: for(x=0; bit; x++, bit >>= 1) Code: 2 << (4 - x)
__________________ dwk Seek and ye shall find. quaere et invenies. "Simplicity does not precede complexity, but follows it." -- Alan Perlis "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra "The only real mistake is the one from which we learn nothing." -- John Powell Other boards: DaniWeb, TPS Unofficial Wiki FAQ: cpwiki.sf.net My website: http://dwks.theprogrammingsite.com/ Projects: codeform, xuni, atlantis, etc. New project: nort | |
| dwks is offline | |
| | #12 | ||
| Wheres the lesbians? Join Date: Oct 2006 Location: UK
Posts: 1,219
| Quote:
![]() Quote:
Code: Data "mprtxpm" ; 0 Data "ckccccm" ; 1 Data "mp`acg~" ; 2 Data "mp`e`pm" ; 3 Data "aeiq~aa" ; 4 Data "~oom`pm" ; 5 Data "ego}ppm" ; 6 Data "~``acgo" ; 7 Data "mppmppm" ; 8 Data "mppn`ak" ; 9 Data "cipp~pp" ; A Data "}pp}pp}" ; B Data "mpooopm" ; C Data "}ppppp}" ; D Data "~oo}oo~" ; E Data "~oo}ooo" ; F Data "mpoorpn" ; G Data "ppp~ppp" ; H Data "mcccccm" ; I Data "~aaaqqk" ; J Data "pqswsqp" ; K Data "oooooo~" ; L Data "pztpppp" ; M Data "ppxtrpp" ; N Data "mpppppm" ; O Data "}pp}ooo" ; P Data "mppptrn" ; Q Data "}pp}sqp" ; R Data "mpom`pm" ; S Data "~cccccc" ; T Data "ppppppm" ; U Data "pppppic" ; V Data "pppptti" ; W Data "ppicipp" ; X Data "pppiccc" ; Y Data "~`acgo~" ; Z | ||
| mike_g is offline | |
| | #13 |
| Wheres the lesbians? Join Date: Oct 2006 Location: UK
Posts: 1,219
| Ok I just drew the binary pattern out for the first character and I found it dosent match to what I want. Apparently the prog I got this from used some other method to read the data. >_< That was kind of dumb of me not checking it. Guess I need to come up with some new data. |
| mike_g is offline | |
| | #14 |
| Registered User Join Date: Oct 2001
Posts: 2,936
| I noticed the map had more than the 5 least significant bits set in some of the chars too, which seemed odd, so maybe somehow it makes use of all 8 bits (or perhaps 7 bits), but as you say, the patterns don't seem to properly map.
__________________ http://www.freechess.org |
| swoopy is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need help understanding a problem | dnguyen1022 | C++ Programming | 2 | 04-29-2009 04:21 PM |
| Memory problem with Borland C 3.1 | AZ1699 | C Programming | 16 | 11-16-2007 11:22 AM |
| Someone having same problem with Code Block? | ofayto | C++ Programming | 1 | 07-12-2007 08:38 AM |
| A question related to strcmp | meili100 | C++ Programming | 6 | 07-07-2007 02:51 PM |
| WS_POPUP, continuation of old problem | blurrymadness | Windows Programming | 1 | 04-20-2007 06:54 PM |