home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / stk-3.002 / stk-3 / STk-3.1 / Tk / win / tkWinImage.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-17  |  2.8 KB  |  121 lines

  1. /* 
  2.  * tkWinImage.c --
  3.  *
  4.  *    This file contains routines for manipulation full-color images.
  5.  *
  6.  * Copyright (c) 1995 Sun Microsystems, Inc.
  7.  *
  8.  * See the file "license.terms" for information on usage and redistribution
  9.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  10.  *
  11.  * SCCS: @(#) tkWinImage.c 1.4 96/02/15 18:56:16
  12.  */
  13.  
  14. #include "tkWinInt.h"
  15.  
  16. static int        PutPixel _ANSI_ARGS_((XImage *image, int x, int y,
  17.                 unsigned long pixel));
  18.  
  19. /*
  20.  *----------------------------------------------------------------------
  21.  *
  22.  * PutPixel --
  23.  *
  24.  *    Set a single pixel in an image.
  25.  *
  26.  * Results:
  27.  *    None.
  28.  *
  29.  * Side effects:
  30.  *    None.
  31.  *
  32.  *----------------------------------------------------------------------
  33.  */
  34.  
  35. static int
  36. PutPixel(image, x, y, pixel)
  37.     XImage *image;
  38.     int x, y;
  39.     unsigned long pixel;
  40. {
  41.     char *destPtr = &(image->data[(y * image->bytes_per_line)
  42.         + (x * (image->bits_per_pixel >> 3))]);
  43.     destPtr[0] = GetBValue(pixel);
  44.     destPtr[1] = GetGValue(pixel);
  45.     destPtr[2] = GetRValue(pixel);
  46.     return 0;
  47. }
  48.  
  49. /*
  50.  *----------------------------------------------------------------------
  51.  *
  52.  * XCreateImage --
  53.  *
  54.  *    Allocates storage for a new XImage.
  55.  *
  56.  * Results:
  57.  *    Returns a newly allocated XImage.
  58.  *
  59.  * Side effects:
  60.  *    None.
  61.  *
  62.  *----------------------------------------------------------------------
  63.  */
  64.  
  65. XImage *
  66. XCreateImage(display, visual, depth, format, offset, data, width, height,
  67.     bitmap_pad, bytes_per_line)
  68.     Display* display;
  69.     Visual* visual;
  70.     unsigned int depth;
  71.     int format;
  72.     int offset;
  73.     char* data;
  74.     unsigned int width;
  75.     unsigned int height;
  76.     int bitmap_pad;
  77.     int bytes_per_line;
  78. {
  79.     XImage* imagePtr = (XImage *) ckalloc(sizeof(XImage));
  80.     imagePtr->width = width;
  81.     imagePtr->height = height;
  82.     imagePtr->xoffset = offset;
  83.     imagePtr->format = format;
  84.     imagePtr->data = data;
  85.     imagePtr->byte_order = LSBFirst;
  86.     imagePtr->bitmap_unit = 32;
  87.     imagePtr->bitmap_bit_order = LSBFirst;
  88.     imagePtr->bitmap_pad = bitmap_pad;
  89.     imagePtr->depth = depth;
  90.  
  91.     /*
  92.      * Round to the nearest word boundary.
  93.      */
  94.     
  95.     imagePtr->bytes_per_line = bytes_per_line ? bytes_per_line
  96.      : ((depth * width + 31) >> 3) & ~3;
  97.  
  98.     /*
  99.      * If the screen supports TrueColor, then we use 3 bytes per pixel, and
  100.      * we have to install our own pixel routine.
  101.      */
  102.     
  103.     if (visual->class == TrueColor) {
  104.     imagePtr->bits_per_pixel = 24;
  105.     imagePtr->f.put_pixel = PutPixel;
  106.     } else {
  107.     imagePtr->bits_per_pixel = 8;
  108.     imagePtr->f.put_pixel = NULL;
  109.     }
  110.     imagePtr->red_mask = visual->red_mask;
  111.     imagePtr->green_mask = visual->green_mask;
  112.     imagePtr->blue_mask = visual->blue_mask;
  113.     imagePtr->f.create_image = NULL;
  114.     imagePtr->f.destroy_image = NULL;
  115.     imagePtr->f.get_pixel = NULL;
  116.     imagePtr->f.sub_image = NULL;
  117.     imagePtr->f.add_pixel = NULL;
  118.     
  119.     return imagePtr;
  120. }
  121.