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.

158 lines
3.6KB

  1. /*
  2. * Cirrus Logic AccuPak (CLJR) codec
  3. * Copyright (c) 2003 Alex Beregszaszi
  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 cljr.c
  23. * Cirrus Logic AccuPak codec.
  24. */
  25. #include "avcodec.h"
  26. #include "mpegvideo.h"
  27. typedef struct CLJRContext{
  28. AVCodecContext *avctx;
  29. AVFrame picture;
  30. int delta[16];
  31. int offset[4];
  32. GetBitContext gb;
  33. } CLJRContext;
  34. static int decode_frame(AVCodecContext *avctx,
  35. void *data, int *data_size,
  36. uint8_t *buf, int buf_size)
  37. {
  38. CLJRContext * const a = avctx->priv_data;
  39. AVFrame *picture = data;
  40. AVFrame * const p= (AVFrame*)&a->picture;
  41. int 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. init_get_bits(&a->gb, buf, buf_size);
  52. for(y=0; y<avctx->height; y++){
  53. uint8_t *luma= &a->picture.data[0][ y*a->picture.linesize[0] ];
  54. uint8_t *cb= &a->picture.data[1][ y*a->picture.linesize[1] ];
  55. uint8_t *cr= &a->picture.data[2][ y*a->picture.linesize[2] ];
  56. for(x=0; x<avctx->width; x+=4){
  57. luma[3] = get_bits(&a->gb, 5) << 3;
  58. luma[2] = get_bits(&a->gb, 5) << 3;
  59. luma[1] = get_bits(&a->gb, 5) << 3;
  60. luma[0] = get_bits(&a->gb, 5) << 3;
  61. luma+= 4;
  62. *(cb++) = get_bits(&a->gb, 6) << 2;
  63. *(cr++) = get_bits(&a->gb, 6) << 2;
  64. }
  65. }
  66. *picture= *(AVFrame*)&a->picture;
  67. *data_size = sizeof(AVPicture);
  68. emms_c();
  69. return buf_size;
  70. }
  71. #if 0
  72. static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
  73. CLJRContext * const a = avctx->priv_data;
  74. AVFrame *pict = data;
  75. AVFrame * const p= (AVFrame*)&a->picture;
  76. int size;
  77. int mb_x, mb_y;
  78. *p = *pict;
  79. p->pict_type= I_TYPE;
  80. p->key_frame= 1;
  81. emms_c();
  82. align_put_bits(&a->pb);
  83. while(get_bit_count(&a->pb)&31)
  84. put_bits(&a->pb, 8, 0);
  85. size= get_bit_count(&a->pb)/32;
  86. return size*4;
  87. }
  88. #endif
  89. static void common_init(AVCodecContext *avctx){
  90. CLJRContext * const a = avctx->priv_data;
  91. avctx->coded_frame= (AVFrame*)&a->picture;
  92. a->avctx= avctx;
  93. }
  94. static int decode_init(AVCodecContext *avctx){
  95. common_init(avctx);
  96. avctx->pix_fmt= PIX_FMT_YUV411P;
  97. return 0;
  98. }
  99. #if 0
  100. static int encode_init(AVCodecContext *avctx){
  101. common_init(avctx);
  102. return 0;
  103. }
  104. #endif
  105. AVCodec cljr_decoder = {
  106. "cljr",
  107. CODEC_TYPE_VIDEO,
  108. CODEC_ID_CLJR,
  109. sizeof(CLJRContext),
  110. decode_init,
  111. NULL,
  112. NULL,
  113. decode_frame,
  114. CODEC_CAP_DR1,
  115. };
  116. #if 0
  117. #ifdef CONFIG_ENCODERS
  118. AVCodec cljr_encoder = {
  119. "cljr",
  120. CODEC_TYPE_VIDEO,
  121. CODEC_ID_cljr,
  122. sizeof(CLJRContext),
  123. encode_init,
  124. encode_frame,
  125. //encode_end,
  126. };
  127. #endif //CONFIG_ENCODERS
  128. #endif