Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 107 lines (75 sloc) 2.717 kb
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
1 #include "image.h"
2 #include <stdio.h>
895dbd3 Replaced i_readraw() and i_writeraw() with the equivalent _wiol function...
Arnar Mar Hrafnkelsson authored
3 #include "iolayer.h"
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
4 #ifndef _MSC_VER
5 #include <unistd.h>
6 #endif
7 #include <string.h>
8
895dbd3 Replaced i_readraw() and i_writeraw() with the equivalent _wiol function...
Arnar Mar Hrafnkelsson authored
9
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
10 #define TRUE 1
11 #define FALSE 0
12
13 #define BSIZ 100*BUFSIZ
14
15 /*
16
17 Image loader for raw files.
18
19 This is a barebones raw loader...
20
21 fd: filedescriptor
22 x: xsize
23 y: ysize
24 datachannels: the number of channels the file contains
25 storechannels: the bitmap of channels we will read
26 intrl: interlace flag,
27 0 = sample interleaving
28 1 = line interleaving
29 2 = image interleaving
30
31 */
32
33 void
34 expandchannels(unsigned char *inbuffer,unsigned char *outbuffer,int chunks,int datachannels,int storechannels) {
35 int ch,i;
36 if (inbuffer==outbuffer) return; /* Check if data is already in expanded format */
37 for(ch=0;ch<chunks;ch++) for (i=0;i<storechannels;i++) outbuffer[ch*storechannels+i]=inbuffer[ch*datachannels+i];
38 }
39
40 i_img *
895dbd3 Replaced i_readraw() and i_writeraw() with the equivalent _wiol function...
Arnar Mar Hrafnkelsson authored
41 i_readraw_wiol(io_glue *ig, int x, int y, int datachannels, int storechannels, int intrl) {
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
42 i_img* im;
43 int rc,k;
44
45 unsigned char *inbuffer;
46 unsigned char *ilbuffer;
47 unsigned char *exbuffer;
48
49 int inbuflen,ilbuflen,exbuflen;
50
895dbd3 Replaced i_readraw() and i_writeraw() with the equivalent _wiol function...
Arnar Mar Hrafnkelsson authored
51 io_glue_commit_types(ig);
52 mm_log((1, "i_readraw(ig %p,x %d,y %d,datachannels %d,storechannels %d,intrl %d)\n",
53 ig, x, y, datachannels, storechannels, intrl));
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
54
895dbd3 Replaced i_readraw() and i_writeraw() with the equivalent _wiol function...
Arnar Mar Hrafnkelsson authored
55 im = i_img_empty_ch(NULL,x,y,storechannels);
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
56
895dbd3 Replaced i_readraw() and i_writeraw() with the equivalent _wiol function...
Arnar Mar Hrafnkelsson authored
57 inbuflen = im->xsize*datachannels;
58 ilbuflen = inbuflen;
59 exbuflen = im->xsize*storechannels;
60 inbuffer = (unsigned char*)mymalloc(inbuflen);
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
61 mm_log((1,"inbuflen: %d, ilbuflen: %d, exbuflen: %d.\n",inbuflen,ilbuflen,exbuflen));
62
63 if (intrl==0) ilbuffer=inbuffer; else ilbuffer=(unsigned char*)mymalloc(inbuflen);
64 if (datachannels==storechannels) exbuffer=ilbuffer; else exbuffer=(unsigned char*)mymalloc(exbuflen);
65
66 k=0;
67 while(k<im->ysize) {
895dbd3 Replaced i_readraw() and i_writeraw() with the equivalent _wiol function...
Arnar Mar Hrafnkelsson authored
68 rc = ig->readcb(ig, inbuffer, inbuflen);
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
69 if (rc!=inbuflen) { fprintf(stderr,"Premature end of file.\n"); exit(2); }
70 interleave(inbuffer,ilbuffer,im->xsize,datachannels);
71 expandchannels(ilbuffer,exbuffer,im->xsize,datachannels,storechannels);
72 memcpy(&(im->data[im->xsize*storechannels*k]),exbuffer,exbuflen);
73 k++;
74 }
75
76 myfree(inbuffer);
77 if (intrl!=0) myfree(ilbuffer);
78 if (datachannels!=storechannels) myfree(exbuffer);
79 return im;
80 }
81
82
83
84 undef_int
895dbd3 Replaced i_readraw() and i_writeraw() with the equivalent _wiol function...
Arnar Mar Hrafnkelsson authored
85 i_writeraw_wiol(i_img* im, io_glue *ig) {
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
86 int rc;
895dbd3 Replaced i_readraw() and i_writeraw() with the equivalent _wiol function...
Arnar Mar Hrafnkelsson authored
87 io_glue_commit_types(ig);
88 mm_log((1,"writeraw(im %p,ig %p)\n", im, ig));
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
89
90 if (im == NULL) { mm_log((1,"Image is empty\n")); return(0); }
895dbd3 Replaced i_readraw() and i_writeraw() with the equivalent _wiol function...
Arnar Mar Hrafnkelsson authored
91 rc = ig->writecb(ig, im->data, im->bytes);
92 if (rc != im->bytes) {
93 mm_log((1,"i_writeraw: Couldn't write to file\n"));
94 return(0);
95 }
02d1d62 Initial revision
Arnar Mar Hrafnkelsson authored
96 return(1);
97 }
98
99
100
101
102
103
104
105
106
Something went wrong with that request. Please try again.