473,797 Members | 3,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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)) incrmntcurrentR unlength();
else startNewRunleng th();
}
....
}

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 1327
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**********@g mail.comwrote in message
news:07******** *************** ***********@s33 g2000pri.google groups.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)) incrmntcurrentR unlength();
else startNewRunleng th();
}
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**********@g mail.comwrote:
)currentcolor =WHITE
)>
)for (i=0 ; i<bitImageSize ; i++){
) octet=bit_image[i] ;
) ...
) for (c=0x80 ; c ; c>>=1){
) if ((currentcolor& c)==(octet&c)) incrmntcurrentR unlength();
) else startNewRunleng th();
) }
)
) 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
5125
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 * 10^12) it's pretty efficient, it took 15 minutes to compute the first 1,000,000 primes.
6
17310
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 there is HTML-code, for example:
6
1535
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 program that was copied, though, and I'm having a difficult time finding the original source. Can anyone suggest a place that would let me search their database of codes for snips of code, or something like that? I'm hesitant to post
19
4455
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 array 4) Figure out if the original number is evenly divisible by any of the numbers in the array.
3
6262
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++ -Wall -W -ansi -pedantic -g3 -O0 -D_WIN32_WINNT=0x501 -D_WIN32_IE=0x600 -c crc32.cpp g++ -Wall -W -ansi -pedantic -g3 -O0 -D_WIN32_WINNT=0x501 -D_WIN32_IE=0x600 -c globals.cpp g++ -Wall -W -ansi -pedantic -g3 -O0 -D_WIN32_WINNT=0x501
23
2255
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 moment I use this terrible substitute: FLOAT_PREC = repr(1.0/3).count('3')
4
1461
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 whatever will make it work to tell me how many of these things I can put in this space. So example I want to put 60 of these thing that take up (21) units each. Well given that I cannot go over 512 the max I am able to put in any one space is 29. ...
25
4565
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 this. So of course it does not matter how many bits a single int has, but I do need a reliable way to find it out. I think of something like
17
3790
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 is what is difference between 1) (unsigned long) &((struct foobar *)0)->foo and
0
10468
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10245
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10205
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9063
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7559
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.