~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/file/ras/ras_io.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**@(#)Functions to read RASTER image file
  2 */
  3 
  4 #include <stdio.h>
  5 #include <string.h>
  6 #include <tina/file.h>
  7 #include <tina/sys.h>
  8 #include <tina/sys_types.h>
  9 #include <tina/sysfuncs.h>
 10 
 11 Imrect *ras_read_image(char *pathname, Vartype  vtype){
 12     Imregion       *region, *roi_alloc();
 13     Imrect         *image, *im_alloc();
 14     FILE           *fd;
 15     void           *row;
 16     int             row_length;
 17     int             lx, ly, uy, i;
 18     double          offset;
 19     int             height, width, magic, depth, length, type;
 20     int             maptype, maplength, j=0;
 21     unsigned char   *temps;
 22 
 23     if ((fd = fopen(pathname, "r")) == NULL){
 24         string_append(temps, "can not open file ", pathname, 0);
 25         error(temps, non_fatal);
 26         return (NULL);
 27     }
 28     fread((char *)&magic, sizeof(int), 1, fd);
 29     fread((char *)&width, sizeof(int), 1, fd);
 30     fread((char *)&height, sizeof(int), 1, fd);
 31     fread((char *)&depth, sizeof(int), 1, fd);
 32     fread((char *)&length, sizeof(int), 1, fd);
 33     fread((char *)&type, sizeof(int), 1, fd);
 34     fread((char *)&maptype, sizeof(int), 1, fd);
 35     fread((char *)&maplength, sizeof(int), 1, fd);
 36 
 37 /* width is rounded to the nearest 16 bits */
 38     width = 2*((width+1)/2);
 39     temps = (unsigned char *)ralloc(maplength);
 40     if((maptype != 0) || (maplength !=0)){
 41         fread(temps, 1, maplength, fd);
 42     }
 43     image = im_alloc(height, width, NULL, vtype);
 44 
 45     lx = image->region->lx;
 46     ly = image->region->ly;
 47     uy = image->region->uy;
 48     for (i = 0; i < height; ++i){
 49         IM_PIX_GETP(image, i, lx, row);
 50         fread(row, 1, width, fd);
 51     }
 52     if(maplength!=0){
 53         for(i=0; i<height; i++){
 54                 for(j=0; j<width; j++){
 55                         IM_PIX_GET(image, i, j, offset);
 56                         IM_PIX_SET(image, i, j, temps[(int)offset]);
 57                 }
 58         }
 59     }
 60     fclose(fd);
 61     rfree(temps);
 62     return (image);
 63 }
 64 
 65 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.