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.

195 lines
5.0KB

  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 libavcodec/vcr1.c
  23. * ati vcr1 codec.
  24. */
  25. #include "avcodec.h"
  26. #include "dsputil.h"
  27. //#undef NDEBUG
  28. //#include <assert.h>
  29. /* Disable the encoder. */
  30. #undef CONFIG_VCR1_ENCODER
  31. #define CONFIG_VCR1_ENCODER 0
  32. typedef struct VCR1Context{
  33. AVCodecContext *avctx;
  34. AVFrame picture;
  35. int delta[16];
  36. int offset[4];
  37. } VCR1Context;
  38. static int decode_frame(AVCodecContext *avctx,
  39. void *data, int *data_size,
  40. AVPacket *avpkt)
  41. {
  42. const uint8_t *buf = avpkt->data;
  43. int buf_size = avpkt->size;
  44. VCR1Context * const a = avctx->priv_data;
  45. AVFrame *picture = data;
  46. AVFrame * const p= (AVFrame*)&a->picture;
  47. const uint8_t *bytestream= buf;
  48. int i, x, y;
  49. if(p->data[0])
  50. avctx->release_buffer(avctx, p);
  51. p->reference= 0;
  52. if(avctx->get_buffer(avctx, p) < 0){
  53. av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
  54. return -1;
  55. }
  56. p->pict_type= FF_I_TYPE;
  57. p->key_frame= 1;
  58. for(i=0; i<16; i++){
  59. a->delta[i]= *(bytestream++);
  60. bytestream++;
  61. }
  62. for(y=0; y<avctx->height; y++){
  63. int offset;
  64. uint8_t *luma= &a->picture.data[0][ y*a->picture.linesize[0] ];
  65. if((y&3) == 0){
  66. uint8_t *cb= &a->picture.data[1][ (y>>2)*a->picture.linesize[1] ];
  67. uint8_t *cr= &a->picture.data[2][ (y>>2)*a->picture.linesize[2] ];
  68. for(i=0; i<4; i++)
  69. a->offset[i]= *(bytestream++);
  70. offset= a->offset[0] - a->delta[ bytestream[2]&0xF ];
  71. for(x=0; x<avctx->width; x+=4){
  72. luma[0]=( offset += a->delta[ bytestream[2]&0xF ]);
  73. luma[1]=( offset += a->delta[ bytestream[2]>>4 ]);
  74. luma[2]=( offset += a->delta[ bytestream[0]&0xF ]);
  75. luma[3]=( offset += a->delta[ bytestream[0]>>4 ]);
  76. luma += 4;
  77. *(cb++) = bytestream[3];
  78. *(cr++) = bytestream[1];
  79. bytestream+= 4;
  80. }
  81. }else{
  82. offset= a->offset[y&3] - a->delta[ bytestream[2]&0xF ];
  83. for(x=0; x<avctx->width; x+=8){
  84. luma[0]=( offset += a->delta[ bytestream[2]&0xF ]);
  85. luma[1]=( offset += a->delta[ bytestream[2]>>4 ]);
  86. luma[2]=( offset += a->delta[ bytestream[3]&0xF ]);
  87. luma[3]=( offset += a->delta[ bytestream[3]>>4 ]);
  88. luma[4]=( offset += a->delta[ bytestream[0]&0xF ]);
  89. luma[5]=( offset += a->delta[ bytestream[0]>>4 ]);
  90. luma[6]=( offset += a->delta[ bytestream[1]&0xF ]);
  91. luma[7]=( offset += a->delta[ bytestream[1]>>4 ]);
  92. luma += 8;
  93. bytestream+= 4;
  94. }
  95. }
  96. }
  97. *picture= *(AVFrame*)&a->picture;
  98. *data_size = sizeof(AVPicture);
  99. emms_c();
  100. return buf_size;
  101. }
  102. #if CONFIG_VCR1_ENCODER
  103. static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
  104. VCR1Context * const a = avctx->priv_data;
  105. AVFrame *pict = data;
  106. AVFrame * const p= (AVFrame*)&a->picture;
  107. int size;
  108. *p = *pict;
  109. p->pict_type= FF_I_TYPE;
  110. p->key_frame= 1;
  111. emms_c();
  112. align_put_bits(&a->pb);
  113. while(get_bit_count(&a->pb)&31)
  114. put_bits(&a->pb, 8, 0);
  115. size= get_bit_count(&a->pb)/32;
  116. return size*4;
  117. }
  118. #endif
  119. static av_cold void common_init(AVCodecContext *avctx){
  120. VCR1Context * const a = avctx->priv_data;
  121. avctx->coded_frame= (AVFrame*)&a->picture;
  122. a->avctx= avctx;
  123. }
  124. static av_cold int decode_init(AVCodecContext *avctx){
  125. common_init(avctx);
  126. avctx->pix_fmt= PIX_FMT_YUV410P;
  127. return 0;
  128. }
  129. #if CONFIG_VCR1_ENCODER
  130. static av_cold int encode_init(AVCodecContext *avctx){
  131. common_init(avctx);
  132. return 0;
  133. }
  134. #endif
  135. AVCodec vcr1_decoder = {
  136. "vcr1",
  137. CODEC_TYPE_VIDEO,
  138. CODEC_ID_VCR1,
  139. sizeof(VCR1Context),
  140. decode_init,
  141. NULL,
  142. NULL,
  143. decode_frame,
  144. CODEC_CAP_DR1,
  145. .long_name = NULL_IF_CONFIG_SMALL("ATI VCR1"),
  146. };
  147. #if CONFIG_VCR1_ENCODER
  148. AVCodec vcr1_encoder = {
  149. "vcr1",
  150. CODEC_TYPE_VIDEO,
  151. CODEC_ID_VCR1,
  152. sizeof(VCR1Context),
  153. encode_init,
  154. encode_frame,
  155. //encode_end,
  156. .long_name = NULL_IF_CONFIG_SMALL("ATI VCR1"),
  157. };
  158. #endif