Lines Matching refs:lzw_info

169 static LZWInfo *RelinquishLZWInfo(LZWInfo *lzw_info)  in RelinquishLZWInfo()  argument
171 if (lzw_info->table[0] != (size_t *) NULL) in RelinquishLZWInfo()
172 lzw_info->table[0]=(size_t *) RelinquishMagickMemory( in RelinquishLZWInfo()
173 lzw_info->table[0]); in RelinquishLZWInfo()
174 if (lzw_info->table[1] != (size_t *) NULL) in RelinquishLZWInfo()
175 lzw_info->table[1]=(size_t *) RelinquishMagickMemory( in RelinquishLZWInfo()
176 lzw_info->table[1]); in RelinquishLZWInfo()
177 if (lzw_info->stack != (LZWStack *) NULL) in RelinquishLZWInfo()
179 if (lzw_info->stack->codes != (size_t *) NULL) in RelinquishLZWInfo()
180 lzw_info->stack->codes=(size_t *) RelinquishMagickMemory( in RelinquishLZWInfo()
181 lzw_info->stack->codes); in RelinquishLZWInfo()
182 lzw_info->stack=(LZWStack *) RelinquishMagickMemory(lzw_info->stack); in RelinquishLZWInfo()
184 lzw_info=(LZWInfo *) RelinquishMagickMemory(lzw_info); in RelinquishLZWInfo()
188 static inline void ResetLZWInfo(LZWInfo *lzw_info) in ResetLZWInfo() argument
193 lzw_info->bits=lzw_info->data_size+1; in ResetLZWInfo()
195 lzw_info->maximum_code=one << lzw_info->bits; in ResetLZWInfo()
196 lzw_info->slot=lzw_info->maximum_data_value+3; in ResetLZWInfo()
197 lzw_info->genesis=MagickTrue; in ResetLZWInfo()
203 *lzw_info; in AcquireLZWInfo() local
211 lzw_info=(LZWInfo *) AcquireMagickMemory(sizeof(*lzw_info)); in AcquireLZWInfo()
212 if (lzw_info == (LZWInfo *) NULL) in AcquireLZWInfo()
214 (void) memset(lzw_info,0,sizeof(*lzw_info)); in AcquireLZWInfo()
215 lzw_info->image=image; in AcquireLZWInfo()
216 lzw_info->data_size=data_size; in AcquireLZWInfo()
218 lzw_info->maximum_data_value=(one << data_size)-1; in AcquireLZWInfo()
219 lzw_info->clear_code=lzw_info->maximum_data_value+1; in AcquireLZWInfo()
220 lzw_info->end_code=lzw_info->maximum_data_value+2; in AcquireLZWInfo()
221 lzw_info->table[0]=(size_t *) AcquireQuantumMemory(MaximumLZWCode, in AcquireLZWInfo()
222 sizeof(**lzw_info->table)); in AcquireLZWInfo()
223 lzw_info->table[1]=(size_t *) AcquireQuantumMemory(MaximumLZWCode, in AcquireLZWInfo()
224 sizeof(**lzw_info->table)); in AcquireLZWInfo()
225 if ((lzw_info->table[0] == (size_t *) NULL) || in AcquireLZWInfo()
226 (lzw_info->table[1] == (size_t *) NULL)) in AcquireLZWInfo()
228 lzw_info=RelinquishLZWInfo(lzw_info); in AcquireLZWInfo()
231 (void) memset(lzw_info->table[0],0,MaximumLZWCode* in AcquireLZWInfo()
232 sizeof(**lzw_info->table)); in AcquireLZWInfo()
233 (void) memset(lzw_info->table[1],0,MaximumLZWCode* in AcquireLZWInfo()
234 sizeof(**lzw_info->table)); in AcquireLZWInfo()
235 for (i=0; i <= (ssize_t) lzw_info->maximum_data_value; i++) in AcquireLZWInfo()
237 lzw_info->table[0][i]=0; in AcquireLZWInfo()
238 lzw_info->table[1][i]=(size_t) i; in AcquireLZWInfo()
240 ResetLZWInfo(lzw_info); in AcquireLZWInfo()
241 lzw_info->code_info.buffer[0]='\0'; in AcquireLZWInfo()
242 lzw_info->code_info.buffer[1]='\0'; in AcquireLZWInfo()
243 lzw_info->code_info.count=2; in AcquireLZWInfo()
244 lzw_info->code_info.bit=8*lzw_info->code_info.count; in AcquireLZWInfo()
245 lzw_info->code_info.eof=MagickFalse; in AcquireLZWInfo()
246 lzw_info->genesis=MagickTrue; in AcquireLZWInfo()
247 lzw_info->stack=(LZWStack *) AcquireMagickMemory(sizeof(*lzw_info->stack)); in AcquireLZWInfo()
248 if (lzw_info->stack == (LZWStack *) NULL) in AcquireLZWInfo()
250 lzw_info=RelinquishLZWInfo(lzw_info); in AcquireLZWInfo()
253 lzw_info->stack->codes=(size_t *) AcquireQuantumMemory(2UL* in AcquireLZWInfo()
254 MaximumLZWCode,sizeof(*lzw_info->stack->codes)); in AcquireLZWInfo()
255 if (lzw_info->stack->codes == (size_t *) NULL) in AcquireLZWInfo()
257 lzw_info=RelinquishLZWInfo(lzw_info); in AcquireLZWInfo()
260 lzw_info->stack->index=lzw_info->stack->codes; in AcquireLZWInfo()
261 lzw_info->stack->top=lzw_info->stack->codes+2*MaximumLZWCode; in AcquireLZWInfo()
262 return(lzw_info); in AcquireLZWInfo()
265 static inline int GetNextLZWCode(LZWInfo *lzw_info,const size_t bits) in GetNextLZWCode() argument
276 while (((lzw_info->code_info.bit+bits) > (8*lzw_info->code_info.count)) && in GetNextLZWCode()
277 (lzw_info->code_info.eof == MagickFalse)) in GetNextLZWCode()
282 lzw_info->code_info.buffer[0]=lzw_info->code_info.buffer[ in GetNextLZWCode()
283 lzw_info->code_info.count-2]; in GetNextLZWCode()
284 lzw_info->code_info.buffer[1]=lzw_info->code_info.buffer[ in GetNextLZWCode()
285 lzw_info->code_info.count-1]; in GetNextLZWCode()
286 lzw_info->code_info.bit-=8*(lzw_info->code_info.count-2); in GetNextLZWCode()
287 lzw_info->code_info.count=2; in GetNextLZWCode()
288 count=ReadBlobBlock(lzw_info->image,&lzw_info->code_info.buffer[ in GetNextLZWCode()
289 lzw_info->code_info.count]); in GetNextLZWCode()
291 lzw_info->code_info.count+=count; in GetNextLZWCode()
293 lzw_info->code_info.eof=MagickTrue; in GetNextLZWCode()
295 if ((lzw_info->code_info.bit+bits) > (8*lzw_info->code_info.count)) in GetNextLZWCode()
301 code|=((lzw_info->code_info.buffer[lzw_info->code_info.bit/8] & in GetNextLZWCode()
302 (one << (lzw_info->code_info.bit % 8))) != 0) << i; in GetNextLZWCode()
303 lzw_info->code_info.bit++; in GetNextLZWCode()
324 static int ReadBlobLZWByte(LZWInfo *lzw_info) in ReadBlobLZWByte() argument
336 if (lzw_info->stack->index != lzw_info->stack->codes) in ReadBlobLZWByte()
337 return(PopLZWStack(lzw_info->stack)); in ReadBlobLZWByte()
338 if (lzw_info->genesis != MagickFalse) in ReadBlobLZWByte()
340 lzw_info->genesis=MagickFalse; in ReadBlobLZWByte()
343 lzw_info->first_code=(size_t) GetNextLZWCode(lzw_info,lzw_info->bits); in ReadBlobLZWByte()
344 lzw_info->last_code=lzw_info->first_code; in ReadBlobLZWByte()
345 } while (lzw_info->first_code == lzw_info->clear_code); in ReadBlobLZWByte()
346 return((int) lzw_info->first_code); in ReadBlobLZWByte()
348 code=GetNextLZWCode(lzw_info,lzw_info->bits); in ReadBlobLZWByte()
351 if ((size_t) code == lzw_info->clear_code) in ReadBlobLZWByte()
353 ResetLZWInfo(lzw_info); in ReadBlobLZWByte()
354 return(ReadBlobLZWByte(lzw_info)); in ReadBlobLZWByte()
356 if ((size_t) code == lzw_info->end_code) in ReadBlobLZWByte()
358 if ((size_t) code < lzw_info->slot) in ReadBlobLZWByte()
362 PushLZWStack(lzw_info->stack,lzw_info->first_code); in ReadBlobLZWByte()
363 value=lzw_info->last_code; in ReadBlobLZWByte()
366 while (value > lzw_info->maximum_data_value) in ReadBlobLZWByte()
373 PushLZWStack(lzw_info->stack,lzw_info->table[1][value]); in ReadBlobLZWByte()
374 value=lzw_info->table[0][value]; in ReadBlobLZWByte()
376 lzw_info->first_code=lzw_info->table[1][value]; in ReadBlobLZWByte()
377 PushLZWStack(lzw_info->stack,lzw_info->first_code); in ReadBlobLZWByte()
379 if (lzw_info->slot < MaximumLZWCode) in ReadBlobLZWByte()
381 lzw_info->table[0][lzw_info->slot]=lzw_info->last_code; in ReadBlobLZWByte()
382 lzw_info->table[1][lzw_info->slot]=lzw_info->first_code; in ReadBlobLZWByte()
383 lzw_info->slot++; in ReadBlobLZWByte()
384 if ((lzw_info->slot >= lzw_info->maximum_code) && in ReadBlobLZWByte()
385 (lzw_info->bits < MaximumLZWBits)) in ReadBlobLZWByte()
387 lzw_info->bits++; in ReadBlobLZWByte()
388 lzw_info->maximum_code=one << lzw_info->bits; in ReadBlobLZWByte()
391 lzw_info->last_code=(size_t) code; in ReadBlobLZWByte()
392 return(PopLZWStack(lzw_info->stack)); in ReadBlobLZWByte()
402 *lzw_info; in DecodeImage() local
425 lzw_info=AcquireLZWInfo(image,data_size); in DecodeImage()
426 if (lzw_info == (LZWInfo *) NULL) in DecodeImage()
444 c=ReadBlobLZWByte(lzw_info); in DecodeImage()
503 lzw_info=RelinquishLZWInfo(lzw_info); in DecodeImage()