Untitled
unknown
plain_text
a year ago
3.3 kB
6
Indexable
/*************************************************************************** ** CLB2BGI_putimage2() ** ** Uses mult calls to Borland's putimage() to display a 256 color, ** 1-byte-per-pixel image in 16 color mode, line by line. We could use ** putpixel(), but that would be too slow! ** ** Things driving this code: ** (1.) Need for speed. ** (2.) Overcoming putimage's horrendous limitation of 64K! ** ** Adapted from pg 123 in Steve Rimmer's "Bit Mapped Graphics". ** ** Note: ** Each line of the putimage buffer is a representation of four vid ** planes; 1 section to a video plane. The length of each sector can be ** gotten by the pixels2bytes macro: planeW = pixels2bytes(ImageW); ** ****************************************************************************/ #define pixels2bytes(n) ((n+7)/8) //get uneven divide... "+7" BOOL CLB2BGI_putimage2(int x1,int y1,int x2,int y2, uchar huge *ImageBuff ){ register int c, i, j, planeSec, bits=4; int ImageW = x2-x1+1, ImageH = y2-y1+1, ScreenY = y1, planeW = pixels2bytes(ImageW), //about 1/8 of ImageW ScreenW = getmaxx() + 1, ScreenH = getmaxy() + 1; uchar huge *ptrImageBuff = &ImageBuff[0]; uchar *lineBuff, *extraBuff, *dispBuff, *ptrlineBuff; uchar masktable[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}, bittable[8]= {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; /* This func doesn't do images larger than screen */ if((ImageW > ScreenW) || (ImageH > ScreenH)) return FALSE; /* Malloc the scrap buffers (too many!) */ lineBuff = (uchar *)malloc(ImageW); if(!lineBuff) return FALSE; extraBuff = (uchar *)malloc(ImageW); if(!extraBuff) return FALSE; dispBuff = (uchar *)malloc(ImageW + 4); if(!dispBuff) return FALSE; /* Put putimage() coords into display buffer */ dispBuff[0]= (ImageW - 1) & 0xFF ; dispBuff[1]= ((ImageW-1) >> 8) ; dispBuff[2]= 0 ; dispBuff[3]= 0 ; do{ /** Display the image, top to bottom. ***/ memmove(extraBuff, ptrImageBuff, ImageW); /* Get an image line */ memset(lineBuff, '\0', ImageW); /* Work out the bitmask ugliness (planar madness!) */ for(i=0; i<ImageW; i++){ c=extraBuff[i] >> 4; //256 color > 16 color xlate ptrlineBuff=lineBuff; for(j=0; j<bits; ++j){ if(c & bittable[j]) ptrlineBuff[i>>3] |= masktable[i & 0x0007]; else ptrlineBuff[i>>3] &= ~masktable[i & 0x0007]; ptrlineBuff += planeW; //next sector } } /* Copy the planes into the display buffer */ for(i=4,planeSec=0; i>0;){ memcpy(dispBuff+4+(planeW * --i ), lineBuff+planeSec, planeW); planeSec+=planeW; } putimage(x1, ScreenY, dispBuff, COPY_PUT); /* Display this line */ ScreenY++; /* Advance pointer (and normalize for cheap compilers<g>) */ ptrImageBuff = ptrImageBuff + ImageW; }while( ScreenY <= y2 ); free(lineBuff); free(extraBuff); free(dispBuff); return TRUE; }
Editor is loading...
Leave a Comment