/[dtapublic]/projs/trunk/shared_source/c_tk_base_7_5_w_mods/tkimgutil.c
ViewVC logotype

Contents of /projs/trunk/shared_source/c_tk_base_7_5_w_mods/tkimgutil.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 71 - (show annotations) (download)
Sat Nov 5 11:07:06 2016 UTC (7 years, 4 months ago) by dashley
File MIME type: text/plain
File size: 1982 byte(s)
Set EOL properties appropriately to facilitate simultaneous Linux and Windows development.
1 /* $Header$ */
2
3 /*
4 * tkImgUtil.c --
5 *
6 * This file contains image related utility functions.
7 *
8 * Copyright (c) 1995 Sun Microsystems, Inc.
9 *
10 * See the file "license.terms" for information on usage and redistribution
11 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12 *
13 * RCS: @(#) $Id: tkimgutil.c,v 1.1.1.1 2001/06/13 05:03:31 dtashley Exp $
14 */
15
16 #include "tkInt.h"
17 #include "tkPort.h"
18 #include "xbytes.h"
19
20
21 /*
22 *----------------------------------------------------------------------
23 *
24 * TkAlignImageData --
25 *
26 * This function takes an image and copies the data into an
27 * aligned buffer, performing any necessary bit swapping.
28 *
29 * Results:
30 * Returns a newly allocated buffer that should be freed by the
31 * caller.
32 *
33 * Side effects:
34 * None.
35 *
36 *----------------------------------------------------------------------
37 */
38
39 char *
40 TkAlignImageData(image, alignment, bitOrder)
41 XImage *image; /* Image to be aligned. */
42 int alignment; /* Number of bytes to which the data should
43 * be aligned (e.g. 2 or 4) */
44 int bitOrder; /* Desired bit order: LSBFirst or MSBFirst. */
45 {
46 long dataWidth;
47 char *data, *srcPtr, *destPtr;
48 int i, j;
49
50 if (image->bits_per_pixel != 1) {
51 panic("TkAlignImageData: Can't handle image depths greater than 1.");
52 }
53
54 /*
55 * Compute line width for output data buffer.
56 */
57
58 dataWidth = image->bytes_per_line;
59 if (dataWidth % alignment) {
60 dataWidth += (alignment - (dataWidth % alignment));
61 }
62
63 data = ckalloc(dataWidth * image->height);
64
65 destPtr = data;
66 for (i = 0; i < image->height; i++) {
67 srcPtr = &image->data[i * image->bytes_per_line];
68 for (j = 0; j < dataWidth; j++) {
69 if (j >= image->bytes_per_line) {
70 *destPtr = 0;
71 } else if (image->bitmap_bit_order != bitOrder) {
72 *destPtr = xBitReverseTable[(unsigned char)(*(srcPtr++))];
73 } else {
74 *destPtr = *(srcPtr++);
75 }
76 destPtr++;
77 }
78 }
79 return data;
80 }
81
82 /* End of tkimgutil.c */

Properties

Name Value
svn:eol-style native
svn:keywords Header

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25