/[public]/psiconv/trunk/lib/psiconv/parse_image.c
ViewVC logotype

Diff of /psiconv/trunk/lib/psiconv/parse_image.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 11 Revision 12
20#include "config.h" 20#include "config.h"
21#include <stdlib.h> 21#include <stdlib.h>
22 22
23#include "data.h" 23#include "data.h"
24#include "parse_routines.h" 24#include "parse_routines.h"
25
26int psiconv_parse_mbm_jumptable_section(const psiconv_buffer buf,int lev,
27 psiconv_u32 off, int *length,
28 psiconv_mbm_jumptable_section *result)
29{
30 int res = 0;
31 int len = 0;
32 psiconv_u32 listlen,temp;
33 int i;
34
35 psiconv_progress(lev+1,off+len,"Going to read the mbm jumptable section");
36 (*result) = psiconv_list_new(sizeof(psiconv_u32));
37
38 psiconv_progress(lev+2,off+len,"Going to read the list length");
39 listlen = psiconv_read_u32(buf,lev+2,off+len);
40 psiconv_debug(lev+2,off+len,"List length: %08x",listlen);
41 len += 4;
42
43 psiconv_progress(lev+2,off+len,"Going to read the list");
44 for (i = 0; i < listlen; i++) {
45 temp = psiconv_read_u32(buf,lev+2,off+len);
46 psiconv_list_add(*result,&temp);
47 psiconv_debug(lev+3,off+len,"Offset: %08x",temp);
48 len += 4;
49 }
50
51 if (length)
52 *length = len;
53
54 psiconv_progress(lev+1,off+len-1,"End of mbm jumptable section "
55 "(total length: %08x", len);
56
57 return res;
58}
25 59
26int psiconv_parse_paint_data_section(const psiconv_buffer buf,int lev, 60int psiconv_parse_paint_data_section(const psiconv_buffer buf,int lev,
27 psiconv_u32 off, int *length, 61 psiconv_u32 off, int *length,
28 psiconv_paint_data_section *result) 62 psiconv_paint_data_section *result)
29{ 63{
30 int res = 0; 64 int res = 0;
31 int len = 0; 65 int len = 0;
66 int read_err = 0;
32 psiconv_u32 size,offset,picsize,temp,datasize,pixelnr,datanr; 67 psiconv_u32 size,offset,picsize,temp,datasize,pixelnr,datanr;
33 psiconv_u8 marker; 68 psiconv_u8 marker;
34 int i; 69 int i;
35 70
36 psiconv_progress(lev+1,off,"Going to read a paint data section"); 71 psiconv_progress(lev+1,off,"Going to read a paint data section");
46 if (size != 0x28) { 81 if (size != 0x28) {
47 psiconv_warn(lev+2,off+len, 82 psiconv_warn(lev+2,off+len,
48 "Paint data section data offset has unexpected value"); 83 "Paint data section data offset has unexpected value");
49 psiconv_debug(lev+2,off+len, 84 psiconv_debug(lev+2,off+len,
50 "Data offset: read %08x, expected %08x",offset,0x28); 85 "Data offset: read %08x, expected %08x",offset,0x28);
86 res = -1;
51 } 87 }
52 len += 4; 88 len += 4;
53 89
54 psiconv_progress(lev+2,off+len,"Going to read picture X size"); 90 psiconv_progress(lev+2,off+len,"Going to read picture X size");
55 (*result)->xsize = psiconv_read_u32(buf,lev+2,off+len); 91 (*result)->xsize = psiconv_read_u32(buf,lev+2,off+len);
69 if (temp != 0x00) { 105 if (temp != 0x00) {
70 psiconv_warn(lev+2,off+len, 106 psiconv_warn(lev+2,off+len,
71 "Paint data section prologue has unknown values"); 107 "Paint data section prologue has unknown values");
72 psiconv_debug(lev+2,off+len, 108 psiconv_debug(lev+2,off+len,
73 "offset %02x: read %08x, expected %08x",i,temp,0x00); 109 "offset %02x: read %08x, expected %08x",i,temp,0x00);
110 res = -1;
74 } 111 }
75 len += 4; 112 len += 4;
76 } 113 }
77 114
78 (*result)->red = malloc(sizeof(float) * picsize); 115 (*result)->red = malloc(sizeof(float) * picsize);
97 psiconv_warn(lev+3,off+len+datanr,"Corrupted picture data"); 134 psiconv_warn(lev+3,off+len+datanr,"Corrupted picture data");
98 psiconv_debug(lev+3,off+len+datanr, 135 psiconv_debug(lev+3,off+len+datanr,
99 "Picsize: %08x, Datasize: %08x, Pixelnr: %08x," 136 "Picsize: %08x, Datasize: %08x, Pixelnr: %08x,"
100 "Datanr: %08x, marker: %02x",picsize,datasize,pixelnr, 137 "Datanr: %08x, marker: %02x",picsize,datasize,pixelnr,
101 datanr,marker); 138 datanr,marker);
139 res = -1;
140 read_err = 1;
102 } else { 141 } else {
103 for (i = 0; i < 0x100-marker; i++) { 142 for (i = 0; i < 0x100-marker; i++) {
104 temp = psiconv_read_u8(buf,lev+3,off+len+datanr+i); 143 temp = psiconv_read_u8(buf,lev+3,off+len+datanr+i);
105 (*result)->red[pixelnr + i*4] = 144 (*result)->red[pixelnr + i*4] =
106 (*result)->green[pixelnr + i*4] = 145 (*result)->green[pixelnr + i*4] =
128 psiconv_warn(lev+3,off+len+datanr,"Corrupted picture data"); 167 psiconv_warn(lev+3,off+len+datanr,"Corrupted picture data");
129 psiconv_debug(lev+3,off+len+datanr, 168 psiconv_debug(lev+3,off+len+datanr,
130 "Picsize: %08x, Datasize: %08x, Pixelnr: %08x," 169 "Picsize: %08x, Datasize: %08x, Pixelnr: %08x,"
131 "Datanr: %08x, marker: %02x",picsize,datasize,pixelnr, 170 "Datanr: %08x, marker: %02x",picsize,datasize,pixelnr,
132 datanr,marker); 171 datanr,marker);
172 res = -1;
173 read_err = 1;
133 } else { 174 } else {
134 temp = psiconv_read_u8(buf,lev+3,off+len+datanr); 175 temp = psiconv_read_u8(buf,lev+3,off+len+datanr);
135 for (i = 0; i < marker; i++) { 176 for (i = 0; i < marker; i++) {
136 (*result)->red[pixelnr + i*4] = 177 (*result)->red[pixelnr + i*4] =
137 (*result)->green[pixelnr + i*4] = 178 (*result)->green[pixelnr + i*4] =
153 } 194 }
154 pixelnr += marker * 4; 195 pixelnr += marker * 4;
155 datanr += 1; 196 datanr += 1;
156 } 197 }
157 } 198 }
199 if (!read_err && ((datanr != datasize) || (pixelnr != picsize))) {
200 psiconv_warn(lev+2,off+len,"Corrupted picture data!");
201 psiconv_debug(lev+3,off+len+datanr,
202 "Picsize: %08x, Datasize: %08x, Pixelnr: %08x,"
203 "Datanr: %08x",picsize,datasize,pixelnr,datanr);
204 res = -1;
205 }
206
158 len += datanr; 207 len += datanr;
159 208
160 if (length) 209 if (length)
161 *length = len; 210 *length = len;
162 211

Legend:
Removed from v.11  
changed lines
  Added in v.12

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26