bitmapped grahics help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2008
Posts: 91
Reputation: CPPRULZ is an unknown quantity at this point 
Solved Threads: 0
CPPRULZ CPPRULZ is offline Offline
Junior Poster in Training

bitmapped grahics help

 
0
  #1
Nov 9th, 2008
I am doing an online course and for one of the chapters (in Practical C++ Programming by Steve Oualline) it had a bitmapped graphics section-only 4 pages long. The chapter is about bit operations and includes a section about hexadecimals. I understoodit until I got to this passage in bitmapped graphics:

"Suppose we have a small graphics devicce- a 16 by 16 pixel monochrome display. We want to set a bit at 4,7. But we have a problem. There is no data type for an array of bits in C++. The closest we can come is an array of bytes. Our 16 by 16 array of bits now becomes a 2 by 16 array of bytes. [Why isn't it a 2 by 2 array?] To set the pixel at bit number 4,7 we need to set the fourth bit of byte (0,7). To set this bit we would use the statement bit_array[0][7] |= (0x80>>(4));"

What was the |= in the statement and I am also in need of a step by step explanation of the bit_array[0][7] |= (0x80>>(4)); statement (dont tell me it was explained above-it didnt make sense to me). Also, how would you output a simple 8 bit by 8 bit graphics that has 1 pixel turned on the rest off(because the book has no explanation of how to output that to the console)?
Thank You for your help.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,923
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 276
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: bitmapped grahics help

 
0
  #2
Nov 9th, 2008
| is the bitwise OR operator it means you are performing an OR on 1 bit(0 and 1). This is in contrast with the logical OR operator || which performs his actions on true and false values(booleans)

>> is a bitwise right shift operator.
In your case the hex value 0x80 gets shifted 4 bit-positions to the right.

Hope this helps.
Last edited by ddanbe; Nov 9th, 2008 at 6:45 am. Reason: typo
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 275
Reputation: dougy83 is on a distinguished road 
Solved Threads: 45
dougy83 dougy83 is offline Offline
Posting Whiz in Training

Re: bitmapped grahics help

 
0
  #3
Nov 9th, 2008
Originally Posted by CPPRULZ View Post
Our 16 by 16 array of bits now becomes a 2 by 16 array of bytes. [Why isn't it a 2 by 2 array?]
A byte is made up of 8 bits. Therefore a row can contain the 16 bits in 2 bytes. There are 16 rows, hence 2 x 16 bytes.

Calculate 16 x 16 bits = (2 x 8) x 16 bits = 256 bits.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 91
Reputation: CPPRULZ is an unknown quantity at this point 
Solved Threads: 0
CPPRULZ CPPRULZ is offline Offline
Junior Poster in Training

Re: bitmapped grahics help

 
0
  #4
Nov 9th, 2008
Still how would you output the bitmap? And why is there an = sign after the |?
Last edited by CPPRULZ; Nov 9th, 2008 at 3:21 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,923
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 276
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: bitmapped grahics help

 
1
  #5
Nov 9th, 2008
a |= b; is the same as a = a | b; It is a sort of shorthand notation. Just as a += b; is the same as a = a + b; It is probably invented to make life of newbies a little harder...
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 91
Reputation: CPPRULZ is an unknown quantity at this point 
Solved Threads: 0
CPPRULZ CPPRULZ is offline Offline
Junior Poster in Training

Re: bitmapped grahics help

 
0
  #6
Nov 9th, 2008
Oh, wow....I don't know how i didn't see that. Still, how would you output the bitmap and why is the book using hexadecimals-is it really neccessary (can you use just binary)?
Last edited by CPPRULZ; Nov 9th, 2008 at 3:58 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,923
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 276
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: bitmapped grahics help

 
0
  #7
Nov 9th, 2008
Well... hexadecimal is a shorthand for binary, but a very usefull one!
Google hexadecimal to find out more!
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 91
Reputation: CPPRULZ is an unknown quantity at this point 
Solved Threads: 0
CPPRULZ CPPRULZ is offline Offline
Junior Poster in Training

Re: bitmapped grahics help

 
0
  #8
Nov 9th, 2008
I did and I found an article at http://www.codeproject.com/KB/cpp/bitbashing.aspx that explained how a hexadecimal is like a nibble and very useful in representng binary but would it be possible to say bit_array[0][4]=bin 0001 or something like that and do you know of any sites that explain outputing "manual" bitmaps (not pictures)?

thank you for your help
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,923
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 276
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: bitmapped grahics help

 
0
  #9
Nov 9th, 2008
What do you mean by "manual" bitmaps?
Do you mean to output zeros and ones instead of pixels?
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 91
Reputation: CPPRULZ is an unknown quantity at this point 
Solved Threads: 0
CPPRULZ CPPRULZ is offline Offline
Junior Poster in Training

Re: bitmapped grahics help

 
0
  #10
Nov 9th, 2008
Usually when I google bitmaps I get how to upload .bmp's but I want to manualy set the pixels in say a 16by16 bit bitmap (3,6)=1 (2,9)=1...
I looked at the sample program in teh book and it just outputs "." do you know if you could actually make a bitmap in C++.
Last edited by CPPRULZ; Nov 9th, 2008 at 5:04 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC