123a0898aSmrg/* 223a0898aSmrg 323a0898aSmrgCopyright 1990, 1994, 1998 The Open Group 423a0898aSmrg 523a0898aSmrgPermission to use, copy, modify, distribute, and sell this software and its 623a0898aSmrgdocumentation for any purpose is hereby granted without fee, provided that 723a0898aSmrgthe above copyright notice appear in all copies and that both that 823a0898aSmrgcopyright notice and this permission notice appear in supporting 923a0898aSmrgdocumentation. 1023a0898aSmrg 1123a0898aSmrgThe above copyright notice and this permission notice shall be included in 1223a0898aSmrgall copies or substantial portions of the Software. 1323a0898aSmrg 1423a0898aSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1523a0898aSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1623a0898aSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1723a0898aSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 1823a0898aSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 1923a0898aSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2023a0898aSmrg 2123a0898aSmrgExcept as contained in this notice, the name of The Open Group shall not be 2223a0898aSmrgused in advertising or otherwise to promote the sale, use or other dealings 2323a0898aSmrgin this Software without prior written authorization from The Open Group. 2423a0898aSmrg 2523a0898aSmrg*/ 2623a0898aSmrg 2723a0898aSmrg/* 2823a0898aSmrg * Author: Keith Packard, MIT X Consortium 2923a0898aSmrg */ 3023a0898aSmrg 3123a0898aSmrg#ifdef HAVE_CONFIG_H 3223a0898aSmrg#include <config.h> 3323a0898aSmrg#endif 3423a0898aSmrg#include <X11/fonts/fontmisc.h> 3523a0898aSmrg 3623a0898aSmrg/* Utility functions for reformating font bitmaps */ 3723a0898aSmrg 387f7f5e4eSmrgstatic const unsigned char _reverse_byte[0x100] = { 3923a0898aSmrg 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 4023a0898aSmrg 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, 4123a0898aSmrg 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, 4223a0898aSmrg 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, 4323a0898aSmrg 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, 4423a0898aSmrg 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, 4523a0898aSmrg 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, 4623a0898aSmrg 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, 4723a0898aSmrg 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, 4823a0898aSmrg 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, 4923a0898aSmrg 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, 5023a0898aSmrg 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, 5123a0898aSmrg 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, 5223a0898aSmrg 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, 5323a0898aSmrg 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, 5423a0898aSmrg 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, 5523a0898aSmrg 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, 5623a0898aSmrg 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, 5723a0898aSmrg 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, 5823a0898aSmrg 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, 5923a0898aSmrg 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, 6023a0898aSmrg 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, 6123a0898aSmrg 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, 6223a0898aSmrg 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, 6323a0898aSmrg 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, 6423a0898aSmrg 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, 6523a0898aSmrg 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, 6623a0898aSmrg 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, 6723a0898aSmrg 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, 6823a0898aSmrg 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, 6923a0898aSmrg 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, 7023a0898aSmrg 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff 7123a0898aSmrg}; 7223a0898aSmrg 7323a0898aSmrg/* 7423a0898aSmrg * Invert bit order within each BYTE of an array. 7523a0898aSmrg */ 7623a0898aSmrgvoid 7723a0898aSmrgBitOrderInvert(unsigned char *buf, int nbytes) 7823a0898aSmrg{ 797f7f5e4eSmrg const unsigned char *rev = _reverse_byte; 8023a0898aSmrg 8123a0898aSmrg for (; --nbytes >= 0; buf++) 8223a0898aSmrg *buf = rev[*buf]; 8323a0898aSmrg} 8423a0898aSmrg 8523a0898aSmrg/* 8623a0898aSmrg * Invert byte order within each 16-bits of an array. 8723a0898aSmrg */ 8823a0898aSmrgvoid 8923a0898aSmrgTwoByteSwap(unsigned char *buf, int nbytes) 9023a0898aSmrg{ 9123a0898aSmrg unsigned char c; 9223a0898aSmrg 9323a0898aSmrg for (; nbytes > 0; nbytes -= 2, buf += 2) 9423a0898aSmrg { 9523a0898aSmrg c = buf[0]; 9623a0898aSmrg buf[0] = buf[1]; 9723a0898aSmrg buf[1] = c; 9823a0898aSmrg } 9923a0898aSmrg} 10023a0898aSmrg 10123a0898aSmrg/* 10223a0898aSmrg * Invert byte order within each 32-bits of an array. 10323a0898aSmrg */ 10423a0898aSmrgvoid 10523a0898aSmrgFourByteSwap(unsigned char *buf, int nbytes) 10623a0898aSmrg{ 10723a0898aSmrg unsigned char c; 10823a0898aSmrg 10941c30155Smrg for (; nbytes > 0; nbytes -= 4, buf += 4) 11023a0898aSmrg { 11123a0898aSmrg c = buf[0]; 11223a0898aSmrg buf[0] = buf[3]; 11323a0898aSmrg buf[3] = c; 11423a0898aSmrg c = buf[1]; 11523a0898aSmrg buf[1] = buf[2]; 11623a0898aSmrg buf[2] = c; 11723a0898aSmrg } 11823a0898aSmrg} 11923a0898aSmrg 12023a0898aSmrg/* 12123a0898aSmrg * Repad a bitmap 12223a0898aSmrg */ 12323a0898aSmrg 12423a0898aSmrgint 12541c30155SmrgRepadBitmap (char *pSrc, char *pDst, 12641c30155Smrg unsigned int srcPad, unsigned int dstPad, 12723a0898aSmrg int width, int height) 12823a0898aSmrg{ 12923a0898aSmrg int srcWidthBytes,dstWidthBytes; 13023a0898aSmrg int row,col; 13123a0898aSmrg char *pTmpSrc,*pTmpDst; 13223a0898aSmrg 13323a0898aSmrg switch (srcPad) { 13441c30155Smrg case 1: 13523a0898aSmrg srcWidthBytes = (width+7)>>3; 13623a0898aSmrg break; 13723a0898aSmrg case 2: 13823a0898aSmrg srcWidthBytes = ((width+15)>>4)<<1; 13923a0898aSmrg break; 14041c30155Smrg case 4: 14123a0898aSmrg srcWidthBytes = ((width+31)>>5)<<2; 14223a0898aSmrg break; 14341c30155Smrg case 8: 14441c30155Smrg srcWidthBytes = ((width+63)>>6)<<3; 14523a0898aSmrg break; 14623a0898aSmrg default: 14723a0898aSmrg return 0; 14823a0898aSmrg } 14923a0898aSmrg switch (dstPad) { 15041c30155Smrg case 1: 15123a0898aSmrg dstWidthBytes = (width+7)>>3; 15223a0898aSmrg break; 15323a0898aSmrg case 2: 15423a0898aSmrg dstWidthBytes = ((width+15)>>4)<<1; 15523a0898aSmrg break; 15641c30155Smrg case 4: 15723a0898aSmrg dstWidthBytes = ((width+31)>>5)<<2; 15823a0898aSmrg break; 15941c30155Smrg case 8: 16041c30155Smrg dstWidthBytes = ((width+63)>>6)<<3; 16123a0898aSmrg break; 16223a0898aSmrg default: 16323a0898aSmrg return 0; 16423a0898aSmrg } 16523a0898aSmrg 16623a0898aSmrg width = srcWidthBytes; 16723a0898aSmrg if (width > dstWidthBytes) 16823a0898aSmrg width = dstWidthBytes; 16923a0898aSmrg pTmpSrc= pSrc; 17023a0898aSmrg pTmpDst= pDst; 17123a0898aSmrg for (row = 0; row < height; row++) 17223a0898aSmrg { 17323a0898aSmrg for (col = 0; col < width; col++) 17423a0898aSmrg *pTmpDst++ = *pTmpSrc++; 17523a0898aSmrg while (col < dstWidthBytes) 17623a0898aSmrg { 17723a0898aSmrg *pTmpDst++ = '\0'; 17823a0898aSmrg col++; 17923a0898aSmrg } 18023a0898aSmrg pTmpSrc += srcWidthBytes - width; 18123a0898aSmrg } 18223a0898aSmrg return dstWidthBytes * height; 18323a0898aSmrg} 18423a0898aSmrg 18523a0898aSmrg 186