Mercurial > libavcodec.hg
comparison targaenc.c @ 4677:47237f2638b2 libavcodec
Move the encoding of the image data to its own function.
patch by Bobby Bingham, uhmmmm gmail com
author | diego |
---|---|
date | Sat, 17 Mar 2007 13:16:18 +0000 |
parents | 046456cf7d31 |
children | ae5abc4dc946 |
comparison
equal
deleted
inserted
replaced
4676:046456cf7d31 | 4677:47237f2638b2 |
---|---|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 * | 20 * |
21 */ | 21 */ |
22 #include "avcodec.h" | 22 #include "avcodec.h" |
23 | 23 |
24 static int targa_encode_normal(uint8_t *outbuf, AVFrame *pic, int bpp, int w, int h) | |
25 { | |
26 int i, n = bpp * w; | |
27 uint8_t *out = outbuf; | |
28 uint8_t *ptr = pic->data[0]; | |
29 | |
30 for(i=0; i < h; i++) { | |
31 memcpy(out, ptr, n); | |
32 out += n; | |
33 ptr += pic->linesize[0]; | |
34 } | |
35 | |
36 return out - outbuf; | |
37 } | |
38 | |
24 static int targa_encode_frame(AVCodecContext *avctx, | 39 static int targa_encode_frame(AVCodecContext *avctx, |
25 unsigned char *outbuf, | 40 unsigned char *outbuf, |
26 int buf_size, void *data){ | 41 int buf_size, void *data){ |
27 AVFrame *p = data; | 42 AVFrame *p = data; |
28 int i, n, linesize; | 43 int bpp; |
29 uint8_t *ptr, *out; | 44 uint8_t *out; |
30 | 45 |
31 if(avctx->width > 0xffff || avctx->height > 0xffff) { | 46 if(avctx->width > 0xffff || avctx->height > 0xffff) { |
32 av_log(avctx, AV_LOG_ERROR, "image dimensions too large\n"); | 47 av_log(avctx, AV_LOG_ERROR, "image dimensions too large\n"); |
33 return -1; | 48 return -1; |
34 } | 49 } |
49 /* TODO: support alpha channel and RLE */ | 64 /* TODO: support alpha channel and RLE */ |
50 switch(avctx->pix_fmt) { | 65 switch(avctx->pix_fmt) { |
51 case PIX_FMT_GRAY8: | 66 case PIX_FMT_GRAY8: |
52 outbuf[2] = 3; /* uncompressed grayscale image */ | 67 outbuf[2] = 3; /* uncompressed grayscale image */ |
53 outbuf[16] = 8; /* bpp */ | 68 outbuf[16] = 8; /* bpp */ |
54 n = avctx->width; | |
55 break; | 69 break; |
56 case PIX_FMT_RGB555: | 70 case PIX_FMT_RGB555: |
57 outbuf[2] = 2; /* uncompresses true-color image */ | 71 outbuf[2] = 2; /* uncompresses true-color image */ |
58 outbuf[16] = 16; /* bpp */ | 72 outbuf[16] = 16; /* bpp */ |
59 n = 2 * avctx->width; | |
60 break; | 73 break; |
61 case PIX_FMT_BGR24: | 74 case PIX_FMT_BGR24: |
62 outbuf[2] = 2; /* uncompressed true-color image */ | 75 outbuf[2] = 2; /* uncompressed true-color image */ |
63 outbuf[16] = 24; /* bpp */ | 76 outbuf[16] = 24; /* bpp */ |
64 n = 3 * avctx->width; | |
65 break; | 77 break; |
66 default: | 78 default: |
67 return -1; | 79 return -1; |
68 } | 80 } |
81 bpp = outbuf[16] >> 3; | |
69 | 82 |
70 out = outbuf + 18; /* skip past the header we just output */ | 83 out = outbuf + 18; /* skip past the header we just output */ |
71 ptr = p->data[0]; | |
72 linesize = p->linesize[0]; | |
73 | 84 |
74 for(i=0; i < avctx->height; i++) { | 85 out += targa_encode_normal(out, p, bpp, avctx->width, avctx->height); |
75 memcpy(out, ptr, n); | |
76 out += n; | |
77 ptr += linesize; | |
78 } | |
79 | 86 |
80 /* The standard recommends including this section, even if we don't use | 87 /* The standard recommends including this section, even if we don't use |
81 * any of the features it affords. TODO: take advantage of the pixel | 88 * any of the features it affords. TODO: take advantage of the pixel |
82 * aspect ratio and encoder ID fields available? */ | 89 * aspect ratio and encoder ID fields available? */ |
83 memcpy(out, "\0\0\0\0\0\0\0\0TRUEVISION-XFILE.", 26); | 90 memcpy(out, "\0\0\0\0\0\0\0\0TRUEVISION-XFILE.", 26); |