Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
RLE.m
Go to the documentation of this file.
1 #import "RLE.h"
2 #import <stdio.h>
3 #import <stdlib.h>
4 #import <string.h>
5 #import <libc.h>
6 #import <zone.h>
7 #import <mach.h>
8 #import <appkit/Window.h>
9 #import <appkit/Panel.h>
10 #import <appkit/tiff.h>
11 
12 // RLE.m
13 //
14 // Written by Vince DeMarco
15 // demarco@cpsc.ucalgary.ca
16 //
17 // This program is In the Public Domain. If you make any improvements to this
18 // program please let me know
19 //
20 
21 @implementation RLE:Image
22 
23 - init
24 {
25  self = [super init];
26  strncpy(windowIconName,"rle.icon.tiff",14);
27  rle_file_hdr = *rle_hdr_init( (rle_hdr *)NULL );
28  return(self);
29 }
30 
31 - open:(char *)filename
32 {
33  int i,j,row_pos;
34 
35  rle_pixel **scan;
36 
37  thisview = self;
38  rmap = 0;
39 
40  strncpy(fileName,filename,1024);
42  rle_names( &rle_file_hdr, "RLEViewer", filename, 0 );
43 
44  if (rle_file_hdr.rle_file == NULL) {
45  NXRunAlertPanel("RLE ERROR", "Can't open %s", NULL, NULL, NULL, fileName);
46  return(self);
47  }
48 
49 
50  //Read in the header from the RLE file
52  NXRunAlertPanel("RLE ERROR", "%s Not an RLE file ", NULL, NULL, NULL, fileName);
53  return(self);
54  }
55 
58 
62 
63  if (rle_file_hdr.alpha && (numColors == 3))
64  numColors++;
65 
66  if (rle_row_alloc(&rle_file_hdr,&scan) < 0){
67  NXRunAlertPanel("RLE ERROR", "%s Malloc Error ", NULL, NULL, NULL, fileName);
68  return(self);
69  }
70 
71  // Read each scan line into memory ready for displaying.
72  if (numColors == 1){
73  r = (unsigned char *)NXZoneMalloc(newZone,ysize*xsize*(sizeof(unsigned char)));
74  for (i = ysize; i > 0; i--) {
75 
77  j = i*xsize;
78  row_pos = 0;
79 
80  while(j <= (i*xsize)+xsize){ // Copy each scanline into a temp
81  r[j]=scan[0][row_pos]; // dataspace
82  j++;
83  row_pos++;
84  }
85  }
86  }
87  if (numColors == 3){
88  r = (unsigned char *)NXZoneMalloc(newZone,ysize*xsize*(sizeof(unsigned char)));
89  g = (unsigned char *)NXZoneMalloc(newZone,ysize*xsize*(sizeof(unsigned char)));
90  b = (unsigned char *)NXZoneMalloc(newZone,ysize*xsize*(sizeof(unsigned char)));
91  for (i = ysize; i > 0; i--) {
92 
94  j = i*xsize;
95  row_pos = 0;
96 
97  while(j <= (i*xsize)+xsize){ // Copy each scanline into a temp
98  r[j]=scan[0][row_pos]; // dataspace
99  g[j]=scan[1][row_pos];
100  b[j]=scan[2][row_pos];
101  j++;
102  row_pos++;
103  }
104  }
105  }
106 
107  if (numColors == 4){
108  r = (unsigned char *)NXZoneMalloc(newZone,ysize*xsize*(sizeof(unsigned char)));
109  g = (unsigned char *)NXZoneMalloc(newZone,ysize*xsize*(sizeof(unsigned char)));
110  b = (unsigned char *)NXZoneMalloc(newZone,ysize*xsize*(sizeof(unsigned char)));
111  a = (unsigned char *)NXZoneMalloc(newZone,ysize*xsize*(sizeof(unsigned char)));
112 
113  for (i = ysize; i > 0; i--) {
114 
116  j = i*xsize;
117  row_pos = 0;
118 
119  while(j <= (i*xsize)+xsize){ // Copy each scanline into a temp
120  r[j]=scan[0] [row_pos]; // dataspace
121  g[j]=scan[1] [row_pos];
122  b[j]=scan[2] [row_pos];
123  a[j]=scan[-1][row_pos];
124  j++;
125  row_pos++;
126  }
127  }
128  }
129 
130  // Program WILL DIE if you have a file with a valid rle header but
131  // nothing for it to read, it will read the NOTHING in but when you
132  // try to render it, the program will die.
133 
135  fclose(rle_file_hdr.rle_file);
136  [self displayImage];
137  return(self);
138 }
139 
140 @end
int xmin
Definition: rle.h:100
unsigned char * g
Definition: Image.h:20
struct rle_hdr rle_file_hdr
Definition: RLE.h:15
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
Definition: rle_hdr.c:48
void rle_row_free(rle_hdr *the_hdr, rle_pixel **scanp)
Definition: rle_row_alc.c:114
id init()
int rle_get_setup(rle_hdr *the_hdr)
Definition: rle_getrow.c:74
int rle_row_alloc(rle_hdr *the_hdr, rle_pixel ***scanp)
Definition: rle_row_alc.c:56
int rle_getrow(rle_hdr *the_hdr, scanline)
Definition: rle_getrow.c:333
unsigned char * r
Definition: Image.h:20
#define RLE_SUCCESS
Definition: rle.h:70
int ymin
Definition: rle.h:100
unsigned char * a
Definition: Image.h:20
char fileName[1024]
Definition: Image.h:22
int xmax
Definition: rle.h:100
id init()
Definition: RLE.h:13
unsigned char * b
Definition: Image.h:20
void * rmap
Definition: Image.h:19
id displayImage()
Definition: Image.m:36
FILE * rle_open_f_noexit(char *prog_name, char *file_name, char *mode)
Definition: rle_open_f.c:57
int ymax
Definition: rle.h:100
unsigned char rle_pixel
Definition: rle.h:56
int alpha
Definition: rle.h:100
int ysize
Definition: Image.h:18
int xsize
Definition: Image.h:18
id open:(char *filename)
Definition: RLE.m:31
id thisview
Definition: Image.h:16
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267
int numColors
Definition: Image.h:24
FILE * rle_file
Definition: rle.h:114
int ncolors
Definition: rle.h:100
char windowIconName[1024]
Definition: Image.h:23