comparison libvo/vo_jpeg.c @ 9989:98791b90215a

Spring cleanup: supporting only RGB24 as input (native jpeg lib supports only that, maybe we could later add nativ YCbCr (YUV) support, but not swscale ones)
author alex
date Fri, 25 Apr 2003 20:37:26 +0000
parents 555d64fc02b8
children db49cdedb88d
comparison
equal deleted inserted replaced
9988:a32fb6812221 9989:98791b90215a
1 #define DISP
2
3 /* 1 /*
4 * vo_jpeg.c, JPEG Renderer for Mplayer 2 * vo_jpeg.c, JPEG Renderer for Mplayer
5 * 3 *
6 * Copyright 2002 by Pontscho (pontscho@makacs.poliod.hu) 4 * Copyright 2002 by Pontscho (pontscho@makacs.poliod.hu)
5 * 25/04/2003: Spring cleanup -- alex
7 * 6 *
8 */ 7 */
9 8
10 #include <stdio.h> 9 #include <stdio.h>
11 #include <stdlib.h> 10 #include <stdlib.h>
15 #include <jpeglib.h> 14 #include <jpeglib.h>
16 15
17 #include "config.h" 16 #include "config.h"
18 #include "video_out.h" 17 #include "video_out.h"
19 #include "video_out_internal.h" 18 #include "video_out_internal.h"
20 #include "sub.h"
21
22 #include "../postproc/swscale.h"
23 #include "../postproc/rgb2rgb.h"
24 19
25 static vo_info_t info= 20 static vo_info_t info=
26 { 21 {
27 "JPEG file", 22 "JPEG file",
28 "jpeg", 23 "jpeg",
30 "" 25 ""
31 }; 26 };
32 27
33 LIBVO_EXTERN (jpeg) 28 LIBVO_EXTERN (jpeg)
34 29
35 #define RGB 0
36 #define BGR 1
37
38 extern int verbose;
39 static int image_width; 30 static int image_width;
40 static int image_height; 31 static int image_height;
41 static int image_format;
42 static uint8_t *image_data=NULL;
43 static unsigned int scale_srcW=0, scale_srcH=0;
44 32
45 int jpeg_baseline = 1; 33 int jpeg_baseline = 1;
46 int jpeg_progressive_mode = 0; 34 int jpeg_progressive_mode = 0;
47 int jpeg_optimize = 100; 35 int jpeg_optimize = 100;
48 int jpeg_smooth = 0; 36 int jpeg_smooth = 0;
49 int jpeg_quality = 75; 37 int jpeg_quality = 75;
50 char * jpeg_outdir = "."; 38 char * jpeg_outdir = ".";
51 39
52 #define bpp 24
53
54 static int cspace=RGB;
55 static int framenum=0; 40 static int framenum=0;
56
57 static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)
58 {
59 vo_draw_alpha_rgb24(w, h, src, srca, stride, image_data + 3 * (y0 * image_width + x0), 3 * image_width);
60 }
61 41
62 static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format) 42 static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format)
63 { 43 {
64 if ( fullscreen&0x04 && ( width != d_width || height != d_height )&&( ( format == IMGFMT_YV12 ) ) )
65 {
66 // software scaling
67 image_width=(d_width + 7) & ~7;
68 image_height=d_height;
69 scale_srcW=width;
70 scale_srcH=height;
71 SwScale_Init();
72 }
73 else
74 {
75 image_height=height; 44 image_height=height;
76 image_width=width; 45 image_width=width;
77 }
78
79 image_format=format;
80 switch(format)
81 {
82 case IMGFMT_BGR32:
83 cspace=BGR;
84 image_data=malloc( image_width * image_height * 3 );
85 break;
86 case IMGFMT_BGR24:
87 cspace=BGR;
88 image_data=malloc( image_width * image_height * 3 );
89 break;
90 case IMGFMT_RGB24:
91 cspace=RGB;
92 break;
93 case IMGFMT_IYUV:
94 case IMGFMT_I420:
95 case IMGFMT_YV12:
96 cspace=BGR;
97 yuv2rgb_init( bpp,MODE_BGR );
98 image_data=malloc( image_width * image_height * 3 );
99 break;
100 default:
101 return 1;
102 }
103 46
104 return 0; 47 return 0;
105 } 48 }
106 49
107 static uint32_t jpeg_write( uint8_t * name,uint8_t * buffer ) 50 static uint32_t jpeg_write( uint8_t * name,uint8_t * buffer )
117 60
118 cinfo.err=jpeg_std_error(&jerr); 61 cinfo.err=jpeg_std_error(&jerr);
119 jpeg_create_compress(&cinfo); 62 jpeg_create_compress(&cinfo);
120 jpeg_stdio_dest( &cinfo,o ); 63 jpeg_stdio_dest( &cinfo,o );
121 64
122
123 cinfo.image_width=image_width; 65 cinfo.image_width=image_width;
124 cinfo.image_height=image_height; 66 cinfo.image_height=image_height;
125 cinfo.input_components=bpp / 8; 67 cinfo.input_components=3;
126 cinfo.in_color_space=JCS_RGB; 68 cinfo.in_color_space=JCS_RGB;
127 69
128 jpeg_set_defaults( &cinfo ); 70 jpeg_set_defaults( &cinfo );
129 jpeg_set_quality( &cinfo,jpeg_quality,jpeg_baseline ); 71 jpeg_set_quality( &cinfo,jpeg_quality,jpeg_baseline );
130 cinfo.optimize_coding=jpeg_optimize; 72 cinfo.optimize_coding=jpeg_optimize;
131 cinfo.smoothing_factor=jpeg_smooth; 73 cinfo.smoothing_factor=jpeg_smooth;
132 74
133 if ( jpeg_progressive_mode ) jpeg_simple_progression( &cinfo ); 75 if ( jpeg_progressive_mode ) jpeg_simple_progression( &cinfo );
134 jpeg_start_compress( &cinfo,TRUE ); 76 jpeg_start_compress( &cinfo,TRUE );
135 77
136 row_stride = image_width * ( bpp / 8 ); 78 row_stride = image_width * 3;
137 while ( cinfo.next_scanline < cinfo.image_height ) 79 while ( cinfo.next_scanline < cinfo.image_height )
138 { 80 {
139 row_pointer[0]=&buffer[ cinfo.next_scanline * row_stride ]; 81 row_pointer[0]=&buffer[ cinfo.next_scanline * row_stride ];
140 (void)jpeg_write_scanlines( &cinfo,row_pointer,1 ); 82 (void)jpeg_write_scanlines( &cinfo,row_pointer,1 );
141 } 83 }
152 char buf[256]; 94 char buf[256];
153 uint8_t *dst= src[0]; 95 uint8_t *dst= src[0];
154 96
155 snprintf (buf, 256, "%s/%08d.jpg", jpeg_outdir, ++framenum); 97 snprintf (buf, 256, "%s/%08d.jpg", jpeg_outdir, ++framenum);
156 98
157 if ( image_format == IMGFMT_BGR32 ) 99 return jpeg_write( buf,src[0] );
158 {
159 rgb32to24( src[0],image_data,image_width * image_height * 4 );
160 rgb24tobgr24( image_data,image_data,image_width * image_height * 3 );
161 dst=image_data;
162 }
163 if ( image_format == IMGFMT_BGR24 )
164 {
165 rgb24tobgr24( src[0],image_data,image_width * image_height * 3 );
166 dst=image_data;
167 }
168 return jpeg_write( buf,dst );
169 } 100 }
170 101
171 static void draw_osd(void) 102 static void draw_osd(void)
172 { 103 {
173 vo_draw_text(image_width, image_height, draw_alpha);
174 } 104 }
175 105
176 static void flip_page (void) 106 static void flip_page (void)
177 { 107 {
178 char buf[256];
179
180 if((image_format == IMGFMT_YV12) || (image_format == IMGFMT_IYUV) || (image_format == IMGFMT_I420))
181 {
182 snprintf (buf, 256, "%s/%08d.jpg", jpeg_outdir, ++framenum);
183 jpeg_write( buf,image_data );
184 }
185 } 108 }
186 109
187 static uint32_t draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y ) 110 static uint32_t draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y )
188 { 111 {
189 if (scale_srcW)
190 {
191 uint8_t *dst[3]={image_data, NULL, NULL};
192 SwScale_YV12slice(src,stride,y,h,
193 dst, image_width*((bpp+7)/8), bpp,
194 scale_srcW, scale_srcH, image_width, image_height);
195 }
196 else
197 {
198 uint8_t *dst=image_data + (image_width * y + x) * (bpp/8);
199 yuv2rgb(dst,src[0],src[1],src[2],w,h,image_width*(bpp/8),stride[0],stride[1]);
200 }
201 return 0; 112 return 0;
202 } 113 }
203 114
204 static uint32_t query_format(uint32_t format) 115 static uint32_t query_format(uint32_t format)
205 { 116 {
206 switch( format ) 117 if (format == IMGFMT_RGB24)
207 { 118 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW;
208 case IMGFMT_IYUV: 119
209 case IMGFMT_I420: 120 return 0;
210 case IMGFMT_YV12:
211 case IMGFMT_BGR|24:
212 case IMGFMT_BGR|32:
213 return VFCAP_CSP_SUPPORTED;
214 case IMGFMT_RGB|24:
215 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_OSD;
216 }
217 return 0;
218 } 121 }
219 122
220 static void uninit(void) 123 static void uninit(void)
221 { 124 {
222 if ( image_data )
223 {
224 free( image_data );
225 image_data=NULL;
226 }
227 } 125 }
228 126
229 static void check_events(void) 127 static void check_events(void)
230 { 128 {
231 } 129 }
232 130
233 static uint32_t preinit(const char *arg) 131 static uint32_t preinit(const char *arg)
234 { 132 {
235 if(arg)
236 {
237 printf("JPEG Unknown subdevice: %s\n",arg);
238 return ENOSYS;
239 }
240 return 0; 133 return 0;
241 } 134 }
242 135
243 static uint32_t control(uint32_t request, void *data, ...) 136 static uint32_t control(uint32_t request, void *data, ...)
244 { 137 {