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

Diff of /projs/ets/trunk/src/c_tk_base_7_5_w_mods/tkimgutil.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

projs/trunk/shared_source/tk_base/tkimgutil.c revision 42 by dashley, Fri Oct 14 01:50:00 2016 UTC projs/trunk/shared_source/c_tk_base_7_5_w_mods/tkimgutil.c revision 71 by dashley, Sat Nov 5 11:07:06 2016 UTC
# Line 1  Line 1 
 /* $Header: /cvsroot/esrg/sfesrg/esrgpcpj/shared/tk_base/tkimgutil.c,v 1.1.1.1 2001/06/13 05:03:31 dtashley Exp $ */  
   
 /*  
  * tkImgUtil.c --  
  *  
  *      This file contains image related utility functions.  
  *  
  * Copyright (c) 1995 Sun Microsystems, Inc.  
  *  
  * See the file "license.terms" for information on usage and redistribution  
  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.  
  *  
  * RCS: @(#) $Id: tkimgutil.c,v 1.1.1.1 2001/06/13 05:03:31 dtashley Exp $  
  */  
   
 #include "tkInt.h"  
 #include "tkPort.h"  
 #include "xbytes.h"  
   
   
 /*  
  *----------------------------------------------------------------------  
  *  
  * TkAlignImageData --  
  *  
  *      This function takes an image and copies the data into an  
  *      aligned buffer, performing any necessary bit swapping.  
  *  
  * Results:  
  *      Returns a newly allocated buffer that should be freed by the  
  *      caller.  
  *  
  * Side effects:  
  *      None.  
  *  
  *----------------------------------------------------------------------  
  */  
   
 char *  
 TkAlignImageData(image, alignment, bitOrder)  
     XImage *image;              /* Image to be aligned. */  
     int alignment;              /* Number of bytes to which the data should  
                                  * be aligned (e.g. 2 or 4) */  
     int bitOrder;               /* Desired bit order: LSBFirst or MSBFirst. */  
 {  
     long dataWidth;  
     char *data, *srcPtr, *destPtr;  
     int i, j;  
   
     if (image->bits_per_pixel != 1) {  
         panic("TkAlignImageData: Can't handle image depths greater than 1.");  
     }  
   
     /*  
      * Compute line width for output data buffer.  
      */  
   
     dataWidth = image->bytes_per_line;  
     if (dataWidth % alignment) {  
         dataWidth += (alignment - (dataWidth % alignment));  
     }  
   
     data = ckalloc(dataWidth * image->height);  
   
     destPtr = data;  
     for (i = 0; i < image->height; i++) {  
         srcPtr = &image->data[i * image->bytes_per_line];  
         for (j = 0; j < dataWidth; j++) {  
             if (j >= image->bytes_per_line) {  
                 *destPtr = 0;  
             } else if (image->bitmap_bit_order != bitOrder) {  
                 *destPtr = xBitReverseTable[(unsigned char)(*(srcPtr++))];  
             } else {  
                 *destPtr = *(srcPtr++);  
             }  
             destPtr++;  
         }  
     }  
     return data;  
 }  
   
   
 /* $History: tkImgUtil.c $  
  *  
  * *****************  Version 1  *****************  
  * User: Dtashley     Date: 1/02/01    Time: 2:53a  
  * Created in $/IjuScripter, IjuConsole/Source/Tk Base  
  * Initial check-in.  
  */  
   
 /* End of TKIMGUTIL.C */  
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 */

Legend:
Removed from v.42  
changed lines
  Added in v.71

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25