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.

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