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.

152 lines
4.5KB

  1. /*
  2. * ATI VCR1 codec
  3. * Copyright (c) 2003 Michael Niedermayer
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * ATI VCR1 codec
  24. */
  25. #include "avcodec.h"
  26. #include "dsputil.h"
  27. #include "internal.h"
  28. #include "libavutil/internal.h"
  29. typedef struct VCR1Context {
  30. AVFrame picture;
  31. int delta[16];
  32. int offset[4];
  33. } VCR1Context;
  34. static av_cold int vcr1_common_init(AVCodecContext *avctx)
  35. {
  36. VCR1Context *const a = avctx->priv_data;
  37. avctx->coded_frame = &a->picture;
  38. return 0;
  39. }
  40. static av_cold int vcr1_decode_init(AVCodecContext *avctx)
  41. {
  42. vcr1_common_init(avctx);
  43. avctx->pix_fmt = AV_PIX_FMT_YUV410P;
  44. return 0;
  45. }
  46. static av_cold int vcr1_decode_end(AVCodecContext *avctx)
  47. {
  48. VCR1Context *s = avctx->priv_data;
  49. if (s->picture.data[0])
  50. avctx->release_buffer(avctx, &s->picture);
  51. return 0;
  52. }
  53. static int vcr1_decode_frame(AVCodecContext *avctx, void *data,
  54. int *got_frame, AVPacket *avpkt)
  55. {
  56. const uint8_t *buf = avpkt->data;
  57. int buf_size = avpkt->size;
  58. VCR1Context *const a = avctx->priv_data;
  59. AVFrame *picture = data;
  60. AVFrame *const p = &a->picture;
  61. const uint8_t *bytestream = buf;
  62. int i, x, y, ret;
  63. if (p->data[0])
  64. avctx->release_buffer(avctx, p);
  65. p->reference = 0;
  66. if ((ret = ff_get_buffer(avctx, p)) < 0) {
  67. av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
  68. return ret;
  69. }
  70. p->pict_type = AV_PICTURE_TYPE_I;
  71. p->key_frame = 1;
  72. for (i = 0; i < 16; i++) {
  73. a->delta[i] = *bytestream++;
  74. bytestream++;
  75. }
  76. for (y = 0; y < avctx->height; y++) {
  77. int offset;
  78. uint8_t *luma = &a->picture.data[0][y * a->picture.linesize[0]];
  79. if ((y & 3) == 0) {
  80. uint8_t *cb = &a->picture.data[1][(y >> 2) * a->picture.linesize[1]];
  81. uint8_t *cr = &a->picture.data[2][(y >> 2) * a->picture.linesize[2]];
  82. for (i = 0; i < 4; i++)
  83. a->offset[i] = *bytestream++;
  84. offset = a->offset[0] - a->delta[bytestream[2] & 0xF];
  85. for (x = 0; x < avctx->width; x += 4) {
  86. luma[0] = offset += a->delta[bytestream[2] & 0xF];
  87. luma[1] = offset += a->delta[bytestream[2] >> 4];
  88. luma[2] = offset += a->delta[bytestream[0] & 0xF];
  89. luma[3] = offset += a->delta[bytestream[0] >> 4];
  90. luma += 4;
  91. *cb++ = bytestream[3];
  92. *cr++ = bytestream[1];
  93. bytestream += 4;
  94. }
  95. } else {
  96. offset = a->offset[y & 3] - a->delta[bytestream[2] & 0xF];
  97. for (x = 0; x < avctx->width; x += 8) {
  98. luma[0] = offset += a->delta[bytestream[2] & 0xF];
  99. luma[1] = offset += a->delta[bytestream[2] >> 4];
  100. luma[2] = offset += a->delta[bytestream[3] & 0xF];
  101. luma[3] = offset += a->delta[bytestream[3] >> 4];
  102. luma[4] = offset += a->delta[bytestream[0] & 0xF];
  103. luma[5] = offset += a->delta[bytestream[0] >> 4];
  104. luma[6] = offset += a->delta[bytestream[1] & 0xF];
  105. luma[7] = offset += a->delta[bytestream[1] >> 4];
  106. luma += 8;
  107. bytestream += 4;
  108. }
  109. }
  110. }
  111. *picture = a->picture;
  112. *got_frame = 1;
  113. return buf_size;
  114. }
  115. AVCodec ff_vcr1_decoder = {
  116. .name = "vcr1",
  117. .type = AVMEDIA_TYPE_VIDEO,
  118. .id = AV_CODEC_ID_VCR1,
  119. .priv_data_size = sizeof(VCR1Context),
  120. .init = vcr1_decode_init,
  121. .close = vcr1_decode_end,
  122. .decode = vcr1_decode_frame,
  123. .capabilities = CODEC_CAP_DR1,
  124. .long_name = NULL_IF_CONFIG_SMALL("ATI VCR1"),
  125. };