File: picf.c

package info (click to toggle)
abiword 0.7.7-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 20,604 kB
  • ctags: 18,358
  • sloc: cpp: 88,791; ansic: 66,296; sh: 7,777; makefile: 3,397; xml: 687; perl: 361; awk: 273; sed: 36; csh: 28
file content (333 lines) | stat: -rw-r--r-- 7,769 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "wv.h"

int wvGetPICF(version ver,PICF *apicf,FILE *fd)
	{
	char buffer[1024];
	int ret=0;
	FILE *f;
	U8 temp;
	U32 i;
	static int s;
	long pos=ftell(fd);

	apicf->lcb = read_32ubit(fd);
	apicf->cbHeader = read_16ubit(fd);
	wvTrace(("size of pic is %x (%d)\n",apicf->cbHeader,apicf->cbHeader));
	apicf->mfp_mm = (S16)read_16ubit(fd);
	wvTrace(("mm type is %d\n",apicf->mfp_mm));
	apicf->mfp_xExt = (S16)read_16ubit(fd);
	apicf->mfp_yExt = (S16)read_16ubit(fd);
	apicf->mfp_hMF = (S16)read_16ubit(fd);
	if (apicf->mfp_mm == 99)
		wvGetBITMAP(&(apicf->obj.bitmap),fd);
	else 
		wvGetrc(&(apicf->obj.arc),fd);
	apicf->dxaGoal = (S16)read_16ubit(fd);
	apicf->dyaGoal = (S16)read_16ubit(fd);
	apicf->mx = (S16)read_16ubit(fd);
	apicf->my = (S16)read_16ubit(fd);
	apicf->dxaCropLeft = (S16)read_16ubit(fd);
	apicf->dyaCropTop = (S16)read_16ubit(fd);
	apicf->dxaCropRight = (S16)read_16ubit(fd);
	apicf->dyaCropBottom = (S16)read_16ubit(fd);
	temp = getc(fd);

	apicf->brcl = temp & 0x0F;
	apicf->fFrameEmpty = (temp & 0x10)>>4;
	apicf->fBitmap = (temp&0x20)>>5;
	wvTrace(("bitmap is %d\n",apicf->fBitmap));
	apicf->fDrawHatch = (temp&0x40)>>6;
	apicf->fError = (temp&0x80)>>7;

	apicf->bpp = getc(fd);
	wvGetBRC(ver,&(apicf->brcTop),fd);
	wvGetBRC(ver,&(apicf->brcLeft),fd);
	wvGetBRC(ver,&(apicf->brcBottom),fd);
	wvGetBRC(ver,&(apicf->brcRight),fd);
	apicf->dxaOrigin = (S16)read_16ubit(fd);
	apicf->dyaOrigin = (S16)read_16ubit(fd);
	if (ver == WORD8)
		apicf->cProps = (S16)read_16ubit(fd);
	else
		apicf->cProps = 0;
	pos = ftell(fd)-pos;
	for(i=pos;i<apicf->cbHeader;i++)
		getc(fd);
	wvTrace(("pos is finally %x\n",ftell(fd)));
	wvTrace(("len of data is %d\n",apicf->lcb-apicf->cbHeader));
	wvTrace(("ends at %x\n",ftell(fd)+apicf->lcb-apicf->cbHeader));
	f = tmpfile();
	if (f == NULL)
		{
		wvError(("Couldnt create tmpfile: %s\n",strerror(errno)));
		apicf->rgb = NULL;
		return(ret);
		}
	/*
	sprintf(buffer,"/tmp/newtest-%d",s++);
	f = fopen(buffer,"w+b");
	*/
	i=0;

	if (apicf->mfp_mm < 90)
		{
		U32 len;
		wvTrace(("test\n"));
		ret=1;
		len = apicf->lcb-apicf->cbHeader;

		i = wvEatOldGraphicHeader(fd,len);
		wvTrace(("len is %d, header len guess is %d\n",len,i));
		if (i+1 >= len)
			{
			wvTrace(("all read ok methinks\n"));
			apicf->rgb = NULL;
			return(ret);
			}
		len -= i;
#if 0
		/*
		a msofbtSpContainer amsofbh
		a msofbtSp amsofbh 
		a fopt
		a msofbtBSE amsofbh
		a BSE amsofbh
		a FBSE for a dib, and then
		all this dib information
		*/
#else
		len += 14;
		wvTrace(("len is now %d\n",len));
		fputc(0x42,f);
		fputc(0x4D,f);

		fputc(len&0x000000FF,f);
		fputc((len&0x0000FF00)>>8,f);
		fputc((len&0x00FF0000)>>16,f);
		fputc((len&0xFF000000)>>24,f);

		fputc(0x00,f);
		fputc(0x00,f);
		fputc(0x00,f);
		fputc(0x00,f);

		fputc(0x36,f);
		fputc(0x00,f);
		fputc(0x00,f);
		fputc(0x00,f);
#endif
		}

	for(;i<apicf->lcb-apicf->cbHeader;i++)
		fputc(getc(fd),f);
	rewind(f);
	apicf->rgb = (void *)f;
	return(ret);
	}

