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.

139 lines
3.6KB

  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. if(p->data[0])
  47. avctx->release_buffer(avctx, p);
  48. p->reference = 0;
  49. if(avctx->get_buffer(avctx, p) < 0){
  50. av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
  51. return -1;
  52. }
  53. p->pict_type= I_TYPE;
  54. p->key_frame= 1;
  55. Y = a->pic.data[0];
  56. U = a->pic.data[1];
  57. V = a->pic.data[2];
  58. stride = avctx->width - 4;
  59. for (i = 0; i < avctx->height; i++) {
  60. /* lines are stored in reversed order */
  61. buf += stride;
  62. for (j = 0; j < avctx->width; j += 4) {
  63. /* value is stored in LE dword with word swapped */
  64. val = LE_32(buf);
  65. buf -= 4;
  66. val = ((val >> 16) & 0xFFFF) | ((val & 0xFFFF) << 16);
  67. if(!j)
  68. y0 = (val & 0x1F) << 2;
  69. else
  70. y0 = y3 + xl_table[val & 0x1F];
  71. val >>= 5;
  72. y1 = y0 + xl_table[val & 0x1F];
  73. val >>= 5;
  74. y2 = y1 + xl_table[val & 0x1F];
  75. val >>= 6; /* align to word */
  76. y3 = y2 + xl_table[val & 0x1F];
  77. val >>= 5;
  78. if(!j)
  79. c0 = (val & 0x1F) << 2;
  80. else
  81. c0 += xl_table[val & 0x1F];
  82. val >>= 5;
  83. if(!j)
  84. c1 = (val & 0x1F) << 2;
  85. else
  86. c1 += xl_table[val & 0x1F];
  87. Y[j + 0] = y0 << 1;
  88. Y[j + 1] = y1 << 1;
  89. Y[j + 2] = y2 << 1;
  90. Y[j + 3] = y3 << 1;
  91. U[j >> 2] = c0 << 1;
  92. V[j >> 2] = c1 << 1;
  93. }
  94. buf += avctx->width + 4;
  95. Y += a->pic.linesize[0];
  96. U += a->pic.linesize[1];
  97. V += a->pic.linesize[2];
  98. }
  99. *data_size = sizeof(AVFrame);
  100. *(AVFrame*)data = a->pic;
  101. return buf_size;
  102. }
  103. static int decode_init(AVCodecContext *avctx){
  104. // VideoXLContext * const a = avctx->priv_data;
  105. avctx->pix_fmt= PIX_FMT_YUV411P;
  106. return 0;
  107. }
  108. AVCodec xl_decoder = {
  109. "xl",
  110. CODEC_TYPE_VIDEO,
  111. CODEC_ID_VIXL,
  112. sizeof(VideoXLContext),
  113. decode_init,
  114. NULL,
  115. NULL,
  116. decode_frame,
  117. CODEC_CAP_DR1,
  118. };