* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
*/
-#include "avcodec.h"
-enum TargaCompr{
- TGA_NODATA = 0, // no image data
- TGA_PAL = 1, // palettized
- TGA_RGB = 2, // true-color
- TGA_BW = 3, // black & white or grayscale
- TGA_RLE = 8, // flag pointing that data is RLE-coded
-};
+#include "libavutil/intreadwrite.h"
+#include "libavcore/imgutils.h"
+#include "avcodec.h"
+#include "targa.h"
typedef struct TargaContext {
AVFrame picture;
int compression_type;
} TargaContext;
-static void targa_decode_rle(AVCodecContext *avctx, TargaContext *s, uint8_t *src, uint8_t *dst, int w, int h, int stride, int bpp)
+static void targa_decode_rle(AVCodecContext *avctx, TargaContext *s, const uint8_t *src, uint8_t *dst, int w, int h, int stride, int bpp)
{
int i, x, y;
int depth = (bpp + 1) >> 3;
static int decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
- uint8_t *buf, int buf_size)
+ AVPacket *avpkt)
{
+ const uint8_t *buf = avpkt->data;
+ int buf_size = avpkt->size;
TargaContext * const s = avctx->priv_data;
AVFrame *picture = data;
AVFrame * const p= (AVFrame*)&s->picture;
avctx->pix_fmt = PIX_FMT_BGR24;
break;
case 32:
- avctx->pix_fmt = PIX_FMT_RGBA32;
+ avctx->pix_fmt = PIX_FMT_RGB32;
break;
default:
av_log(avctx, AV_LOG_ERROR, "Bit depth %i is not supported\n", s->bpp);
if(s->picture.data[0])
avctx->release_buffer(avctx, &s->picture);
- if(avcodec_check_dimensions(avctx, w, h))
+ if(av_image_check_size(w, h, 0, avctx))
return -1;
if(w != avctx->width || h != avctx->height)
avcodec_set_dimensions(avctx, w, h);
*pal++ = (b << 16) | (g << 8) | r;
}
p->palette_has_changed = 1;
- avctx->palctrl->palette_changed = 0;
}
}
if((compr & (~TGA_RLE)) == TGA_NODATA)
targa_decode_rle(avctx, s, buf, dst, avctx->width, avctx->height, stride, bpp);
else{
for(y = 0; y < s->height; y++){
-#ifdef WORDS_BIGENDIAN
+#if HAVE_BIGENDIAN
if((s->bpp + 1) >> 3 == 2){
uint16_t *dst16 = (uint16_t*)dst;
for(x = 0; x < s->width; x++)
return buf_size;
}
-static int targa_init(AVCodecContext *avctx){
+static av_cold int targa_init(AVCodecContext *avctx){
TargaContext *s = avctx->priv_data;
avcodec_get_frame_defaults((AVFrame*)&s->picture);
avctx->coded_frame= (AVFrame*)&s->picture;
- s->picture.data[0] = NULL;
return 0;
}
-static int targa_end(AVCodecContext *avctx){
+static av_cold int targa_end(AVCodecContext *avctx){
TargaContext *s = avctx->priv_data;
if(s->picture.data[0])
AVCodec targa_decoder = {
"targa",
- CODEC_TYPE_VIDEO,
+ AVMEDIA_TYPE_VIDEO,
CODEC_ID_TARGA,
sizeof(TargaContext),
targa_init,
NULL,
targa_end,
decode_frame,
- 0,
- NULL
+ CODEC_CAP_DR1,
+ NULL,
+ .long_name = NULL_IF_CONFIG_SMALL("Truevision Targa image"),
};