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.

145 lines
3.7KB

  1. /*
  2. * Miro VideoXL codec
  3. * Copyright (c) 2004 Konstantin Shishkov
  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. /**
  21. * @file xl.c
  22. * Miro VideoXL codec.
  23. */
  24. #include "avcodec.h"
  25. #include "mpegvideo.h"
  26. typedef struct VideoXLContext{
  27. AVCodecContext *avctx;
  28. AVFrame pic;
  29. } VideoXLContext;
  30. const int xl_table[32] = {
  31. 0, 1, 2, 3, 4, 5, 6, 7,
  32. 8, 9, 12, 15, 20, 25, 34, 46,
  33. 64, 82, 94, 103, 108, 113, 116, 119,
  34. 120, 121, 122, 123, 124, 125, 126, 127};
  35. static int decode_frame(AVCodecContext *avctx,
  36. void *data, int *data_size,
  37. uint8_t *buf, int buf_size)
  38. {
  39. VideoXLContext * const a = avctx->priv_data;
  40. AVFrame * const p= (AVFrame*)&a->pic;
  41. uint8_t *Y, *U, *V;
  42. int i, j;
  43. int stride;
  44. uint32_t val;
  45. int y0, y1, y2, y3, c0, c1;
  46. /* special case for last picture */
  47. if (buf_size == 0) {
  48. return 0;
  49. }
  50. if(p->data[0])
  51. avctx->release_buffer(avctx, p);
  52. p->reference = 0;
  53. if(avctx->get_buffer(avctx, p) < 0){
  54. av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
  55. return -1;
  56. }
  57. p->pict_type= I_TYPE;
  58. p->key_frame= 1;
  59. Y = a->pic.data[0];
  60. U = a->pic.data[1];
  61. V = a->pic.data[2];
  62. stride = avctx->width - 4;
  63. for (i = 0; i < avctx->height; i++) {
  64. /* lines are stored in reversed order */
  65. buf += stride;
  66. for (j = 0; j < avctx->width; j += 4) {
  67. /* value is stored in LE dword with word swapped */
  68. val = LE_32(buf);
  69. buf -= 4;
  70. val = ((val >> 16) & 0xFFFF) | ((val & 0xFFFF) << 16);
  71. if(!j)
  72. y0 = (val & 0x1F) << 2;
  73. else
  74. y0 = y3 + xl_table[val & 0x1F];
  75. val >>= 5;
  76. y1 = y0 + xl_table[val & 0x1F];
  77. val >>= 5;
  78. y2 = y1 + xl_table[val & 0x1F];
  79. val >>= 6; /* align to word */
  80. y3 = y2 + xl_table[val & 0x1F];
  81. val >>= 5;
  82. if(!j)
  83. c0 = (val & 0x1F) << 2;
  84. else
  85. c0 += xl_table[val & 0x1F];
  86. val >>= 5;
  87. if(!j)
  88. c1 = (val & 0x1F) << 2;
  89. else
  90. c1 += xl_table[val & 0x1F];
  91. Y[j + 0] = y0 << 1;
  92. Y[j + 1] = y1 << 1;
  93. Y[j + 2] = y2 << 1;
  94. Y[j + 3] = y3 << 1;
  95. U[j >> 2] = c0 << 1;
  96. V[j >> 2] = c1 << 1;
  97. }
  98. buf += avctx->width + 4;
  99. Y += a->pic.linesize[0];
  100. U += a->pic.linesize[1];
  101. V += a->pic.linesize[2];
  102. }
  103. *data_size = sizeof(AVFrame);
  104. *(AVFrame*)data = a->pic;
  105. return buf_size;
  106. }
  107. static int decode_init(AVCodecContext *avctx){
  108. // VideoXLContext * const a = avctx->priv_data;
  109. avctx->pix_fmt= PIX_FMT_YUV411P;
  110. return 0;
  111. }
  112. AVCodec xl_decoder = {
  113. "xl",
  114. CODEC_TYPE_VIDEO,
  115. CODEC_ID_VIXL,
  116. sizeof(VideoXLContext),
  117. decode_init,
  118. NULL,
  119. NULL,
  120. decode_frame,
  121. CODEC_CAP_DR1,
  122. };