00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "libavutil/intreadwrite.h"
00023 #include "avcodec.h"
00024
00025 typedef struct PTXContext {
00026 AVFrame picture;
00027 } PTXContext;
00028
00029 static av_cold int ptx_init(AVCodecContext *avctx) {
00030 PTXContext *s = avctx->priv_data;
00031
00032 avcodec_get_frame_defaults(&s->picture);
00033 avctx->coded_frame= &s->picture;
00034
00035 return 0;
00036 }
00037
00038 static int ptx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
00039 const uint8_t *buf, int buf_size) {
00040 PTXContext * const s = avctx->priv_data;
00041 AVFrame *picture = data;
00042 AVFrame * const p = &s->picture;
00043 unsigned int offset, w, h, y, stride, bytes_per_pixel;
00044 uint8_t *ptr;
00045
00046 offset = AV_RL16(buf);
00047 w = AV_RL16(buf+8);
00048 h = AV_RL16(buf+10);
00049 bytes_per_pixel = AV_RL16(buf+12) >> 3;
00050
00051 if (bytes_per_pixel != 2) {
00052 av_log(avctx, AV_LOG_ERROR, "image format is not rgb15, please report on ffmpeg-users mailing list\n");
00053 return -1;
00054 }
00055
00056 avctx->pix_fmt = PIX_FMT_RGB555;
00057
00058 if (offset != 0x2c)
00059 av_log(avctx, AV_LOG_WARNING, "offset != 0x2c, untested due to lack of sample files\n");
00060
00061 buf += offset;
00062
00063 if (p->data[0])
00064 avctx->release_buffer(avctx, p);
00065
00066 if (avcodec_check_dimensions(avctx, w, h))
00067 return -1;
00068 if (w != avctx->width || h != avctx->height)
00069 avcodec_set_dimensions(avctx, w, h);
00070 if (avctx->get_buffer(avctx, p) < 0) {
00071 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
00072 return -1;
00073 }
00074
00075 p->pict_type = FF_I_TYPE;
00076
00077 ptr = p->data[0];
00078 stride = p->linesize[0];
00079
00080 for (y=0; y<h; y++) {
00081 #ifdef WORDS_BIGENDIAN
00082 unsigned int x;
00083 for (x=0; x<w*bytes_per_pixel; x+=bytes_per_pixel)
00084 AV_WN16(ptr+x, AV_RL16(buf+x));
00085 #else
00086 memcpy(ptr, buf, w*bytes_per_pixel);
00087 #endif
00088 ptr += stride;
00089 buf += w*bytes_per_pixel;
00090 }
00091
00092 *picture = s->picture;
00093 *data_size = sizeof(AVPicture);
00094
00095 return offset + w*h*bytes_per_pixel;
00096 }
00097
00098 static av_cold int ptx_end(AVCodecContext *avctx) {
00099 PTXContext *s = avctx->priv_data;
00100
00101 if(s->picture.data[0])
00102 avctx->release_buffer(avctx, &s->picture);
00103
00104 return 0;
00105 }
00106
00107 AVCodec ptx_decoder = {
00108 "ptx",
00109 CODEC_TYPE_VIDEO,
00110 CODEC_ID_PTX,
00111 sizeof(PTXContext),
00112 ptx_init,
00113 NULL,
00114 ptx_end,
00115 ptx_decode_frame,
00116 0,
00117 NULL,
00118 .long_name = NULL_IF_CONFIG_SMALL("V.Flash PTX image"),
00119 };