• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Reading .BMPs the hard way
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Reading .BMPs the hard way


  • Subject: Reading .BMPs the hard way
  • From: Alexander Griekspoor <email@hidden>
  • Date: Fri, 18 Mar 2005 10:26:35 +0100

Hi all,

As the current cocoa implementations automatically convert lut-colored, indexed BMP files to RGB, I am trying to read the files directly and create an NSBitmapRep from it myself (the calculations I like to do on the images can't use the conversion). However, I don't get it working properly. Does someone have experience with this, or could tell me where I make (a perhaps obvious) mistake?

Things go wrong in reading the fileheaders already (from which I try to get the offset where the actual image data begins).
A .bmp file has the following data structures:

BITMAPFILEHEADER bmfh;
BITMAPINFOHEADER bmih;
RGBQUAD aColors[];
BYTE aBitmapBits[];


According to M$ the fileheader struct should be:

typedef struct tagBITMAPFILEHEADER {
WORD bfType; // size 2, std value 19778
DWORD bfSize; // size 4, file size in bytes
WORD bfReserved1; // size 2, should be 0
WORD bfReserved2; // size 2, should be 0
DWORD bfOffBits; // size 4
} BITMAPFILEHEADER;

What I try to get is the bfOffBits number, the offset in the file where the image data begins

My current implementation looks like this:

The struct that I defined:
typedef struct tagWINBITMAPFILEHEADER
{
short bfType;
int bfSize;
short bfReserved1;
short bfReserved2;
int bfOffBits;
} WINBITMAPFILEHEADER;

The test method:
WINBITMAPFILEHEADER *signature;

// Memory alloc and read in struct
signature = malloc(sizeof(WINBITMAPFILEHEADER));
NSData *imgdata = [NSData dataWithContentsOfFile: bmppath];
[imgdata getBytes: signature length:


// See what we got?
NSLog(@"BFType: %hi", signature->bfType);
NSLog(@"Size: %d", signature->bfSize);
NSLog(@"Reserved 1: %hi", signature->bfReserved1);
NSLog(@"Reserved 2: %hi", signature->bfReserved2);
NSLog(@"Offbits: %d", signature->bfOffBits);


free(signature);


Still, the values I get back don't seem to be right... Any clues??
Many thanks in advance!
Alex

*********************************************************
** Alexander Griekspoor **
*********************************************************
The Netherlands Cancer Institute
Department of Tumorbiology (H4)
Plesmanlaan 121, 1066 CX, Amsterdam
Tel: + 31 20 - 512 2023
Fax: + 31 20 - 512 2029
AIM: email@hidden
E-mail: email@hidden
Web: http://www.mekentosj.com


4Peaks - For Peaks, Four Peaks.
2004 Winner of the Apple Design Awards
Best Mac OS X Student Product
http://www.mekentosj.com/4peaks

*********************************************************
 _______________________________________________
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

  • Follow-Ups:
    • Re: Reading .BMPs the hard way
      • From: Matt Gough <email@hidden>
  • Prev by Date: Re: KVO and isKindOfClass:
  • Next by Date: Re: Reading .BMPs the hard way
  • Previous by thread: Re: NSTask as root
  • Next by thread: Re: Reading .BMPs the hard way
  • Index(es):
    • Date
    • Thread