aasc.c
Go to the documentation of this file.
1 /*
2  * Autodesk RLE Decoder
3  * Copyright (C) 2005 the ffmpeg project
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 
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 
31 #include "avcodec.h"
32 #include "dsputil.h"
33 #include "msrledec.h"
34 
35 typedef struct AascContext {
39 } AascContext;
40 
42 {
43  AascContext *s = avctx->priv_data;
44 
45  s->avctx = avctx;
46 
47  avctx->pix_fmt = PIX_FMT_BGR24;
48 
49  return 0;
50 }
51 
53  void *data, int *data_size,
54  AVPacket *avpkt)
55 {
56  const uint8_t *buf = avpkt->data;
57  int buf_size = avpkt->size;
58  AascContext *s = avctx->priv_data;
59  int compr, i, stride;
60 
61  s->frame.reference = 1;
63  if (avctx->reget_buffer(avctx, &s->frame)) {
64  av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
65  return -1;
66  }
67 
68  compr = AV_RL32(buf);
69  buf += 4;
70  buf_size -= 4;
71  switch(compr){
72  case 0:
73  stride = (avctx->width * 3 + 3) & ~3;
74  for(i = avctx->height - 1; i >= 0; i--){
75  memcpy(s->frame.data[0] + i*s->frame.linesize[0], buf, avctx->width*3);
76  buf += stride;
77  }
78  break;
79  case 1:
80  bytestream2_init(&s->gb, buf - 4, buf_size + 4);
81  ff_msrle_decode(avctx, (AVPicture*)&s->frame, 8, &s->gb);
82  break;
83  default:
84  av_log(avctx, AV_LOG_ERROR, "Unknown compression type %d\n", compr);
85  return -1;
86  }
87 
88  *data_size = sizeof(AVFrame);
89  *(AVFrame*)data = s->frame;
90 
91  /* report that the buffer was completely consumed */
92  return buf_size;
93 }
94 
96 {
97  AascContext *s = avctx->priv_data;
98 
99  /* release the last frame */
100  if (s->frame.data[0])
101  avctx->release_buffer(avctx, &s->frame);
102 
103  return 0;
104 }
105 
107  .name = "aasc",
108  .type = AVMEDIA_TYPE_VIDEO,
109  .id = CODEC_ID_AASC,
110  .priv_data_size = sizeof(AascContext),
114  .capabilities = CODEC_CAP_DR1,
115  .long_name = NULL_IF_CONFIG_SMALL("Autodesk RLE"),
116 };
enum PixelFormat pix_fmt
Pixel format, see PIX_FMT_xxx.
Definition: avcodec.h:1426
#define FF_BUFFER_HINTS_VALID
Definition: avcodec.h:880
Audio Video Frame.
Definition: avcodec.h:985
int buffer_hints
codec suggestion on buffer type if != 0
Definition: avcodec.h:1195
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
Definition: avcodec.h:1737
int size
Definition: avcodec.h:909
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:138
four components are given, that's all.
Definition: avcodec.h:3367
int stride
Definition: mace.c:143
AVCodec.
Definition: avcodec.h:3189
int(* reget_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called at the beginning of a frame to get cr buffer for it.
Definition: avcodec.h:2336
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
Definition: mimic.c:228
#define av_cold
Definition: attributes.h:71
const char data[16]
Definition: mxf.c:60
uint8_t * data
Definition: avcodec.h:908
static int aasc_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
Definition: aasc.c:52
static int init(AVCodecParserContext *s)
Definition: h264_parser.c:336
static av_cold int aasc_decode_end(AVCodecContext *avctx)
Definition: aasc.c:95
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:719
struct AascContext AascContext
int reference
is this picture used as reference The values for this are the same as the MpegEncContext.picture_structure variable, that is 1->top field, 2->bottom field, 3->frame/both fields.
Definition: avcodec.h:1074
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:191
AV_RL32
Definition: bytestream.h:89
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:140
const char * name
Name of the codec implementation.
Definition: avcodec.h:3196
GetByteContext gb
Definition: aasc.c:37
int width
picture width / height.
Definition: avcodec.h:1408
struct AVFrame AVFrame
Audio Video Frame.
static av_cold int aasc_decode_init(AVCodecContext *avctx)
Definition: aasc.c:41
#define FF_BUFFER_HINTS_REUSABLE
Definition: avcodec.h:883
AVFrame frame
Definition: aasc.c:38
external API header
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
Definition: avcodec.h:1008
main external API structure.
Definition: avcodec.h:1329
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:327
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:111
#define FF_BUFFER_HINTS_PRESERVE
Definition: avcodec.h:882
AVCodec ff_aasc_decoder
Definition: aasc.c:106
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:67
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: avcodec.h:997
DSP utils.
void * priv_data
Definition: avcodec.h:1531
int ff_msrle_decode(AVCodecContext *avctx, AVPicture *pic, int depth, GetByteContext *gb)
Decode stream in MS RLE format into frame.
Definition: msrledec.c:246
AVCodecContext * avctx
Definition: aasc.c:36