| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#include "tkInt.h" |
| 15 |
#include "tkPort.h" |
| 16 |
#include "xbytes.h" |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
char * |
| 38 |
TkAlignImageData(image, alignment, bitOrder) |
| 39 |
XImage *image; |
| 40 |
int alignment; |
| 41 |
|
| 42 |
int bitOrder; |
| 43 |
{ |
| 44 |
long dataWidth; |
| 45 |
char *data, *srcPtr, *destPtr; |
| 46 |
int i, j; |
| 47 |
|
| 48 |
if (image->bits_per_pixel != 1) { |
| 49 |
Tcl_Panic("TkAlignImageData: Can't handle image depths greater than 1."); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
dataWidth = image->bytes_per_line; |
| 57 |
if (dataWidth % alignment) { |
| 58 |
dataWidth += (alignment - (dataWidth % alignment)); |
| 59 |
} |
| 60 |
|
| 61 |
data = ckalloc(dataWidth * image->height); |
| 62 |
|
| 63 |
destPtr = data; |
| 64 |
for (i = 0; i < image->height; i++) { |
| 65 |
srcPtr = &image->data[i * image->bytes_per_line]; |
| 66 |
for (j = 0; j < dataWidth; j++) { |
| 67 |
if (j >= image->bytes_per_line) { |
| 68 |
*destPtr = 0; |
| 69 |
} else if (image->bitmap_bit_order != bitOrder) { |
| 70 |
*destPtr = xBitReverseTable[(unsigned char)(*(srcPtr++))]; |
| 71 |
} else { |
| 72 |
*destPtr = *(srcPtr++); |
| 73 |
} |
| 74 |
destPtr++; |
| 75 |
} |
| 76 |
} |
| 77 |
return data; |
| 78 |
} |