home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / VGX / blob / readImageRGB.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  1.7 KB  |  61 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include "gl/image.h"
  18.  
  19. #define Pack(r,g,b,a) ((int)(r) | ((int)(g) << 8) | ((int)(b) << 16) | ((int)(a) << 24))
  20.  
  21. unsigned long *
  22. readImageRGB(name, w, h)
  23.     char *        name;
  24.     int            *w, *h;
  25. {
  26.     unsigned long   *image;
  27.     IMAGE        *image_in;
  28.     int            row, components;
  29.     unsigned long   *scan;
  30.  
  31.     if ( (image_in = iopen(name, "r")) == NULL) { 
  32.     return 0;
  33.     }
  34.  
  35.     *w = image_in->xsize;
  36.     *h = image_in->ysize;
  37.     components = image_in->zsize;
  38.  
  39.     if (components != 3)
  40.     return 0;
  41.  
  42.     image = (unsigned long *)malloc(sizeof(unsigned long) * *w * *h);
  43.  
  44.     scan = image;
  45.  
  46.     for (row = 0; row < *h; row++) {
  47.     short        rowbuff[3][4096];
  48.     int        i;
  49.  
  50.     getrow(image_in, rowbuff[0], row, 0);
  51.     getrow(image_in, rowbuff[1], row, 1);
  52.     getrow(image_in, rowbuff[2], row, 2);
  53.     for (i = 0; i < *w; i++)
  54.         *(scan++) = 
  55.         Pack(rowbuff[0][i], rowbuff[1][i], rowbuff[2][i], 0);
  56.     }
  57.  
  58.     iclose(image_in);    
  59.     return image;
  60. }
  61.