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.

189 lines
4.8KB

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