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.

121 lines
3.2KB

  1. /*
  2. * V.Flash PTX (.ptx) image decoder
  3. * Copyright (c) 2007 Ivo van Poorten
  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. #include "libavutil/intreadwrite.h"
  22. #include "avcodec.h"
  23. typedef struct PTXContext {
  24. AVFrame picture;
  25. } PTXContext;
  26. static av_cold int ptx_init(AVCodecContext *avctx) {
  27. PTXContext *s = avctx->priv_data;
  28. avcodec_get_frame_defaults(&s->picture);
  29. avctx->coded_frame= &s->picture;
  30. return 0;
  31. }
  32. static int ptx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
  33. AVPacket *avpkt) {
  34. const uint8_t *buf = avpkt->data;
  35. PTXContext * const s = avctx->priv_data;
  36. AVFrame *picture = data;
  37. AVFrame * const p = &s->picture;
  38. unsigned int offset, w, h, y, stride, bytes_per_pixel;
  39. uint8_t *ptr;
  40. offset = AV_RL16(buf);
  41. w = AV_RL16(buf+8);
  42. h = AV_RL16(buf+10);
  43. bytes_per_pixel = AV_RL16(buf+12) >> 3;
  44. if (bytes_per_pixel != 2) {
  45. av_log(avctx, AV_LOG_ERROR, "image format is not rgb15, please report on ffmpeg-users mailing list\n");
  46. return -1;
  47. }
  48. avctx->pix_fmt = PIX_FMT_RGB555;
  49. if (offset != 0x2c)
  50. av_log(avctx, AV_LOG_WARNING, "offset != 0x2c, untested due to lack of sample files\n");
  51. buf += offset;
  52. if (p->data[0])
  53. avctx->release_buffer(avctx, p);
  54. if (avcodec_check_dimensions(avctx, w, h))
  55. return -1;
  56. if (w != avctx->width || h != avctx->height)
  57. avcodec_set_dimensions(avctx, w, h);
  58. if (avctx->get_buffer(avctx, p) < 0) {
  59. av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
  60. return -1;
  61. }
  62. p->pict_type = FF_I_TYPE;
  63. ptr = p->data[0];
  64. stride = p->linesize[0];
  65. for (y=0; y<h; y++) {
  66. #if HAVE_BIGENDIAN
  67. unsigned int x;
  68. for (x=0; x<w*bytes_per_pixel; x+=bytes_per_pixel)
  69. AV_WN16(ptr+x, AV_RL16(buf+x));
  70. #else
  71. memcpy(ptr, buf, w*bytes_per_pixel);
  72. #endif
  73. ptr += stride;
  74. buf += w*bytes_per_pixel;
  75. }
  76. *picture = s->picture;
  77. *data_size = sizeof(AVPicture);
  78. return offset + w*h*bytes_per_pixel;
  79. }
  80. static av_cold int ptx_end(AVCodecContext *avctx) {
  81. PTXContext *s = avctx->priv_data;
  82. if(s->picture.data[0])
  83. avctx->release_buffer(avctx, &s->picture);
  84. return 0;
  85. }
  86. AVCodec ptx_decoder = {
  87. "ptx",
  88. AVMEDIA_TYPE_VIDEO,
  89. CODEC_ID_PTX,
  90. sizeof(PTXContext),
  91. ptx_init,
  92. NULL,
  93. ptx_end,
  94. ptx_decode_frame,
  95. CODEC_CAP_DR1,
  96. NULL,
  97. .long_name = NULL_IF_CONFIG_SMALL("V.Flash PTX image"),
  98. };