diff --git a/src/osgPlugins/bmp/ReaderWriterBMP.cpp b/src/osgPlugins/bmp/ReaderWriterBMP.cpp index 8dbed5f3d..6c66aea2a 100644 --- a/src/osgPlugins/bmp/ReaderWriterBMP.cpp +++ b/src/osgPlugins/bmp/ReaderWriterBMP.cpp @@ -162,124 +162,123 @@ int *numComponents_ret) } } if (hd.FileType == MB) { - long infsize; //size of BMPinfo in bytes + long infsize; //size of BMPinfo in bytes unsigned char *cols=NULL; // dynamic colour palette unsigned char *imbuff; // returned to sender & as read from the disk - fread((char *)&infsize, sizeof(long), 1, fp); // insert inside 'the file is bmp' clause - if (swap) swapbyte(&infsize); - if ((infsize-sizeof(long))>16; - int npln = inf.height&0xffff; // number of planes - int cbits = inf.height>>16; - inf.width=wd; - inf.height=ht; - inf.planes=npln; - inf.Colorbits=cbits; - inf.ColorUsed=pow(2,inf.Colorbits); // infer the colours - } - long size = hd.siz[1]*65536+hd.siz[0]; - int ncpal=4; // default number of colours per palette entry - size -= sizeof(bmpheader)+infsize; - if (inf.ImageSize0) buffer = (unsigned char *)malloc( (ncomp==BW?3:ncomp)*inf.width*inf.height*sizeof(unsigned char)); // to be returned - else buffer = (unsigned char *)malloc( 3*inf.width*inf.height*sizeof(unsigned char)); // default full colour to be returned - - unsigned long off=0; - unsigned long rowbytes=ncomp*sizeof(unsigned char)*inf.width; - unsigned long doff=(rowbytes)/4; - if ((rowbytes%4)) doff++; // round up if needed - doff*=4; // to find dword alignment - for(int j=0; jBW) memcpy(buffer+j*rowbytes, imbuff+off, rowbytes); // pack bytes closely - else { // find from the palette.. - unsigned char *imptr=imbuff+inf.ColorUsed*ncpal; // add size of the palette- start of image - int npixperbyte=8/inf.Colorbits; // no of pixels per byte - for (int ii=0; ii>jj); // fill N High end bits - for (jj=0; jj>((npixperbyte-1-jj)*inf.Colorbits); - buffer[3*(j*inf.width+ii*npixperbyte+jj)+0]=cols[ncpal*colidx+2]; - buffer[3*(j*inf.width+ii*npixperbyte+jj)+1]=cols[ncpal*colidx+1]; - buffer[3*(j*inf.width+ii*npixperbyte+jj)+2]=cols[ncpal*colidx]; - mask>>=inf.Colorbits; - } - } - } - off+=doff; - if (ncomp>2) { // yes bill, colours are usually BGR aren't they - for(int i=0; i>16; + int npln = inf.height&0xffff; // number of planes + int cbits = inf.height>>16; + inf.width=wd; + inf.height=ht; + inf.planes=npln; + inf.Colorbits=cbits; + inf.ColorUsed=pow(2,inf.Colorbits); // infer the colours + } + long size = hd.siz[1]*65536+hd.siz[0]; + int ncpal=4; // default number of colours per palette entry + size -= sizeof(bmpheader)+infsize; + if (inf.ImageSize0) buffer = (unsigned char *)malloc( (ncomp==BW?3:ncomp)*inf.width*inf.height*sizeof(unsigned char)); // to be returned + else buffer = (unsigned char *)malloc( 3*inf.width*inf.height*sizeof(unsigned char)); // default full colour to be returned + + unsigned long off=0; + unsigned long rowbytes=ncomp*sizeof(unsigned char)*inf.width; + unsigned long doff=(rowbytes)/4; + if ((rowbytes%4)) doff++; // round up if needed + doff*=4; // to find dword alignment + for(int j=0; jBW) memcpy(buffer+j*rowbytes, imbuff+off, rowbytes); // pack bytes closely + else { // find from the palette.. + unsigned char *imptr=imbuff+inf.ColorUsed*ncpal; // add size of the palette- start of image + int npixperbyte=8/inf.Colorbits; // no of pixels per byte + for (int ii=0; ii>jj); // fill N High end bits + for (jj=0; jj>((npixperbyte-1-jj)*inf.Colorbits); + buffer[3*(j*inf.width+ii*npixperbyte+jj)+0]=cols[ncpal*colidx+2]; + buffer[3*(j*inf.width+ii*npixperbyte+jj)+1]=cols[ncpal*colidx+1]; + buffer[3*(j*inf.width+ii*npixperbyte+jj)+2]=cols[ncpal*colidx]; + mask>>=inf.Colorbits; + } + } + } + off+=doff; + if (ncomp>2) { // yes bill, colours are usually BGR aren't they + for(int i=0; i