/[dtapublic]/to_be_filed/sf_code/esrgpcpj/shared/tk_base/tkimgutil.c
ViewVC logotype

Contents of /to_be_filed/sf_code/esrgpcpj/shared/tk_base/tkimgutil.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 29 - (show annotations) (download)
Sat Oct 8 07:08:47 2016 UTC (7 years, 5 months ago) by dashley
File MIME type: text/plain
File size: 2388 byte(s)
Directories relocated.
1 /* $Header: /cvsroot/esrg/sfesrg/esrgpcpj/shared/tk_base/tkimgutil.c,v 1.1.1.1 2001/06/13 05:03:31 dtashley Exp $ */
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
83 /* $History: tkImgUtil.c $
84 *
85 * ***************** Version 1 *****************
86 * User: Dtashley Date: 1/02/01 Time: 2:53a
87 * Created in $/IjuScripter, IjuConsole/Source/Tk Base
88 * Initial check-in.
89 */
90
91 /* End of TKIMGUTIL.C */

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25