annotate jpeg.c @ 656:0d700094e887 libavformat

wmv3
author michael
date Sun, 23 Jan 2005 21:54:07 +0000
parents 5cb0e4cdb864
children 66cc656ea404
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
2 * JPEG image format
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
3 * Copyright (c) 2003 Fabrice Bellard.
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
18 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
19 #include "avformat.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
21 static int jpeg_probe(AVProbeData *pd)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22 {
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
23 if (pd->buf_size >= 64 &&
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
24 pd->buf[0] == 0xff && pd->buf[1] == 0xd8 && pd->buf[2] == 0xff)
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
25 return AVPROBE_SCORE_MAX;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
26 else
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
27 return 0;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
30 typedef struct JpegOpaque {
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
31 int (*alloc_cb)(void *opaque, AVImageInfo *info);
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
32 void *opaque;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
33 int ret_code;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
34 } JpegOpaque;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
35
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
36 /* called by the codec to allocate the image */
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
37 static int jpeg_get_buffer(AVCodecContext *c, AVFrame *picture)
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
38 {
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
39 JpegOpaque *jctx = c->opaque;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
40 AVImageInfo info1, *info = &info1;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
41 int ret, i;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
43 info->width = c->width;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
44 info->height = c->height;
114
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
45 switch(c->pix_fmt) {
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
46 case PIX_FMT_YUV420P:
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
47 info->pix_fmt = PIX_FMT_YUVJ420P;
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
48 break;
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
49 case PIX_FMT_YUV422P:
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
50 info->pix_fmt = PIX_FMT_YUVJ422P;
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
51 break;
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
52 case PIX_FMT_YUV444P:
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
53 info->pix_fmt = PIX_FMT_YUVJ444P;
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
54 break;
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
55 default:
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
56 return -1;
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
57 }
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
58 ret = jctx->alloc_cb(jctx->opaque, info);
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
59 if (ret) {
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
60 jctx->ret_code = ret;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
61 return -1;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
62 } else {
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
63 for(i=0;i<3;i++) {
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
64 picture->data[i] = info->pict.data[i];
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
65 picture->linesize[i] = info->pict.linesize[i];
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
66 }
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
67 return 0;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
68 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70
321
5cb0e4cdb864 - Add reget_buffer() function to AVCodecContext
rtognimp
parents: 215
diff changeset
71 static void jpeg_img_copy(uint8_t *dst, int dst_wrap,
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 48
diff changeset
72 uint8_t *src, int src_wrap,
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
73 int width, int height)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74 {
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
75 for(;height > 0; height--) {
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
76 memcpy(dst, src, width);
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
77 dst += dst_wrap;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
78 src += src_wrap;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
79 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
82 /* XXX: libavcodec is broken for truncated jpegs! */
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
83 #define IO_BUF_SIZE (1024*1024)
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
84
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
85 static int jpeg_read(ByteIOContext *f,
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
86 int (*alloc_cb)(void *opaque, AVImageInfo *info), void *opaque)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87 {
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
88 AVCodecContext *c;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
89 AVFrame *picture, picture1;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
90 int len, size, got_picture, i;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
91 uint8_t *inbuf_ptr, inbuf[IO_BUF_SIZE];
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
92 JpegOpaque jctx;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
94 jctx.alloc_cb = alloc_cb;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
95 jctx.opaque = opaque;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
96 jctx.ret_code = -1; /* default return code is error */
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
97
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
98 c = avcodec_alloc_context();
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
99 if (!c)
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
100 return -1;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
101 picture= avcodec_alloc_frame();
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
102 if (!picture) {
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
103 av_free(c);
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
104 return -1;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
105 }
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
106 c->opaque = &jctx;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
107 c->get_buffer = jpeg_get_buffer;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
108 c->flags |= CODEC_FLAG_TRUNCATED; /* we dont send complete frames */
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
109 if (avcodec_open(c, &mjpeg_decoder) < 0)
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
110 goto fail1;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
111 for(;;) {
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
112 size = get_buffer(f, inbuf, sizeof(inbuf));
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
113 if (size == 0)
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
114 break;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
115 inbuf_ptr = inbuf;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
116 while (size > 0) {
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
117 len = avcodec_decode_video(c, &picture1, &got_picture,
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
118 inbuf_ptr, size);
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
119 if (len < 0)
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
120 goto fail;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
121 if (got_picture)
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
122 goto the_end;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
123 size -= len;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
124 inbuf_ptr += len;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
125 }
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
126 }
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
127 the_end:
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
128 /* XXX: currently, the mjpeg decoder does not use AVFrame, so we
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
129 must do it by hand */
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
130 if (jpeg_get_buffer(c, picture) < 0)
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
131 goto fail;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
132 for(i=0;i<3;i++) {
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
133 int w, h;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
134 w = c->width;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
135 h = c->height;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
136 if (i >= 1) {
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
137 switch(c->pix_fmt) {
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
138 default:
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
139 case PIX_FMT_YUV420P:
48
e308ea014922 fixed copy
bellard
parents: 47
diff changeset
140 w = (w + 1) >> 1;
e308ea014922 fixed copy
bellard
parents: 47
diff changeset
141 h = (h + 1) >> 1;
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
142 break;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
143 case PIX_FMT_YUV422P:
48
e308ea014922 fixed copy
bellard
parents: 47
diff changeset
144 w = (w + 1) >> 1;
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
145 break;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
146 case PIX_FMT_YUV444P:
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
147 break;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
148 }
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
149 }
321
5cb0e4cdb864 - Add reget_buffer() function to AVCodecContext
rtognimp
parents: 215
diff changeset
150 jpeg_img_copy(picture->data[i], picture->linesize[i],
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
151 picture1.data[i], picture1.linesize[i],
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
152 w, h);
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
153 }
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
154 jctx.ret_code = 0;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
155 fail:
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
156 avcodec_close(c);
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
157 fail1:
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
158 av_free(picture);
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
159 av_free(c);
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
160 return jctx.ret_code;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
161 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
162
215
99f4032097e0 Compile fix when no CONFIG_ENCODERS by (Glenn Maynard <g_sf at zewt dot org>)
michaelni
parents: 114
diff changeset
163 #ifdef CONFIG_ENCODERS
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
164 static int jpeg_write(ByteIOContext *pb, AVImageInfo *info)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
165 {
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
166 AVCodecContext *c;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
167 uint8_t *outbuf = NULL;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
168 int outbuf_size, ret, size, i;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
169 AVFrame *picture;
5
39c4c4336486 cleanup
michaelni
parents: 0
diff changeset
170
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
171 ret = -1;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
172 c = avcodec_alloc_context();
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
173 if (!c)
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
174 return -1;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
175 picture = avcodec_alloc_frame();
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
176 if (!picture)
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
177 goto fail2;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
178 c->width = info->width;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
179 c->height = info->height;
114
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
180 /* XXX: currently move that to the codec ? */
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
181 switch(info->pix_fmt) {
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
182 case PIX_FMT_YUVJ420P:
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
183 c->pix_fmt = PIX_FMT_YUV420P;
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
184 break;
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
185 case PIX_FMT_YUVJ422P:
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
186 c->pix_fmt = PIX_FMT_YUV422P;
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
187 break;
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
188 case PIX_FMT_YUVJ444P:
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
189 c->pix_fmt = PIX_FMT_YUV444P;
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
190 break;
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
191 default:
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
192 goto fail1;
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
193 }
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
194 for(i=0;i<3;i++) {
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
195 picture->data[i] = info->pict.data[i];
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
196 picture->linesize[i] = info->pict.linesize[i];
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
197 }
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
198 /* set the quality */
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
199 picture->quality = 3; /* XXX: a parameter should be used */
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
200 c->flags |= CODEC_FLAG_QSCALE;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
201
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
202 if (avcodec_open(c, &mjpeg_encoder) < 0)
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
203 goto fail1;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
204
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
205 /* XXX: needs to sort out that size problem */
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
206 outbuf_size = 1000000;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
207 outbuf = av_malloc(outbuf_size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
209 size = avcodec_encode_video(c, outbuf, outbuf_size, picture);
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
210 if (size < 0)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
211 goto fail;
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
212 put_buffer(pb, outbuf, size);
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
213 put_flush_packet(pb);
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
214 ret = 0;
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
215
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216 fail:
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
217 avcodec_close(c);
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
218 av_free(outbuf);
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
219 fail1:
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
220 av_free(picture);
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
221 fail2:
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
222 av_free(c);
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
223 return ret;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224 }
215
99f4032097e0 Compile fix when no CONFIG_ENCODERS by (Glenn Maynard <g_sf at zewt dot org>)
michaelni
parents: 114
diff changeset
225 #endif //CONFIG_ENCODERS
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
227 AVImageFormat jpeg_image_format = {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228 "jpeg",
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
229 "jpg,jpeg",
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
230 jpeg_probe,
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
231 jpeg_read,
114
3a17db1515e4 use correct YUV format for JPEG
bellard
parents: 65
diff changeset
232 (1 << PIX_FMT_YUVJ420P) | (1 << PIX_FMT_YUVJ422P) | (1 << PIX_FMT_YUVJ444P),
215
99f4032097e0 Compile fix when no CONFIG_ENCODERS by (Glenn Maynard <g_sf at zewt dot org>)
michaelni
parents: 114
diff changeset
233 #ifdef CONFIG_ENCODERS
47
45308962220f added jpeg image encoder and decoder (new YUV handling routines and mjpeg codec fixes are necessary to go further)
bellard
parents: 5
diff changeset
234 jpeg_write,
215
99f4032097e0 Compile fix when no CONFIG_ENCODERS by (Glenn Maynard <g_sf at zewt dot org>)
michaelni
parents: 114
diff changeset
235 #else
99f4032097e0 Compile fix when no CONFIG_ENCODERS by (Glenn Maynard <g_sf at zewt dot org>)
michaelni
parents: 114
diff changeset
236 NULL,
99f4032097e0 Compile fix when no CONFIG_ENCODERS by (Glenn Maynard <g_sf at zewt dot org>)
michaelni
parents: 114
diff changeset
237 #endif //CONFIG_ENCODERS
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
238 };