Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
RASF.m
Go to the documentation of this file.
1 #import "RASF.h"
2 #import <stdio.h>
3 #import <stdlib.h>
4 #import <libc.h>
5 #import <zone.h>
6 #import <mach.h>
7 #import <appkit/Window.h>
8 #import <appkit/Panel.h>
9 #import <appkit/tiff.h>
10 
11 // RASF.m
12 //
13 // Written by Vince DeMarco
14 // demarco@cpsc.ucalgary.ca
15 //
16 // This program is In the Public Domain. If you make any improvements to this
17 // program please let me know
18 //
19 
20 @implementation RASF:Image
21 
22 - init
23 {
24  self = [super init];
25  strncpy(windowIconName,"rasf.icon.tiff",14);
26  return(self);
27 }
28 
29 // The open method written below is
30 // Based on code Written By Thomas Orth
31 // orth@cpsc.ucalgary.ca
32 //
33 // Acually almost completely copied from Tom, I just changed a few variables
34 // and other meaningless stuff like that.
35 //
36 -open:(char *)filename
37 {
38  NXStream *fp;
39  int x,y;
40  int i;
41  unsigned char red,green,blue,n;
42  unsigned char buf[80];
43  int count = 0;
44 
45  thisview = self;
46  rmap = 0;
47  strncpy(fileName,filename,1024);
48  if ((fp = NXMapFile(fileName,NX_READONLY)) == NULL) {
49  NXRunAlertPanel("RASF ERROR", "Can't open %s", NULL, NULL, NULL, fileName);
50  return(self);
51  }
52 
53  //Read in the header from the RASF file
54  NXRead(fp,buf,sizeof(char)*8);
55  if(strncmp((char *)buf,"gl RASF",8)){
56  NXRunAlertPanel("RASF ERROR", "%s Not an RASF file ", NULL, NULL, NULL, fileName);
57  return(self);
58  }
59 
60  // Read in the size of the raster file from the header
61  for (i=0;i<2;i++){
62  NXRead(fp,&red,sizeof(char));
63  }
64  NXRead(fp,&red,sizeof(char));
65  NXRead(fp,&green,sizeof(char));
66  xsize=red*256+green;
67 
68  for (i=0;i<2;i++){
69  NXRead(fp,&red,sizeof(char));
70  }
71  NXRead(fp,&red,sizeof(char));
72  NXRead(fp,&green,sizeof(char));
73  ysize=red*256+green;
74 
75  // Now comes the erase values which we will just ignore
76  for (i=0;i<64;i++){
77  NXRead(fp,&red,sizeof(char));
78  }
79 
80  // Allocate three buffers to store the R,G,B Triplets
81  r = (unsigned char *)NXZoneMalloc(newZone,ysize*xsize*(sizeof(unsigned char)));
82  g = (unsigned char *)NXZoneMalloc(newZone,ysize*xsize*(sizeof(unsigned char)));
83  b = (unsigned char *)NXZoneMalloc(newZone,ysize*xsize*(sizeof(unsigned char)));
84 
85  i = 0;
86  for (y=(ysize-1);y>=0;y--){
87  for (x=0;x<xsize;x++){
88  if (count == 0){
89  NXRead(fp,&red,sizeof(char));
90  NXRead(fp,&green,sizeof(char));
91  NXRead(fp,&blue,sizeof(char));
92  NXRead(fp,&n,sizeof(char));
93  r[i] = red;
94  g[i] = green;
95  b[i] = blue;
96  i++;
97  count=n;
98  }else{
99  count--;
100  r[i] = red;
101  g[i] = green;
102  b[i] = blue;
103  i++;
104  }
105  }
106  }
107 
108  numColors = 3;
109  [self displayImage];
110  NXCloseMemory(fp,NX_FREEBUFFER);
111  return(self);
112 }
113 
114 @end
unsigned char * g
Definition: Image.h:20
unsigned char * r
Definition: Image.h:20
char fileName[1024]
Definition: Image.h:22
id init()
unsigned char * b
Definition: Image.h:20
void * rmap
Definition: Image.h:19
id displayImage()
Definition: Image.m:36
int ysize
Definition: Image.h:18
int xsize
Definition: Image.h:18
id thisview
Definition: Image.h:16
id init()
Definition: RASF.h:13
int numColors
Definition: Image.h:24
id open:(char *filename)
Definition: RASF.m:36
char windowIconName[1024]
Definition: Image.h:23