U32 wvEatOldGraphicHeader(FILE *fd,U32 len)
	{
	U32 X,entry,count=0,test;
	U16 pad;
	test = read_32ubit(fd); 	/*0x00090001*/
	if (test != 0x00090001L)
		wvError(("Old Graphic\n"));
	count+=4;
	test = read_16ubit(fd);	/*0x0300*/
	if (test != 0x0300)
		wvError(("Old Graphic\n"));
	count+=2;

	read_32ubit(fd); 	/*changes*/
	count+=4;
	test = read_16ubit(fd);	/*0x0000*/
	if (test != 0x00000000L)
		wvError(("Old Graphic\n"));
	count+=2;
	X = read_32ubit(fd); 	/*changes, lets call this X*/
	wvError(("X is %x\n",X));
	count+=4;
	read_16ubit(fd);	/*0x0000*/
	if (test != 0x00000000L)
		wvError(("Old Graphic\n"));
	count+=2;

	/*
	while ( entry != X)
	*/
	do
		{
		entry = read_32ubit(fd);
		count+=4;
		wvTrace(("Entry is %x, %x, count is %d\n",entry,ftell(fd),count));
		switch(entry)
			{
			case 3:
				read_16ubit(fd);
				count+=2;
				wvTrace(("suspect that we are finished, count %d, len %d\n",count,len));
				break;
			default:
				{
				U32 len = entry-2,i;
				wvTrace(("len is %d, predict end of %x\n",len,ftell(fd)+(entry-2)*2));
				for(i=0;i<len;i++)
					{
					test = read_16ubit(fd);
					if ((i==0) && ((test ==  0x0f43) || (test == 0x0b41)))
						{
						wvTrace(("Found a Bitmap, Will strip header and return with bitmap data\n"));
						count+=2;
						pad = test;
						test = read_32ubit(fd);	/*0x00cc0020*/
						if (test != 0x00cc0020)
							wvError(("Old Graphic\n"));
						count+=4;

						if (pad == 0x0f43)
							{
							test = read_16ubit(fd); /*0x0000*/
							if (test != 0x0000)
								wvError(("Old Graphic\n"));
							count+=2;
							}
						
						read_16ubit(fd);	/*width*/
						count+=2;
						read_16ubit(fd);	/*height*/
						count+=2;
						test = read_32ubit(fd);	/*0x00000000L*/
						if (test != 0x00000000L)
							wvError(("Old Graphic\n"));
						count+=4;
						read_16ubit(fd);	/*width*/
						count+=2;
						read_16ubit(fd);	/*height*/
						count+=2;
						test = read_32ubit(fd);	/*0x00000000L*/
						if (test != 0x00000000L)
							wvError(("Old Graphic\n"));
						count+=4;
						return(count);
						}
					count+=2;
					}
				}
				break;
			}
		}
	while ( count+1 < len);
	wvTrace(("Entry is %x %x, %d\n",entry,ftell(fd),count));
	return(count);
	}

