4 * This file contains image related utility functions.
6 * Copyright (c) 1995 Sun Microsystems, Inc.
8 * See the file "license.terms" for information on usage and redistribution
9 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
20 *----------------------------------------------------------------------
24 * This function takes an image and copies the data into an
25 * aligned buffer, performing any necessary bit swapping.
28 * Returns a newly allocated buffer that should be freed by the
34 *----------------------------------------------------------------------
38 TkAlignImageData(image, alignment, bitOrder)
39 XImage *image; /* Image to be aligned. */
40 int alignment; /* Number of bytes to which the data should
41 * be aligned (e.g. 2 or 4) */
42 int bitOrder; /* Desired bit order: LSBFirst or MSBFirst. */
45 char *data, *srcPtr, *destPtr;
48 if (image->bits_per_pixel != 1) {
49 panic("TkAlignImageData: Can't handle image depths greater than 1.");
53 * Compute line width for output data buffer.
56 dataWidth = image->bytes_per_line;
57 if (dataWidth % alignment) {
58 dataWidth += (alignment - (dataWidth % alignment));
61 data = ckalloc(dataWidth * image->height);
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) {
69 } else if (image->bitmap_bit_order != bitOrder) {
70 *destPtr = xBitReverseTable[(unsigned char)(*(srcPtr++))];
72 *destPtr = *(srcPtr++);