Patch to read 32-bit-per-pixel BMP files. Apparently such beasts exist these days. (They didn't back when I originally wrote the BMP I/O mod- ule.) Presumably, the extra 8 bits are for an alpha channel, which xv will completely ignore. Still, better'n nothing. --- xv-3.10a.old/xvbmp.c +++ xv-3.10a/xvbmp.c @@ -32,7 +32,7 @@ static int loadBMP1 PARM((FILE *, byte *, u_int, u_int)); static int loadBMP4 PARM((FILE *, byte *, u_int, u_int, u_int)); static int loadBMP8 PARM((FILE *, byte *, u_int, u_int, u_int)); -static int loadBMP24 PARM((FILE *, byte *, u_int, u_int)); +static int loadBMP24 PARM((FILE *, byte *, u_int, u_int, u_int)); static u_int getshort PARM((FILE *)); static u_int getint PARM((FILE *)); static void putshort PARM((FILE *, int)); @@ -127,7 +127,8 @@ /* error checking */ - if ((biBitCount!=1 && biBitCount!=4 && biBitCount!=8 && biBitCount!=24) || + if ((biBitCount!=1 && biBitCount!=4 && biBitCount!=8 && + biBitCount!=24 && biBitCount!=32) || biPlanes!=1 || biCompression>BI_RLE4) { sprintf(buf,"Bogus BMP File! (bitCount=%d, Planes=%d, Compression=%d)", @@ -137,7 +138,8 @@ goto ERROR; } - if (((biBitCount==1 || biBitCount==24) && biCompression != BI_RGB) || + if (((biBitCount==1 || biBitCount==24 || biBitCount==32) + && biCompression != BI_RGB) || (biBitCount==4 && biCompression==BI_RLE8) || (biBitCount==8 && biCompression==BI_RLE4)) { @@ -159,7 +161,7 @@ } /* load up colormap, if any */ - if (biBitCount!=24) { + if (biBitCount!=24 && biBitCount!=32) { int i, cmaplen; cmaplen = (biClrUsed) ? biClrUsed : 1 << biBitCount; @@ -197,7 +199,7 @@ /* create pic8 or pic24 */ - if (biBitCount==24) { + if (biBitCount==24 || biBitCount==32) { pic24 = (byte *) calloc((size_t) biWidth * biHeight * 3, (size_t) 1); if (!pic24) return (bmpError(bname, "couldn't malloc 'pic24'")); } @@ -212,16 +214,18 @@ if (biBitCount == 1) rv = loadBMP1(fp,pic8,biWidth,biHeight); else if (biBitCount == 4) rv = loadBMP4(fp,pic8,biWidth,biHeight, biCompression); - else if (biBitCount == 8) rv = loadBMP8(fp,pic8,biWidth,biHeight, + else if (biBitCount == 8) rv = loadBMP8(fp,pic8,biWidth,biHeight, biCompression); - else rv = loadBMP24(fp,pic24,biWidth,biHeight); + else rv = loadBMP24(fp,pic24,biWidth,biHeight, + biBitCount); + if (rv) bmpError(bname, "File appears truncated. Winging it.\n"); fclose(fp); - if (biBitCount == 24) { + if (biBitCount == 24 || biBitCount == 32) { pinfo->pic = pic24; pinfo->type = PIC24; } @@ -384,10 +388,12 @@ u_int w,h,comp; { int i,j,c,c1,padw,x,y,rv; - byte *pp; + byte *pp, *pend; rv = 0; + pend = pic8 + w * h; + if (comp == BI_RGB) { /* read uncompressed data */ padw = ((w + 3)/4) * 4; /* 'w' padded to a multiple of 4pix (32 bits) */ @@ -407,12 +413,12 @@ x = y = 0; pp = pic8 + x + (h-y-1)*w; - while (y=0; i--) { pp = pic24 + (i * w * 3); @@ -474,6 +481,7 @@ pp[2] = getc(fp); /* blue */ pp[1] = getc(fp); /* green */ pp[0] = getc(fp); /* red */ + if (bits==32) getc(fp); pp += 3; }