开发者

Bitmap point processing

would appreciate some brainstorming help for one of my assignments. I am to write a program that does basic point processing of a .bmp image. Program will open a .bmp file for reading and writing and will not change any part of the header, but the pixel values in the file according to command line arguments:

-fromrow x, where x specifies the bottommost row to process
-torowx, where x specifies the topmost row to process
-fromcol x, where x specifies the leftmost column to process
-tocol x, where x specifies the rightmost column to process
-op x, where x is one of the following:
    - 1 = threshold the image (any pixel value in the specifies range over 127 is changed 开发者_JAVA技巧to 255, and pixel values 127 or less is changed to 0)
    - 2 = negative (any pixel value p in the specified range is changed to 255-p)

To process image data, you will need to make use of the following:
- each pixel value is an unsigned char
- the number of rows in the image is stored as an int at position (byte address) 22 in the file
- the number of columns in the image is stored as an int at position (byte address) 18 in the file
- the position at which the pixel data starts is an int stored at position (byte address) 10 in the file
- pixel information is stored row by row, starting from the bottommost row in the image (row 0) and progressing upwards. within a row; pixel information is stored left to right. padding is added to the end of each row to make row length a multiple of 4 bytes (if the row has 479 columns, there is one extra padding at the end of the row before the next row starts)

I'm a bit lost as to how to begin, but I figure I should make a struct bitmap first like so?

struct bitmap {
    unsigned int startrow;
    unsigned int endrow;
    unsigned int startcol;
    unsigned int endcol;
}

Can anyone help walk me through what I would need to do for the byte addresses that the assignment references? Any other brainstorming advice would be greatly appreciated as well. Thanks!


You can read raw bytes by opening a file in binary mode:

FILE *fid = fopen("blah.bmp", "rb");

You can then read some amount of data thus:

int num_actually_read = fread(p, sizeof(*p), num_to_read, fid);

where p is a pointer to some buffer. In this case, you probably want p to be of type uint8_t *, because you're dealing with raw bytes mostly.

Alternatively, you can jump around in a file thus:

fseek(fid, pos, SEEK_SET);

I hope this is enough to get you going.


You will need a pointer to point to the byte addresses 22 and 18 of the file. Once you point to those addresses, you will need to dereference the pointer to get the row and column values. Then you have to point your pointer to address 10 and then traverse the pixels one by one.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