473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

finding color of bits

hi
i am reading thru a book on digitizing text lines using c code.They
use a font data file containing unsigned char fonts [][16] with
elements like 0x00,0x7e,0x81 etc to represent each character .After a
text line is scanned 16 times the equivalent codes are stored in an
unsigned char[] bitImage.
Now the digitized line stored in bitImage is taken 1 character at a
time(ie 8 bits) and color of each is to be determined whether black or
white.
The book says that 'quickest method will be to write assembler code to
shift each octect(ie bitImage[i] in a for loop of i=0 to
i<bitImageSize) left 8 times so that carry flag will have color of
each bit'.The book says that no high level language can access the
carry flag and so a different method needs to be found.

I didn't quite understand that part.can someone clarify..?

The book continues to point out that 'bits in each octect can be got
by shifting it and ANDing with a constant'.Being new to bit
manipulation etc i couldn't quite write the code.if someone can help
pls do.

Finally the book comes up with a solution ,defining an unsigned char
c =0x80 and uses it as below

....
#define WHITE 0x00
#define BLACK 0xff
....
unsigned char octet ;
unsigned char *bit_image ;
....
currentcolor =WHITE

for (i=0 ; i<bitImageSize ; i++){
octet=bit_image[i] ;
...
for (c=0x80 ; c ; c>>=1){
if ((currentcolor&c)==(octet&c)) incrmntcurrentRunlength();
else startNewRunlength();
}
....
}

if somebody can explain what happens in this loop it would be a great
help..Being a beginner in c/bit manip etc i find it a little difficult
to understand these..

thanks in adv
harry
Jun 27 '08 #1
4 1303
harryos wrote:
The book continues to point out that 'bits in each octect can be got
by shifting it and ANDing with a constant'.Being new to bit
manipulation etc i couldn't quite write the code.if someone can help
pls do.
Least Bit == octet >0 & 1
Next bit == octet >1 & 1
Next next bit == octet >2 & 1

or

Least Bit == (octet & 1) != 0
Next bit == (octet & 2) != 0
Next next bit == (octet & 4) != 0

--
pete
Jun 27 '08 #2

"harryos" <os**********@gmail.comwrote in message
news:07**********************************@s33g2000 pri.googlegroups.com...
hi
i am reading thru a book on digitizing text lines using c code.They
use a font data file containing unsigned char fonts [][16] with
elements like 0x00,0x7e,0x81 etc to represent each character .After a
text line is scanned 16 times the equivalent codes are stored in an
unsigned char[] bitImage.
So each of these numbers represents 8 horizontal bits of one 'scanline' of a
character. A 1 might indicate Black and a 0 might indicate White (or vice
versa, since it depends on whether you're displaying black text on a white
background, or white text on black).
The book says that 'quickest method will be to write assembler code to
shift each octect(ie bitImage[i] in a for loop of i=0 to
i<bitImageSize) left 8 times so that carry flag will have color of
each bit'.The book says that no high level language can access the
carry flag and so a different method needs to be found.
That sounds like nonsense. Looking at your 0x7E, the bits here are 01111110,
bits 7 to bits 0, although they will likely represent pixel 0 to pixel 7 if
you number them left-to-right on the screen. So the leftmost pixel is White,
and the next six are Black, and finally White again.
currentcolor =WHITE

for (i=0 ; i<bitImageSize ; i++){
octet=bit_image[i] ;
...
for (c=0x80 ; c ; c>>=1){
if ((currentcolor&c)==(octet&c)) incrmntcurrentRunlength();
else startNewRunlength();
}
There's too much superfluous code here, and it seems concerned with some
compression scheme.

The essence of it is here, where M contains the current pattern (eg. your
0x7E example from above), or the 'octet':

int M=0x7E;
int i;
int colour;
#define BLACK 0XFF
#define WHITE 0X00

for (i=0x80; i!=0; i>>=1) {
colour = (M & i) ? BLACK : WHITE;
printf("%d ",colour);
}

--
Bartc

Jun 27 '08 #3
Bartc wrote:
) "harryos" <os**********@gmail.comwrote:
)currentcolor =WHITE
)>
)for (i=0 ; i<bitImageSize ; i++){
) octet=bit_image[i] ;
) ...
) for (c=0x80 ; c ; c>>=1){
) if ((currentcolor&c)==(octet&c)) incrmntcurrentRunlength();
) else startNewRunlength();
) }
)
) There's too much superfluous code here, and it seems concerned with some
) compression scheme.

FAX, perhaps ?
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
Jun 27 '08 #4
Ernie,
thanks for the detailed reply..it was a lot,lot helpful...
Willem was right..it was a book about Fax and it uses modified huffman
codes for compression..

thanks again
harry
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

32
by: someone else | last post by:
hi all I'm a newbie to this group. my apologies if I break any rules. I've wrote a simple program to find the first 1,000,000 primes, and to find all primes within any range (up to 200 *...
6
by: Hans Kamp | last post by:
Is it possible to write a function like the following: string ReadURL(string URL) { .... } The purpose is that it reads the URL (determined by the parameter) and returns the string in which...
6
by: Mike | last post by:
Hi, I teach a VB .NET class, and one of the students obviously cheated on the final exam (which was to write a Tic Tac Toe game). They were smart enough to change all of the variables from the...
19
by: gk245 | last post by:
Trying to write a program that will figure out if a number is perfect or not. Here is my logic: 1) Read in the number 2) Split it up (number - 1) 3) Put all the split up numbers into an...
3
by: Eric Lilja | last post by:
Hello, when I compile my project I get this (after doing a complete clean first): $ make g++ -Wall -W -ansi -pedantic -g3 -O0 -D_WIN32_WINNT=0x501 -D_WIN32_IE=0x600 -c common_dialogs.cpp g++...
23
by: Arnaud Delobelle | last post by:
Hi all, I want to know the precision (number of significant digits) of a float in a platform-independent manner. I have scoured through the docs but I can't find anything about it! At the...
4
by: mattG | last post by:
I have a scenario where I have these things that take up (x) number of space. I know the max number of space I will ever have is 512. I am trying to figure out a way to write a formula or...
25
by: Daniel Kraft | last post by:
Hi, I do need to implement something similar to C++'s std::bitset in C; for this, I use an array of int's to get together any desired number of bits, possibly larger than 32/64 or anything like...
17
by: abhimanyu.v | last post by:
Hi Guys, I have one doubt. The test program is given below. It uses two way of finding out the offset of a variable in structure. I executed the program and found the same result. My question...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.