X-Trace-PostClient-IP: 68.147.131.211 From: Brian Inglis Newsgroups: comp.os.msdos.djgpp Subject: Re: struct problem Organization: Systematic Software Message-ID: References: <4beb6242eec71f0c5cf10defc2e78b1d DOT 62691 AT mygate DOT mailgate DOT org> X-Newsreader: Forte Agent 1.92/32.572 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 56 Date: Thu, 09 Jan 2003 11:24:01 GMT NNTP-Posting-Host: 24.71.223.147 X-Complaints-To: abuse AT shaw DOT ca X-Trace: news1.calgary.shaw.ca 1042111441 24.71.223.147 (Thu, 09 Jan 2003 04:24:01 MST) NNTP-Posting-Date: Thu, 09 Jan 2003 04:24:01 MST To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com On Wed, 8 Jan 2003 04:51:46 +0000 (UTC), "Joel Saunders" wrote: >In writting a simple bmp loader, I'm having problems with the struct for >the bmp header. Even with __attribute__((__packed__)) after each item: >struct BMP_Header { > unsigned int BM __attribute__((__packed__)); > unsigned long File_Size __attribute__((__packed__)); > unsigned int R_1 __attribute__((__packed__)); // Reserved 1 > unsigned int R_2 __attribute__((__packed__)); // Reserved 2 > unsigned long BMP_Offset __attribute__((__packed__)); > unsigned long Header_Info __attribute__((__packed__)); > unsigned long BMP_Width __attribute__((__packed__)); > unsigned long BMP_Height __attribute__((__packed__)); > unsigned int BMP_Planes __attribute__((__packed__)); > unsigned int BPP __attribute__((__packed__)); // Bytes Per Scan >Line > unsigned long Compression __attribute__((__packed__)); > unsigned long BMP_Size __attribute__((__packed__)); > unsigned long Width_PPM __attribute__((__packed__)); > unsigned long Height_PPM __attribute__((__packed__)); > unsigned long Num_of_Colors __attribute__((__packed__)); > unsigned long Important_Colors __attribute__((__packed__)); >}image; >I had to do this to use the header information: >unsigned char image[54]; >#define image_BM ((int *)&image[0])[0] >#define image_File_Size ((long *)&image[2])[0] >#define image_R_1 ((int *)&image[6])[0] >#define image_R_2 ((int *)&image[8])[0] >#define image_BMP_Offset ((long *)&image[10])[0] >#define image_Header_Info ((long *)&image[14])[0] >#define image_BMP_Width ((long *)&image[18])[0] >#define image_BMP_Height ((long *)&image[22])[0] >#define image_BMP_Planes ((int *)&image[26])[0] >#define image_BPP ((int *)&image[28])[0] >#define image_Compression ((long *)&image[30])[0] >#define image_BMP_Size ((long *)&image[34])[0] >#define image_Width_PPM ((long *)&image[38])[0] >#define image_Height_PPM ((long *)&image[42])[0] >#define image_Num_of_Colors ((long *)&image[46])[0] >#define image_Important_Colors ((long *)&image[50])[0] >To load the bmp header, I'm using fread (if that makes any difference). >And the program is using C, not CPP files (if that also, makes any >difference.) use short instead of int for now, until you can use int16_t (C99) Thanks. Take care, Brian Inglis Calgary, Alberta, Canada -- Brian DOT Inglis AT CSi DOT com (Brian dot Inglis at SystematicSw dot ab dot ca) fake address use address above to reply abuse AT aol DOT com tosspam AT aol DOT com abuse AT att DOT com abuse AT earthlink DOT com abuse AT hotmail DOT com abuse AT mci DOT com abuse AT msn DOT com abuse AT sprint DOT com abuse AT yahoo DOT com abuse AT cadvision DOT com abuse AT shaw DOT ca abuse AT telus DOT com abuse AT ibsystems DOT com uce AT ftc DOT gov spam traps