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.

111 lines
3.2KB

  1. /*
  2. * 8088flex TMV video decoder
  3. * Copyright (c) 2009 Daniel Verkamp <daniel at drv.nu>
  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. * 8088flex TMV video decoder
  23. * @file libavcodec/tmv.c
  24. * @author Daniel Verkamp
  25. * @sa http://www.oldskool.org/pc/8088_Corruption
  26. */
  27. #include "avcodec.h"
  28. #include "cga_data.h"
  29. typedef struct TMVContext {
  30. AVFrame pic;
  31. } TMVContext;
  32. static int tmv_decode_frame(AVCodecContext *avctx, void *data,
  33. int *data_size, AVPacket *avpkt)
  34. {
  35. TMVContext *tmv = avctx->priv_data;
  36. const uint8_t *src = avpkt->data;
  37. uint8_t *dst, *dst_char;
  38. unsigned char_cols = avctx->width >> 3;
  39. unsigned char_rows = avctx->height >> 3;
  40. unsigned x, y, mask, char_y, fg, bg, c;
  41. if (tmv->pic.data[0])
  42. avctx->release_buffer(avctx, &tmv->pic);
  43. if (avctx->get_buffer(avctx, &tmv->pic) < 0) {
  44. av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
  45. return -1;
  46. }
  47. if (avpkt->size < 2*char_rows*char_cols) {
  48. av_log(avctx, AV_LOG_ERROR,
  49. "Input buffer too small, truncated sample?\n");
  50. *data_size = 0;
  51. return -1;
  52. }
  53. tmv->pic.pict_type = FF_I_TYPE;
  54. tmv->pic.key_frame = 1;
  55. dst = tmv->pic.data[0];
  56. tmv->pic.palette_has_changed = 1;
  57. memcpy(tmv->pic.data[1], ff_cga_palette, 16 * 4);
  58. for (y = 0; y < char_rows; y++) {
  59. for (x = 0; x < char_cols; x++) {
  60. c = *src++ * 8;
  61. bg = *src >> 4;
  62. fg = *src++ & 0xF;
  63. dst_char = dst + x * 8;
  64. for (char_y = 0; char_y < 8; char_y++) {
  65. for (mask = 0x80; mask; mask >>= 1) {
  66. *dst_char++ = ff_cga_font[c + char_y] & mask ? fg : bg;
  67. }
  68. dst_char += tmv->pic.linesize[0] - 8;
  69. }
  70. }
  71. dst += tmv->pic.linesize[0] * 8;
  72. }
  73. *data_size = sizeof(AVFrame);
  74. *(AVFrame *)data = tmv->pic;
  75. return avpkt->size;
  76. }
  77. static av_cold int tmv_decode_close(AVCodecContext *avctx)
  78. {
  79. TMVContext *tmv = avctx->priv_data;
  80. if (tmv->pic.data[0])
  81. avctx->release_buffer(avctx, &tmv->pic);
  82. return 0;
  83. }
  84. AVCodec tmv_decoder = {
  85. .name = "tmv",
  86. .type = CODEC_TYPE_VIDEO,
  87. .id = CODEC_ID_TMV,
  88. .priv_data_size = sizeof(TMVContext),
  89. .close = tmv_decode_close,
  90. .decode = tmv_decode_frame,
  91. .capabilities = CODEC_CAP_DR1,
  92. .long_name = NULL_IF_CONFIG_SMALL("8088flex TMV"),
  93. };