Re: Reading .BMPs the hard way
Re: Reading .BMPs the hard way
- Subject: Re: Reading .BMPs the hard way
- From: Heinrich Giesen <email@hidden>
- Date: Fri, 18 Mar 2005 11:14:40 +0100
On 18.03.2005, at 06:11, <x-tad-smaller>Alexander Griekspoor</x-tad-smaller> wrote:
<x-tad-smaller>As the current cocoa implementations automatically convert lut-colored,
indexed BMP files to RGB, I am trying to read the files directly and </x-tad-smaller>
. . . . .
<x-tad-smaller>Still, the values I get back don't seem to be right... Any clues??</x-tad-smaller>
You have to respect that all values in a BMP file are littleEndian
values. So you have to read with something like:
- (
int) readIntFrom:(
int)inx
// byteOrder==NS_LittleEndian
{
return (imgDataBuffer[inx
24) | (imgDataBuffer[inx
16) | (imgDataBuffer[inx
8) | imgDataBuffer[inx];
}
- (
int) readShortFrom:(
int)inx
// byteOrder==NS_LittleEndian
{
return (imgDataBuffer[inx
8) | imgDataBuffer[inx];
}
with
unsigned char *imgDataBuffer = (
unsigned char *)[<x-tad-smaller>imgdata bytes</x-tad-smaller>];
Excerpt from my BMP reading class: (I used direct addresses instead of structs)
hdrSize = [
self readIntFrom:
0x0e];
xPelsPerMeter = [
self readIntFrom:
0x26];
yPelsPerMeter = [
self readIntFrom:
0x2a];
--
Heinrich Giesen
email: email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden