comparison lcl.c @ 2979:bfabfdf9ce55 libavcodec

COSMETICS: tabs --> spaces, some prettyprinting
author diego
date Thu, 22 Dec 2005 01:10:11 +0000
parents ef2149182f1c
children 0b546eab515d
comparison
equal deleted inserted replaced
2978:403183bbb505 2979:bfabfdf9ce55
79 /* 79 /*
80 * Decoder context 80 * Decoder context
81 */ 81 */
82 typedef struct LclContext { 82 typedef struct LclContext {
83 83
84 AVCodecContext *avctx; 84 AVCodecContext *avctx;
85 AVFrame pic; 85 AVFrame pic;
86 PutBitContext pb; 86 PutBitContext pb;
87 87
88 // Image type 88 // Image type
89 int imgtype; 89 int imgtype;
90 // Compression type 90 // Compression type
196 * Decode a frame 196 * Decode a frame
197 * 197 *
198 */ 198 */
199 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) 199 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
200 { 200 {
201 LclContext * const c = (LclContext *)avctx->priv_data; 201 LclContext * const c = (LclContext *)avctx->priv_data;
202 unsigned char *encoded = (unsigned char *)buf; 202 unsigned char *encoded = (unsigned char *)buf;
203 unsigned int pixel_ptr; 203 unsigned int pixel_ptr;
204 int row, col; 204 int row, col;
205 unsigned char *outptr; 205 unsigned char *outptr;
206 unsigned int width = avctx->width; // Real image width 206 unsigned int width = avctx->width; // Real image width
207 unsigned int height = avctx->height; // Real image height 207 unsigned int height = avctx->height; // Real image height
212 #ifdef CONFIG_ZLIB 212 #ifdef CONFIG_ZLIB
213 int zret; // Zlib return code 213 int zret; // Zlib return code
214 #endif 214 #endif
215 unsigned int len = buf_size; 215 unsigned int len = buf_size;
216 216
217 if(c->pic.data[0]) 217 if(c->pic.data[0])
218 avctx->release_buffer(avctx, &c->pic); 218 avctx->release_buffer(avctx, &c->pic);
219 219
220 c->pic.reference = 0; 220 c->pic.reference = 0;
221 c->pic.buffer_hints = FF_BUFFER_HINTS_VALID; 221 c->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
222 if(avctx->get_buffer(avctx, &c->pic) < 0){ 222 if(avctx->get_buffer(avctx, &c->pic) < 0){
223 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); 223 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
224 return -1; 224 return -1;
225 } 225 }
226 226
227 outptr = c->pic.data[0]; // Output image pointer 227 outptr = c->pic.data[0]; // Output image pointer
228 228
229 /* Decompress frame */ 229 /* Decompress frame */
230 switch (avctx->codec_id) { 230 switch (avctx->codec_id) {
356 case IMGTYPE_RGB24: 356 case IMGTYPE_RGB24:
357 for (row = 0; row < height; row++) { 357 for (row = 0; row < height; row++) {
358 pixel_ptr = row * width * 3; 358 pixel_ptr = row * width * 3;
359 yq = encoded[pixel_ptr++]; 359 yq = encoded[pixel_ptr++];
360 uqvq = encoded[pixel_ptr++]; 360 uqvq = encoded[pixel_ptr++];
361 uqvq+=(encoded[pixel_ptr++] << 8); 361 uqvq+=(encoded[pixel_ptr++] << 8);
362 for (col = 1; col < width; col++) { 362 for (col = 1; col < width; col++) {
363 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; 363 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
364 uqvq -= (encoded[pixel_ptr+1] | (encoded[pixel_ptr+2]<<8)); 364 uqvq -= (encoded[pixel_ptr+1] | (encoded[pixel_ptr+2]<<8));
365 encoded[pixel_ptr+1] = (uqvq) & 0xff; 365 encoded[pixel_ptr+1] = (uqvq) & 0xff;
366 encoded[pixel_ptr+2] = ((uqvq)>>8) & 0xff; 366 encoded[pixel_ptr+2] = ((uqvq)>>8) & 0xff;
586 for(i = avctx->height - 1; i >= 0; i--) { 586 for(i = avctx->height - 1; i >= 0; i--) {
587 c->zstream.next_in = p->data[0]+p->linesize[0]*i; 587 c->zstream.next_in = p->data[0]+p->linesize[0]*i;
588 c->zstream.avail_in = avctx->width*3; 588 c->zstream.avail_in = avctx->width*3;
589 zret = deflate(&(c->zstream), Z_NO_FLUSH); 589 zret = deflate(&(c->zstream), Z_NO_FLUSH);
590 if (zret != Z_OK) { 590 if (zret != Z_OK) {
591 av_log(avctx, AV_LOG_ERROR, "Deflate error: %d\n", zret); 591 av_log(avctx, AV_LOG_ERROR, "Deflate error: %d\n", zret);
592 return -1; 592 return -1;
593 } 593 }
594 } 594 }
595 zret = deflate(&(c->zstream), Z_FINISH); 595 zret = deflate(&(c->zstream), Z_FINISH);
596 if (zret != Z_STREAM_END) { 596 if (zret != Z_STREAM_END) {
597 av_log(avctx, AV_LOG_ERROR, "Deflate error: %d\n", zret); 597 av_log(avctx, AV_LOG_ERROR, "Deflate error: %d\n", zret);
712 case COMP_ZLIB_NORMAL: 712 case COMP_ZLIB_NORMAL:
713 av_log(avctx, AV_LOG_INFO, "Normal compression.\n"); 713 av_log(avctx, AV_LOG_INFO, "Normal compression.\n");
714 break; 714 break;
715 default: 715 default:
716 if ((c->compression < Z_NO_COMPRESSION) || (c->compression > Z_BEST_COMPRESSION)) { 716 if ((c->compression < Z_NO_COMPRESSION) || (c->compression > Z_BEST_COMPRESSION)) {
717 av_log(avctx, AV_LOG_ERROR, "Unsupported compression level for ZLIB: (%d).\n", c->compression); 717 av_log(avctx, AV_LOG_ERROR, "Unsupported compression level for ZLIB: (%d).\n", c->compression);
718 return 1; 718 return 1;
719 } 719 }
720 av_log(avctx, AV_LOG_INFO, "Compression level for ZLIB: (%d).\n", c->compression); 720 av_log(avctx, AV_LOG_INFO, "Compression level for ZLIB: (%d).\n", c->compression);
721 } 721 }
722 #else 722 #else
849 * Uninit lcl decoder 849 * Uninit lcl decoder
850 * 850 *
851 */ 851 */
852 static int decode_end(AVCodecContext *avctx) 852 static int decode_end(AVCodecContext *avctx)
853 { 853 {
854 LclContext * const c = (LclContext *)avctx->priv_data; 854 LclContext * const c = (LclContext *)avctx->priv_data;
855 855
856 if (c->pic.data[0]) 856 if (c->pic.data[0])
857 avctx->release_buffer(avctx, &c->pic); 857 avctx->release_buffer(avctx, &c->pic);
858 #ifdef CONFIG_ZLIB 858 #ifdef CONFIG_ZLIB
859 inflateEnd(&(c->zstream)); 859 inflateEnd(&(c->zstream));
860 #endif 860 #endif
861 861
862 return 0; 862 return 0;
863 } 863 }
864 864
865 865
866 866
867 /* 867 /*
881 881
882 return 0; 882 return 0;
883 } 883 }
884 884
885 AVCodec mszh_decoder = { 885 AVCodec mszh_decoder = {
886 "mszh", 886 "mszh",
887 CODEC_TYPE_VIDEO, 887 CODEC_TYPE_VIDEO,
888 CODEC_ID_MSZH, 888 CODEC_ID_MSZH,
889 sizeof(LclContext), 889 sizeof(LclContext),
890 decode_init, 890 decode_init,
891 NULL, 891 NULL,
892 decode_end, 892 decode_end,
893 decode_frame, 893 decode_frame,
894 CODEC_CAP_DR1, 894 CODEC_CAP_DR1,
895 }; 895 };
896 896
897 897
898 AVCodec zlib_decoder = { 898 AVCodec zlib_decoder = {
899 "zlib", 899 "zlib",
900 CODEC_TYPE_VIDEO, 900 CODEC_TYPE_VIDEO,
901 CODEC_ID_ZLIB, 901 CODEC_ID_ZLIB,
902 sizeof(LclContext), 902 sizeof(LclContext),
903 decode_init, 903 decode_init,
904 NULL, 904 NULL,
905 decode_end, 905 decode_end,
906 decode_frame, 906 decode_frame,
907 CODEC_CAP_DR1, 907 CODEC_CAP_DR1,
908 }; 908 };
909 909
910 #ifdef CONFIG_ENCODERS 910 #ifdef CONFIG_ENCODERS
911 911
912 AVCodec zlib_encoder = { 912 AVCodec zlib_encoder = {