extern int external_knowledge_0x01;

void oldwvGetPICF(PICF *apicf,FILE *fd,U32 offset)
	{
	U32 count=0;
	U8 temp;
	FILE *out;
	fbse_list *pic_list;
	fbse_list *tpic_list;
	fsp_list *afsp_list;
	fsp_list *tfsp_list;
	fopte_list *tfopte_list;

	fseek(fd,offset,SEEK_SET);

	apicf->lcb = read_32ubit(fd);
	apicf->cbHeader = read_16ubit(fd);
	apicf->mfp_mm = (S16)read_16ubit(fd);
	apicf->mfp_xExt = (S16)read_16ubit(fd);
	apicf->mfp_yExt = (S16)read_16ubit(fd);
	apicf->mfp_hMF = (S16)read_16ubit(fd);
	if (apicf->mfp_mm == 99)
		wvGetBITMAP(&(apicf->obj.bitmap),fd);
	else 
		wvGetrc(&(apicf->obj.arc),fd);
	apicf->dxaGoal = (S16)read_16ubit(fd);
	apicf->dyaGoal = (S16)read_16ubit(fd);
	apicf->mx = (S16)read_16ubit(fd);
	apicf->my = (S16)read_16ubit(fd);
	apicf->dxaCropLeft = (S16)read_16ubit(fd);
	apicf->dyaCropTop = (S16)read_16ubit(fd);
	apicf->dxaCropRight = (S16)read_16ubit(fd);
	apicf->dyaCropBottom = (S16)read_16ubit(fd);
	temp = getc(fd);

#ifdef PURIFY
	apicf->brcl = 0;
	apicf->fFrameEmpty = 0;
	apicf->fBitmap = 0;
	apicf->fDrawHatch = 0;
	apicf->fError = 0;
#endif

	apicf->brcl = temp & 0x0F;
	apicf->fFrameEmpty = (temp & 0x10)>>4;
	apicf->fBitmap = (temp&0x20)>>5;
	apicf->fDrawHatch = (temp&0x40)>>6;
	apicf->fError = (temp&0x80)>>7;

	apicf->bpp = getc(fd);
	wvGetBRC(0,&(apicf->brcTop),fd);
	wvGetBRC(0,&(apicf->brcLeft),fd);
	wvGetBRC(0,&(apicf->brcBottom),fd);
	wvGetBRC(0,&(apicf->brcRight),fd);
	apicf->dxaOrigin = (S16)read_16ubit(fd);
	apicf->dyaOrigin = (S16)read_16ubit(fd);
	apicf->cProps = (S16)read_16ubit(fd);
	/*
	apicf->rgb = "/tmp/wvscratch2";
	*/
	count+=68;
	/*
	out = fopen(apicf->rgb,"w+b");
	*/
	out = tmpfile();
	for (;count<apicf->lcb;count++)
		fputc(getc(fd),out);
	rewind(out);

	external_knowledge_0x01 = 1;	/*no delay streams in use*/
	afsp_list = wvParseEscher(&pic_list,0,(apicf->lcb)-68,out,out);
	external_knowledge_0x01 = 0;	/*reenable delay streams (not necessary)*/

	fclose(out);

	apicf->rgb = NULL;

	if (pic_list == NULL)
		wvError(("rats\n"));
	else
		{
		apicf->rgb = (S8 *)malloc(strlen(pic_list->filename)+1);
		strcpy(apicf->rgb,pic_list->filename);
		}

	while (afsp_list != NULL)
		{
		while (afsp_list->afopte_list != NULL)
			{
			tfopte_list = afsp_list->afopte_list;
			afsp_list->afopte_list = afsp_list->afopte_list->next;
			free(tfopte_list);
			}
		tfsp_list = afsp_list;
		afsp_list = afsp_list->next;
		free(tfsp_list);
		}

	while (pic_list != NULL)
		{
		tpic_list = pic_list;
		pic_list = pic_list->next;
		free(tpic_list);
		}

	}