You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

191 lines
4.7KB

  1. /*
  2. * ATI VCR1 codec
  3. * Copyright (c) 2003 Michael Niedermayer
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file vcr1.c
  23. * ati vcr1 codec.
  24. */
  25. #include "avcodec.h"
  26. #include "mpegvideo.h"
  27. //#undef NDEBUG
  28. //#include <assert.h>
  29. typedef struct VCR1Context{
  30. AVCodecContext *avctx;
  31. AVFrame picture;
  32. int delta[16];
  33. int offset[4];
  34. } VCR1Context;
  35. static int decode_frame(AVCodecContext *avctx,
  36. void *data, int *data_size,
  37. uint8_t *buf, int buf_size)
  38. {
  39. VCR1Context * const a = avctx->priv_data;
  40. AVFrame *picture = data;
  41. AVFrame * const p= (AVFrame*)&a->picture;
  42. uint8_t *bytestream= buf;
  43. int i, x, y;
  44. if(p->data[0])
  45. avctx->release_buffer(avctx, p);
  46. p->reference= 0;
  47. if(avctx->get_buffer(avctx, p) < 0){
  48. av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
  49. return -1;
  50. }
  51. p->pict_type= I_TYPE;
  52. p->key_frame= 1;
  53. for(i=0; i<16; i++){
  54. a->delta[i]= *(bytestream++);
  55. bytestream++;
  56. }
  57. for(y=0; y<avctx->height; y++){
  58. int offset;
  59. uint8_t *luma= &a->picture.data[0][ y*a->picture.linesize[0] ];
  60. if((y&3) == 0){
  61. uint8_t *cb= &a->picture.data[1][ (y>>2)*a->picture.linesize[1] ];
  62. uint8_t *cr= &a->picture.data[2][ (y>>2)*a->picture.linesize[2] ];
  63. for(i=0; i<4; i++)
  64. a->offset[i]= *(bytestream++);
  65. offset= a->offset[0] - a->delta[ bytestream[2]&0xF ];
  66. for(x=0; x<avctx->width; x+=4){
  67. luma[0]=( offset += a->delta[ bytestream[2]&0xF ]);
  68. luma[1]=( offset += a->delta[ bytestream[2]>>4 ]);
  69. luma[2]=( offset += a->delta[ bytestream[0]&0xF ]);
  70. luma[3]=( offset += a->delta[ bytestream[0]>>4 ]);
  71. luma += 4;
  72. *(cb++) = bytestream[3];
  73. *(cr++) = bytestream[1];
  74. bytestream+= 4;
  75. }
  76. }else{
  77. offset= a->offset[y&3] - a->delta[ bytestream[2]&0xF ];
  78. for(x=0; x<avctx->width; x+=8){
  79. luma[0]=( offset += a->delta[ bytestream[2]&0xF ]);
  80. luma[1]=( offset += a->delta[ bytestream[2]>>4 ]);
  81. luma[2]=( offset += a->delta[ bytestream[3]&0xF ]);
  82. luma[3]=( offset += a->delta[ bytestream[3]>>4 ]);
  83. luma[4]=( offset += a->delta[ bytestream[0]&0xF ]);
  84. luma[5]=( offset += a->delta[ bytestream[0]>>4 ]);
  85. luma[6]=( offset += a->delta[ bytestream[1]&0xF ]);
  86. luma[7]=( offset += a->delta[ bytestream[1]>>4 ]);
  87. luma += 8;
  88. bytestream+= 4;
  89. }
  90. }
  91. }
  92. *picture= *(AVFrame*)&a->picture;
  93. *data_size = sizeof(AVPicture);
  94. emms_c();
  95. return buf_size;
  96. }
  97. #if 0
  98. static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
  99. VCR1Context * const a = avctx->priv_data;
  100. AVFrame *pict = data;
  101. AVFrame * const p= (AVFrame*)&a->picture;
  102. int size;
  103. int mb_x, mb_y;
  104. *p = *pict;
  105. p->pict_type= I_TYPE;
  106. p->key_frame= 1;
  107. emms_c();
  108. align_put_bits(&a->pb);
  109. while(get_bit_count(&a->pb)&31)
  110. put_bits(&a->pb, 8, 0);
  111. size= get_bit_count(&a->pb)/32;
  112. return size*4;
  113. }
  114. #endif
  115. static void common_init(AVCodecContext *avctx){
  116. VCR1Context * const a = avctx->priv_data;
  117. avctx->coded_frame= (AVFrame*)&a->picture;
  118. a->avctx= avctx;
  119. }
  120. static int decode_init(AVCodecContext *avctx){
  121. common_init(avctx);
  122. avctx->pix_fmt= PIX_FMT_YUV410P;
  123. return 0;
  124. }
  125. #if 0
  126. static int encode_init(AVCodecContext *avctx){
  127. common_init(avctx);
  128. return 0;
  129. }
  130. #endif
  131. AVCodec vcr1_decoder = {
  132. "vcr1",
  133. CODEC_TYPE_VIDEO,
  134. CODEC_ID_VCR1,
  135. sizeof(VCR1Context),
  136. decode_init,
  137. NULL,
  138. NULL,
  139. decode_frame,
  140. CODEC_CAP_DR1,
  141. };
  142. #if 0
  143. #ifdef CONFIG_ENCODERS
  144. AVCodec vcr1_encoder = {
  145. "vcr1",
  146. CODEC_TYPE_VIDEO,
  147. CODEC_ID_VCR1,
  148. sizeof(VCR1Context),
  149. encode_init,
  150. encode_frame,
  151. //encode_end,
  152. };
  153. #endif //CONFIG_ENCODERS
  154. #endif