1 /* wvWare
2 * Copyright (C) Caolan McNamara, Dom Lachowicz, and others
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17 * 02111-1307, USA.
18 */
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include "wv.h"
27 #include "wvinternal.h"
28
29 void
wvGetBRC_internal(BRC * abrc,wvStream * infd,U8 * pointer)30 wvGetBRC_internal (BRC * abrc, wvStream * infd, U8 * pointer)
31 {
32 U8 temp8;
33
34 #ifdef PURIFY
35 wvInitBRC (abrc);
36 #endif
37
38 abrc->dptLineWidth = dread_8ubit (infd, &pointer);
39 abrc->brcType = dread_8ubit (infd, &pointer);
40 abrc->ico = dread_8ubit (infd, &pointer);
41 temp8 = dread_8ubit (infd, &pointer);
42 abrc->dptSpace = temp8 & 0x1f;
43 abrc->fShadow = (temp8 & 0x20) >> 5;
44 abrc->fFrame = (temp8 & 0x40) >> 6;
45 abrc->reserved = (temp8 & 0x80) >> 7;
46 }
47
48 void
wvGetBRC(wvVersion ver,BRC * abrc,wvStream * infd)49 wvGetBRC (wvVersion ver, BRC * abrc, wvStream * infd)
50 {
51 if (ver == WORD8)
52 wvGetBRC_internal (abrc, infd, NULL);
53 else
54 wvGetBRC_internal6 (abrc, infd, NULL);
55 }
56
57 void
wvGetBRC_internal6(BRC * abrc,wvStream * infd,U8 * pointer)58 wvGetBRC_internal6 (BRC * abrc, wvStream * infd, U8 * pointer)
59 {
60 U16 temp16;
61
62 #ifdef PURIFY
63 wvInitBRC (abrc);
64 #endif
65
66 temp16 = dread_16ubit (infd, &pointer);
67
68 abrc->dptLineWidth = (temp16 & 0x0007);
69 abrc->brcType = (temp16 & 0x0018) >> 3;
70 abrc->fShadow = (temp16 & 0x0020) >> 5;
71 abrc->ico = (temp16 & 0x07C0) >> 6;
72 abrc->dptSpace = (temp16 & 0xF800) >> 11;
73 }
74
75
76 int
wvGetBRCFromBucket(wvVersion ver,BRC * abrc,U8 * pointer)77 wvGetBRCFromBucket (wvVersion ver, BRC * abrc, U8 * pointer)
78 {
79 if (ver == WORD8)
80 wvGetBRC_internal (abrc, NULL, pointer);
81 else
82 {
83 wvGetBRC_internal6 (abrc, NULL, pointer);
84 return (cb6BRC);
85 }
86 return (cbBRC);
87 }
88
89 void
wvInitBRC10(BRC10 * item)90 wvInitBRC10 (BRC10 * item)
91 {
92 item->dxpLine2Width = 0;
93 item->dxpSpaceBetween = 0;
94 item->dxpLine1Width = 0;
95 item->dxpSpace = 0;
96 item->fShadow = 0;
97 item->fSpare = 0;
98 }
99
100 void
wvGetBRC10_internal(BRC10 * item,wvStream * infd,U8 * pointer)101 wvGetBRC10_internal (BRC10 * item, wvStream * infd, U8 * pointer)
102 {
103 U16 temp16;
104 temp16 = dread_16ubit (infd, &pointer);
105 #ifdef PURIFY
106 wvInitBRC10 (item);
107 #endif
108 item->dxpLine2Width = (temp16 & 0x0007);
109 item->dxpSpaceBetween = (temp16 & 0x0038) >> 3;
110 item->dxpLine1Width = (temp16 & 0x01C0) >> 6;
111 item->dxpSpace = (temp16 & 0x3E00) >> 9;
112 item->fShadow = (temp16 & 0x4000) >> 14;
113 item->fSpare = (temp16 & 0x8000) >> 15;
114 }
115
116 int
wvGetBRC10FromBucket(BRC10 * abrc10,U8 * pointer)117 wvGetBRC10FromBucket (BRC10 * abrc10, U8 * pointer)
118 {
119 wvGetBRC10_internal (abrc10, NULL, pointer);
120 return (cbBRC10);
121 }
122
123 void
wvInitBRC(BRC * abrc)124 wvInitBRC (BRC * abrc)
125 {
126 abrc->dptLineWidth = 0;
127 abrc->brcType = 0;
128 abrc->ico = 0;
129 abrc->dptSpace = 0;
130 abrc->fShadow = 0;
131 abrc->fFrame = 0;
132 abrc->reserved = 0;
133 }
134
135 int
wvEqualBRC(BRC * a,BRC * b)136 wvEqualBRC (BRC * a, BRC * b)
137 {
138 if (a->dptLineWidth == b->dptLineWidth)
139 if (a->brcType == b->brcType)
140 if (a->ico == b->ico)
141 if (a->dptSpace == b->dptSpace)
142 if (a->fShadow == b->fShadow)
143 if (a->fFrame == b->fFrame)
144 if (a->reserved == b->reserved)
145 return (1);
146 return (0);
147 }
148
149 void
wvCopyBRC(BRC * dest,BRC * src)150 wvCopyBRC (BRC * dest, BRC * src)
151 {
152 dest->dptLineWidth = src->dptLineWidth;
153 dest->brcType = src->brcType;
154 dest->ico = src->ico;
155 dest->dptSpace = src->dptSpace;
156 dest->fShadow = src->fShadow;
157 dest->fFrame = src->fFrame;
158 dest->reserved = src->reserved;
159 }
160
161 /*
162 I'm not certain as to how this should work, but it will probably
163 never occur, its in here for the sake of completeness
164 */
165 void
wvConvertBRC10ToBRC(BRC * item,BRC10 * in)166 wvConvertBRC10ToBRC (BRC * item, BRC10 * in)
167 {
168 wvInitBRC (item);
169 item->dptSpace = in->dxpSpace;
170 item->fShadow = in->fShadow;
171 /*
172 The border lines and their brc10 settings follow:
173
174 line type dxpLine1Width dxpSpaceBetween dxpLine2Width
175
176 no border 0 0 0
177
178 single line 1 0 0
179 border
180
181 two single line 1 1 1
182 border
183
184 fat solid border 4 0 0
185
186 thick solid 2 0 0
187 border
188
189 dotted border 6 (special value meaning 0 0
190 dotted line)
191
192 hairline border 7(special value meaning 0 0
193 hairline)
194 */
195 if ((in->dxpLine1Width == 0) && (in->dxpSpaceBetween == 0)
196 && (in->dxpLine2Width == 0))
197 item->brcType = 0;
198 else if ((in->dxpLine1Width == 1) && (in->dxpSpaceBetween == 0)
199 && (in->dxpLine2Width == 0))
200 item->brcType = 1;
201 else if ((in->dxpLine1Width == 1) && (in->dxpSpaceBetween == 1)
202 && (in->dxpLine2Width == 1))
203 item->brcType = 3;
204 else if ((in->dxpLine1Width == 4) && (in->dxpSpaceBetween == 0)
205 && (in->dxpLine2Width == 0))
206 item->brcType = 3;
207 else if ((in->dxpLine1Width == 2) && (in->dxpSpaceBetween == 0)
208 && (in->dxpLine2Width == 0))
209 item->brcType = 2;
210 else if ((in->dxpLine1Width == 6) && (in->dxpSpaceBetween == 0)
211 && (in->dxpLine2Width == 0))
212 item->brcType = 6;
213 else if ((in->dxpLine1Width == 7) && (in->dxpSpaceBetween == 0)
214 && (in->dxpLine2Width == 0))
215 item->brcType = 5;
216 else
217 item->brcType = 0;
218 }
219