This is bmpheader.c in view mode; [Download] [Up]
#include <stdio.h>
#include <libc.h>
#include "bmp.h"
bmpHeader *loadBmpHeader(FILE *fp, int *errcode)
/* ¥Õ¥¡¥¤¥ë¤«¤é¥Ø¥Ã¥À¾öÊó¤òÆÉ¤à¡£
¥¨¥é¡¼¤¬µ¯¤¤¿¾ì¹ç¤Ï NULL¤¬Ê֤ꡢerrcode¤Ë¤½¤ÎÍýͳ¤¬Æþ¤ë¡£
¥Õ¥¡¥¤¥ë¥Ý¥¤¥ó¥¿¤Ï¥Ñ¥ì¥Ã¥È¾öÊó¤ÎÀèÆ¬¤ò»Ø¤·¤ÆÊ֤롣 */
{
long ftype, boffs, wid, hei, xp, yp, planes, colors;
long cmp=NoComp;
short bits = 0;
bmpHeader *bh;
wid = hei = planes = bits = xp = yp = colors = 0;
*errcode = 0;
if (getc(fp) != 'B' || getc(fp) != 'M') {
*errcode = Err_FORMAT;
return NULL;
}
(void) fseek(fp, 8L, SEEK_CUR); /* Skip hot spot */
boffs = get_long(fp);
ftype = get_long(fp);
if (ftype == OS2) {
wid = get_short(fp);
hei = get_short(fp);
planes = get_short(fp);
bits = get_short(fp);
}else if (ftype == WIN3) {
wid = get_long(fp);
hei = get_long(fp);
planes = get_short(fp);
bits = get_short(fp);
cmp = get_long(fp);
(void) get_long(fp);
xp = get_long(fp);
yp = get_long(fp);
colors = get_long(fp);
(void) get_long(fp);
}else { /* ERROR */
*errcode = Err_FORMAT;
return NULL;
}
if(feof(fp)) {
*errcode = Err_SHORT;
return NULL;
}
if (xp < 0 || yp < 0) {
*errcode = Err_FORMAT;
return NULL;
}
if (planes != 1 || wid > MAXWidth
|| (bits != 1 && bits != 4 && bits != 8 && bits != 24)) {
*errcode = Err_IMPLEMENT;
return NULL;
}
bh = (bmpHeader *)malloc(sizeof(bmpHeader));
bh->type = ftype;
bh->bits = bits;
bh->x = wid;
bh->y = hei;
bh->xpm = xp;
bh->ypm = yp;
bh->bitoffset = boffs;
bh->comp = cmp;
return bh;
}
void freeBmpHeader(bmpHeader *bh)
{
if (bh) {
if (bh->palette) free((void *)bh->palette);
free((void *)bh);
}
}
commonInfo *bmpInfo(bmpHeader *bh, int bits, BOOL mono)
/* Convert bmp-header into commonInfo */
{
commonInfo *cinf;
if (bh == NULL) return NULL;
cinf = (commonInfo *)malloc(sizeof(commonInfo));
cinf->width = bh->x;
cinf->height = bh->y;
cinf->type = Type_bmp;
cinf->bits = bits;
cinf->alpha = NO;
cinf->isplanar = YES;
cinf->numcolors = mono ? 1 : 3;
cinf->cspace = mono ? NX_OneIsWhiteColorSpace : NX_RGBColorSpace;
cinf->xbytes = byte_length(bits, bh->x);
cinf->palette = bh->palette;
bh->palette = NULL;
cinf->palsteps = 1 << bh->bits;
sprintf(cinf->memo, "%d x %d %dbit%s %s %s%s",
bh->x, bh->y, bits, ((bits > 1) ? "s" : ""),
((bh->bits > 8) ? "FullColor" : "Palette"),
(bh->type == OS2)?"OS2":"WIN3", (bh->comp ? "(RLE)":""));
return cinf;
}
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.