473,769 Members | 5,871 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading .bmp file in C

Hi all,
I want to read the pixel values of a .bmp image(which will be input to
the code) into a matrix...plz help me out as i can not understand how
to achieve this...

thanks in advance

biplab
Sep 10 '08
41 5418
Ron Ford <r...@example.i nvalidwrote:
biplab posted:
I want to read the pixel values of a .bmp image(which
will be input to the code) into a matrix...plz help me
out as i can not understand how to achieve this...

Standard C is the wrong tool for this.
Why do you say that?

--
Peter
Sep 11 '08 #11
On Wed, 10 Sep 2008 19:44:06 -0700 (PDT), Peter Nilsson posted:
Ron Ford <r...@example.i nvalidwrote:
>biplab posted:
>>I want to read the pixel values of a .bmp image(which
will be input to the code) into a matrix...plz help me
out as i can not understand how to achieve this...

Standard C is the wrong tool for this.

Why do you say that?
Because extensions make this easy.
--
War will never cease until babies begin to come into the world with larger
cerebrums and smaller adrenal glands. 2
H. L. Mencken
Sep 11 '08 #12

"Ron Ford" <ro*@example.in validwrote in message
>
Because extensions make this easy.
You're right. For instance BMP files can be jpeg-compressed. This happens
but rarely, but it is in the file format. You are much better off calling an
image-loading routine supplied by Microsoft.
Unless that is you are not on a Windows machine.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Sep 11 '08 #13

"Malcolm McLean" <re*******@btin ternet.comwrote in message
news:5q******** *************** *******@bt.com. ..
However if we say

int width;

width = fgetc(fp);
width |= fgetc(fp) << 8;

Then we retrieve the right value of width, regardless of whether integers
are 2 bytes or 4 bytes, or big- or little- endian.
Ok I have no real experience with the binary operators so I'm going to
say your pipe symbol | is XOR. << is the left shift operator for an 8 bit
value. I really don't know yet how to use this in real time but I recognize
the symbols.

Bill
Sep 11 '08 #14
On Sep 11, 11:46 pm, "Bill Cunningham" <nos...@nspam.c omwrote:
"Malcolm McLean" <regniz...@btin ternet.comwrote in message

news:5q******** *************** *******@bt.com. ..
However if we say
int width;
width = fgetc(fp);
width |= fgetc(fp) << 8;
Then we retrieve the right value of width, regardless of whether integers
are 2 bytes or 4 bytes, or big- or little- endian.

Ok I have no real experience with the binary operators so I'm going to
say your pipe symbol | is XOR.
lol.
Sep 11 '08 #15
Bill Cunningham said:

<snip>
Ok I have no real experience with the binary operators so I'm going
to
say your pipe symbol | is XOR.
That's the wrong way to learn. Instead of guessing, consult your C
reference, which makes the roles of bitwise operators perfectly clear.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Sep 11 '08 #16
vi******@gmail. com writes:
On Sep 10, 9:47 pm, s0s...@gmail.co m wrote:
>On Sep 10, 8:21 am, biplab <getbip...@gmai l.comwrote:

<snip>
1st of all i will be highly obliged if you let me know what the code
is doing and how??/As i have found the code in the internet and am a
newbie in C...
thanks in advance...

The code doesn't do much. It invokes undefined behavior

- at line 1 in main() (calling gets() with an uninitialized pointer)

