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.

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