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.

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