Well, not really.
Well, yes, really.
That code would fail to translate, because of the non-standard
headers.
It *might* fail to translate, depending on the implementation. Unless
there's a statement in the standard that I've missed that says
anything that includes a non-standard header must fail to translate.
(Hint: There isn't.)
If not, how can you guess the contents of the non-standard
headers?
For example, <dos.hmight had:

#undef gets
#define gets(x) (void)0
You can't *know* the contents of non-standard headers, but you can
certainly *guess*. For example, I guess, with a fairly high level of
confidence, that a <dos.hheader in any implementation that provides
it *doesn't* have the above macro definition.

The fact that <dos.his non-standard, and therefore off-topic in this
newsgroup, doesn't mean that we can or should pretend that it doesn't
exist or that it's likely to contain some implausible content.
Writing non-portable code is one of the main purposes of C, after all.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Sep 11 '08 #17
"Bill Cunningham" <no****@nspam.c omwrites:
"Malcolm McLean" <re*******@btin ternet.comwrote in message
news:5q******** *************** *******@bt.com. ..
>However if we say

int width;

width = fgetc(fp);
width |= fgetc(fp) << 8;

Then we retrieve the right value of width, regardless of whether integers
are 2 bytes or 4 bytes, or big- or little- endian.

Ok I have no real experience with the binary operators so I'm going to
say your pipe symbol | is XOR. << is the left shift operator for an 8 bit
value. I really don't know yet how to use this in real time but I recognize
the symbols.
They're better referred to as bitwise operators. The term "binary
operator" commonly refers to an operator that takes two operands.

Your lack of experience with bitwise operators is no excuse for
*guessing* what they mean. "|" is not XOR. Consult your copy of
K&R2 (you've said you have one) to learn what it is, and what the
actual XOR operator looks like.

(Yes, << is the left shift operator, but it's not specific to 8
bit values.)

Last month, I gave you some advice about
the use of standard library functions. See
<http://groups.google.c om/group/comp.lang.c/msg/6da991ad26d30ed 9>.
Everything I wrote there applies equally to predefined operators,
at least to any that you're not familiar with. (At least this
time you're not writing code based on your guesses.)

One more thing: you're using <no****@nspam.c omas your return
address, obviously to avoid spam. nspam.com happens to be a
real domain. I'm sure its owner doesn't appreciate getting
all the spam that would have gone to you. Use something like
<no****@nospam. invalid(see RFC 2606).

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Sep 11 '08 #18
On Sep 12, 12:29 am, Keith Thompson <ks...@mib.orgw rote:
vipps...@gmail. com writes:
On Sep 10, 9:47 pm, s0s...@gmail.co m wrote:
The code doesn't do much. It invokes undefined behavior
- at line 1 in main() (calling gets() with an uninitialized pointer)
Well, not really.

Well, yes, really.
That code would fail to translate, because of the non-standard
headers.

It *might* fail to translate, depending on the implementation. Unless
Reading further,
"if not [...]"
So I did not say that it _must_ fail. I examined each posibility.
(I accept that this may not have been obvious, but these were my
intentions)
there's a statement in the standard that I've missed that says
anything that includes a non-standard header must fail to translate.
(Hint: There isn't.)
If not, how can you guess the contents of the non-standard
headers?
For example, <dos.hmight had:
#undef gets
#define gets(x) (void)0

You can't *know* the contents of non-standard headers, but you can
certainly *guess*. For example, I guess, with a fairly high level of
confidence, that a <dos.hheader in any implementation that provides
it *doesn't* have the above macro definition.

The fact that <dos.his non-standard, and therefore off-topic in this
newsgroup, doesn't mean that we can or should pretend that it doesn't
exist or that it's likely to contain some implausible content.
Writing non-portable code is one of the main purposes of C, after all.
I disagree. After all, nasal demons were given life here. :-)
(according to the jargon file, comp.std.c actually)
Being more serious here, of course that gets call invoked undefined
behavior. However, don't you agree my post had some truth hidden in
it? You can't assume what happends if you don't know what the headers
do.

Plus, who knows, there might be an implementation whose header (one of
the non-standard headers) does have such (or similar) macro
definition, to prevent people from using gets.
Sep 11 '08 #19
"Bill Cunningham" <no****@nspam.c omwrites:
"Malcolm McLean" <re*******@btin ternet.comwrote in message
news:5q******** *************** *******@bt.com. ..
>However if we say

int width;

width = fgetc(fp);
width |= fgetc(fp) << 8;

Then we retrieve the right value of width, regardless of whether integers
are 2 bytes or 4 bytes, or big- or little- endian.

Ok I have no real experience with the binary operators so I'm going to
say your pipe symbol | is XOR. << is the left shift operator for an 8 bit
value. I really don't know yet how to use this in real time but I recognize
the symbols.

Bill
Wonderful Bill! You're trolling knows no bounds!

Pipe symbol is XOR. Priceless.
Sep 11 '08 #20

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

Similar topics

14
3176
by: deko | last post by:
Do I need to use flock() when reading a file into an array? It's possible that the file in question could be open at the time the file('filename') request is made. I realize flock() is required when opening a file with fopen() when there is contention for the file: $fp=fopen($ctr, 'w'); //only write if we can get lock on file if (flock($fp, LOCK_EX)) { fwrite($fp, "0");
19
10375
by: Lionel B | last post by:
Greetings, I need to read (unformatted text) from stdin up to EOF into a char buffer; of course I cannot allocate my buffer until I know how much text is available, and I do not know how much text is available until I have read it... which seems to imply that multiple reads of the input stream will be inevitable. Now I can correctly find the number of characters available by: |
4
9842
by: Oliver Knoll | last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode (that is just writing, right?). How would one reopen it for reading? I got the following (which works): FILE *tmpFile = tmpfile(); /* write into tmpFile */ ...
11
3080
by: Matt DeFoor | last post by:
I have some log files that I'm working with that look like this: 1000000000 3456 1234 1000000001 3456 1235 1000020002 3456 1223 1000203044 3456 986 etc. I'm trying to read the file backwards and just look at the first column. Here's what I've got so far:
2
1438
by: archana | last post by:
Hi all, I am new to asp.net (learning phase). I have to develop application in asp.net to read file from client pc and display statistics of that file to client. So my question is that to read file from client pc do i need to upload that file on server and then start reading that file. Or is there any other alternative for this.
12
2910
by: SAL | last post by:
Hello, Is it possible to read a CSV from the Client, and bind my Datagrid to the data in the CSV file without uploading the file to the Server first? I have tried and in Debug mode on my workstation it works fine, but when I publish the page on our DEV server it doesn't fine the CSV file from the client. Has anyone done this before? If so, how do I do it? I'm new to ASP.net so
3
2185
by: miss time | last post by:
Hi all, my java friends ^-^ I have next week quiz in reading file text ,and understand the topic very well. can any one give some question related to this topic .this help me more to understand thanks a lot and sorry for inconvenience..
6
17015
by: Studlyami | last post by:
Is it possible to open a file for reading, while another process has it open for writing to it? One of the problems is that the process that is writing to it is written in C and is running on a vxworks OS. I'm reading the file using MFC on a windows XP PC. The file is stored on a Windows 2000 server. I tried using CStdioFile.Open using the CFile::modeRead flag. When did this i received a CFileException with the cause stating...
1
2141
Coldfire
by: Coldfire | last post by:
Hi, The strange problem i am having is, the input element of type='file' not reading file names after 20 file elements. It simple returns null on reading the 'name' of file. The code is simple and has no error as I am testing it standalone
1
2225
by: bjoarn | last post by:
I have an Application C# handling file reading, building index on this file, using dll wrapped with SWIG. The dll is originaly programmed in C++. Dll reports back to the the C# programm throug callback/delegates. Among others, it reports index building(%). One callback function can receive (stop order) to stop reading file/building index. How ever i do not know how to keep the stopbutton activ while this file reading is going on. I have...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
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...
1
9994
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
9863
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
8872
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...
0
5299
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3959
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.