/[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 10 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;
32 psiconv_u32 size; 66 int read_err = 0;
33 int leng; 67 psiconv_u32 size,offset,picsize,temp,datasize,pixelnr,datanr;
68 psiconv_u8 marker;
69 int i;
34 70
35 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");
36 (*result) = malloc(sizeof(**result)); 72 (*result) = malloc(sizeof(**result));
37 73
38 psiconv_progress(lev+2,off+len,"Going to read section size"); 74 psiconv_progress(lev+2,off+len,"Going to read section size");
45 if (size != 0x28) { 81 if (size != 0x28) {
46 psiconv_warn(lev+2,off+len, 82 psiconv_warn(lev+2,off+len,
47 "Paint data section data offset has unexpected value"); 83 "Paint data section data offset has unexpected value");
48 psiconv_debug(lev+2,off+len, 84 psiconv_debug(lev+2,off+len,
49 "Data offset: read %08x, expected %08x",offset,0x28); 85 "Data offset: read %08x, expected %08x",offset,0x28);
86 res = -1;
50 } 87 }
51 len += 4; 88 len += 4;
52 89
53 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");
54 (*result)->xsize = psiconv_read_u32(buf,lev+2,off+len); 91 (*result)->xsize = psiconv_read_u32(buf,lev+2,off+len);
60 psiconv_debug(lev+2,off+len,"Picture Y size: %08x:",(*result)->ysize); 97 psiconv_debug(lev+2,off+len,"Picture Y size: %08x:",(*result)->ysize);
61 len += 4; 98 len += 4;
62 99
63 picsize = (*result)->ysize * (*result)->xsize; 100 picsize = (*result)->ysize * (*result)->xsize;
64 101
65 psiconv_progress("Going to read 6 unused longs"); 102 psiconv_progress(lev+2,off+len,"Going to read 6 unused longs");
66 for (i = 0 ; i < 6; i++) { 103 for (i = 0 ; i < 6; i++) {
67 temp = psiconv_read_u32(buf,lev+2,off+len); 104 temp = psiconv_read_u32(buf,lev+2,off+len);
68 if (temp != 0x00) { 105 if (temp != 0x00) {
69 psiconv_warn(lev+2,off+len, 106 psiconv_warn(lev+2,off+len,
70 "Paint data section prologue has unknown values"); 107 "Paint data section prologue has unknown values");
71 psiconv_debug(lev+2,off+len, 108 psiconv_debug(lev+2,off+len,
72 "offset %02x: read %08x, expected %08x",i,temp,0x00); 109 "offset %02x: read %08x, expected %08x",i,temp,0x00);
110 res = -1;
73 } 111 }
74 len += 4; 112 len += 4;
75 } 113 }
76 114
77 (*result)->red = malloc(sizeof(float) * picsize); 115 (*result)->red = malloc(sizeof(float) * picsize);
78 (*result)->green = malloc(sizeof(float) * picsize); 116 (*result)->green = malloc(sizeof(float) * picsize);
79 (*result)->blue = malloc(sizeof(float) * picsize); 117 (*result)->blue = malloc(sizeof(float) * picsize);
80 len = offset; 118 len = offset;
81 datasize = size - len; 119 datasize = size - len;
82 120
83 psiconv_progress(buf,lev+2,off+len,"Going to read the pixel data"); 121 psiconv_progress(lev+2,off+len,"Going to read the pixel data");
84 pixelnr = 0; 122 pixelnr = 0;
85 datanr = 0; 123 datanr = 0;
86 while ((datanr < datasize) && (pixelnr < picsize)) { 124 while ((datanr < datasize) && (pixelnr < picsize)) {
87 marker = psiconv_read_u8(buf,lev+3,off+len+datanr); 125 marker = psiconv_read_u8(buf,lev+3,off+len+datanr);
88 psiconv_debug(lev+3,off+len+datanr, 126 psiconv_debug(lev+3,off+len+datanr,
96 psiconv_warn(lev+3,off+len+datanr,"Corrupted picture data"); 134 psiconv_warn(lev+3,off+len+datanr,"Corrupted picture data");
97 psiconv_debug(lev+3,off+len+datanr, 135 psiconv_debug(lev+3,off+len+datanr,
98 "Picsize: %08x, Datasize: %08x, Pixelnr: %08x," 136 "Picsize: %08x, Datasize: %08x, Pixelnr: %08x,"
99 "Datanr: %08x, marker: %02x",picsize,datasize,pixelnr, 137 "Datanr: %08x, marker: %02x",picsize,datasize,pixelnr,
100 datanr,marker); 138 datanr,marker);
139 res = -1;
140 read_err = 1;
101 } else { 141 } else {
102 for (i = 0; i < 0x100-marker; i++) { 142 for (i = 0; i < 0x100-marker; i++) {
103 temp = psiconv_read_u8(buf,lev+3,off+len+datanr+i); 143 temp = psiconv_read_u8(buf,lev+3,off+len+datanr+i);
104 (*result)->red[pixelnr + i*4] = 144 (*result)->red[pixelnr + i*4] =
105 (*result)->green[pixelnr + i*4] = 145 (*result)->green[pixelnr + i*4] =
127 psiconv_warn(lev+3,off+len+datanr,"Corrupted picture data"); 167 psiconv_warn(lev+3,off+len+datanr,"Corrupted picture data");
128 psiconv_debug(lev+3,off+len+datanr, 168 psiconv_debug(lev+3,off+len+datanr,
129 "Picsize: %08x, Datasize: %08x, Pixelnr: %08x," 169 "Picsize: %08x, Datasize: %08x, Pixelnr: %08x,"
130 "Datanr: %08x, marker: %02x",picsize,datasize,pixelnr, 170 "Datanr: %08x, marker: %02x",picsize,datasize,pixelnr,
131 datanr,marker); 171 datanr,marker);
172 res = -1;
173 read_err = 1;
132 } else { 174 } else {
133 temp = psiconv_read_u8(buf,lev+3,off+len+datanr); 175 temp = psiconv_read_u8(buf,lev+3,off+len+datanr);
134 for (i = 0; i < marker; i++) { 176 for (i = 0; i < marker; i++) {
135 (*result)->red[pixelnr + i*4] = 177 (*result)->red[pixelnr + i*4] =
136 (*result)->green[pixelnr + i*4] = 178 (*result)->green[pixelnr + i*4] =
152 } 194 }
153 pixelnr += marker * 4; 195 pixelnr += marker * 4;
154 datanr += 1; 196 datanr += 1;
155 } 197 }
156 } 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
157 len += datanr; 207 len += datanr;
158 208
159 if (length) 209 if (length)
160 *length = len; 210 *length = len;
161 211

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

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