comparison tiff.c @ 4190:405f8395eedc libavcodec

Use table for determining type sizes
author kostya
date Mon, 13 Nov 2006 11:34:46 +0000
parents 57b22f48a6a6
children c9867abab7e6
comparison
equal deleted inserted replaced
4189:3c98b0938897 4190:405f8395eedc
60 TIFF_SHORT, 60 TIFF_SHORT,
61 TIFF_LONG, 61 TIFF_LONG,
62 TIFF_LONGLONG 62 TIFF_LONGLONG
63 }; 63 };
64 64
65 /** sizes of various TIFF field types */
66 static const int type_sizes[6] = {
67 0, 1, 100, 2, 4, 8
68 };
69
65 typedef struct TiffContext { 70 typedef struct TiffContext {
66 AVCodecContext *avctx; 71 AVCodecContext *avctx;
67 AVFrame picture; 72 AVFrame picture;
68 73
69 int width, height; 74 int width, height;
206 break; 211 break;
207 default: 212 default:
208 value = -1; 213 value = -1;
209 buf = start + off; 214 buf = start + off;
210 } 215 }
216 }else if(type_sizes[type] * count <= 4){
217 buf -= 4;
211 }else{ 218 }else{
212 buf = start + off; 219 buf = start + off;
213 } 220 }
214 221
215 if(buf && (buf < start || buf > end_buf)){ 222 if(buf && (buf < start || buf > end_buf)){
395 if(s->avctx->pix_fmt != PIX_FMT_PAL8){ 402 if(s->avctx->pix_fmt != PIX_FMT_PAL8){
396 av_log(s->avctx, AV_LOG_ERROR, "Palette met but this is not palettized format\n"); 403 av_log(s->avctx, AV_LOG_ERROR, "Palette met but this is not palettized format\n");
397 return -1; 404 return -1;
398 } 405 }
399 pal = s->picture.data[1]; 406 pal = s->picture.data[1];
400 off = (type == TIFF_SHORT) ? 2 : 1; 407 off = type_sizes[type];
401 rp = buf; 408 rp = buf;
402 gp = buf + count / 3 * off; 409 gp = buf + count / 3 * off;
403 bp = buf + count / 3 * off * 2; 410 bp = buf + count / 3 * off * 2;
404 off = (type == TIFF_SHORT) ? 8 : 0; 411 off = (type_sizes[type] - 1) << 3;
405 for(i = 0; i < count / 3; i++){ 412 for(i = 0; i < count / 3; i++){
406 j = (tget(&rp, type, s->le) >> off) << 16; 413 j = (tget(&rp, type, s->le) >> off) << 16;
407 j |= (tget(&gp, type, s->le) >> off) << 8; 414 j |= (tget(&gp, type, s->le) >> off) << 8;
408 j |= tget(&bp, type, s->le) >> off; 415 j |= tget(&bp, type, s->le) >> off;
409 pal[i] = j; 416 pal[i] = j;