473,407 Members | 2,326 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,407 software developers and data experts.

bitmap processing in C

9
I'm trying to do some processing in .bmp files and I need to use C, I've used it quite a bit except for image processing...and I'm trying to read the header block and pretty much from there just travel through the pixels and compare it with other file.

I haven't really worked on images before...so any pointers would be appreciated
this is what I'm trying to do to open the file..but I don't seem to be able to parse through the Header....any ideas, or other paths that I can take ?

FILE *fp;
fp = fopen("kitty.bmp","r");
unsigned char Header[0x435], image[256][256];
fread(Header,1,0x435,fp); // copy image header to Header array
fseek(fp,0x436,SEEK_SET); // Move file pointer to start of image data
fread(image,1,256*256,fp); // read image data and copy to ImageIn1[][] array

thanks in advance
May 2 '08 #1
2 2987
Savage
1,764 Expert 1GB
This would be the pseudo code for loadin in the bitmap

Expand|Select|Wrap|Line Numbers
  1. If open Bitmap file
  2. Read two bytes (type) and if different than 0x4D42 stop
  3. Ignore eight bytes
  4. Read four bytes (start of image data)
  5. Ignore four bytes
  6. Read four bytes (width of bitmap)
  7. Read four bytes (height of bitmap)
  8. Ignore two bytes
  9. Read two bytes (bit count of bitmap) and if different than 24 stop//24bit BMP only
  10. Read four bytes (compression of bitmap) and if different than BI_RGB stop//No compression
  11. Move to start of image data
  12. Allocate memory for image data (3(one byte for red, other for 
  13. green other for blue) * ImageWidth * ImageHeight)
  14. Read (3 * ImageWidth * ImageHeight) bytes from file to buffer
  15. Swap the red and blue components of buffer
  16. If ImageHeight is negative
  17. Flip the buffer lines
  18. End if
  19. Close file
Do you see now,where have you gone wrong?
May 2 '08 #2
weaknessforcats
9,208 Expert Mod 8TB
Are you using Windows? These bitmap funcitons are already written and are part of Win32.
May 5 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: halise | last post by:
Hi, i am in trouble with an exception in .net platform with c#. The exception thrown is exactly as follows: System.ArgumentException: Invalid parameter used. at...
1
by: bongoo | last post by:
I'm reading pixel values (RGB) from a bitmap object using function from system.drawing namespace & vb.net (.net framework 1.1) But I would like to make it faster, so is there any another way of...
3
by: Iwanow | last post by:
Hello! My goal is to develop a program that opens a bitmap, copies its pixels to an ArrayList in order to perform some complex calculations (edge detection, Hough transform etc.), and save...
6
by: lanwrangler | last post by:
I know it's a long shot but does anyone have any pointers to generic algorithms - or, even better, Python code - for comparing images and computing a value for the "difference" between them? ...
1
by: WorldHoldOn | last post by:
I need to take raw image data and create a bitmap out of it, then display it on a picturebox control. I know how to create the bitmap pixel data (as in setting up the image), it is the part of...
2
by: Peter Oliphant | last post by:
The Image class allows loading a bitmap from a graphic file. So far I've gotten it to work with JPG and BMP files. What other graphic file formats are supported in this way? Is this fixed based...
1
by: swetha | last post by:
HI, I am very new to C++.Using C++ I am reading one bitmap image.Now,I am trying to zooming that image.Can any one tell me which function have to use for this.Or can any one send some sample code...
7
by: Stephen.Schoenberger | last post by:
Hello, I am reading in a bitmap image and storing it as a bitmap in C#. I need to perform some mathmatical operations on that image but it needs to be broken up into smaller fragments (16x16)....
6
by: ProtossLee | last post by:
Hi, I am currently working on a project for image processing. a double matrix m1(1300X1000) need to be converted into bitmap and displayed on screen. so far I've made the following code: For i...
7
by: Jameson | last post by:
ok... This isn't working, and I dont know why, when I pass the resulting surface to StretchRectangle I get the awsome "error in application" haha... anyway. Is this not the right way (using...
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?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
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,...
0
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...
0
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...
0
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...
0
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,...

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.