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

Legend:
Removed from v.69  
changed lines
  Added in v.220

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25