annotate libmpcodecs/vf_screenshot.c @ 16649:e1d6fbd607e0

Fix DVD audio and subtitle stream mapping, esp. for DVD with both 4:3 and 16:9 subtitles. Patch by Lehel Bernadt (lehel at pmc-services hu) with minor modifications.
author reimar
date Mon, 03 Oct 2005 14:29:01 +0000
parents 0a828abf1f0f
children debd99a161e0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
1 #include "../config.h"
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
2 #ifdef HAVE_PNG
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
3
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
4 #include <stdio.h>
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
5 #include <stdlib.h>
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
6 #ifdef HAVE_MALLOC_H
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
7 #include <malloc.h>
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
8 #endif
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
9 #include <string.h>
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
10 #include <inttypes.h>
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
11
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
12 #include <sys/types.h>
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
13 #include <sys/stat.h>
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
14 #include <unistd.h>
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
15
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
16 #include <png.h>
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
17
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
18 #include "../mp_msg.h"
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
19
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
20 #include "img_format.h"
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
21 #include "mp_image.h"
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
22 #include "vf.h"
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
23 #include "vf_scale.h"
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
24
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
25 #include "../libvo/fastmemcpy.h"
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
26 #include "../postproc/swscale.h"
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
27 #include "../postproc/rgb2rgb.h"
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
28
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
29 struct vf_priv_s {
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
30 int frameno;
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
31 char fname[102];
40222952440f DR and slice support
henry
parents: 16446
diff changeset
32 int shot, store_slices;
40222952440f DR and slice support
henry
parents: 16446
diff changeset
33 int dw, dh, stride;
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
34 uint8_t *buffer;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
35 struct SwsContext *ctx;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
36 };
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
37
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
38 //===========================================================================//
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
39
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
40 static int config(struct vf_instance_s* vf,
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
41 int width, int height, int d_width, int d_height,
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
42 unsigned int flags, unsigned int outfmt)
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
43 {
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
44 vf->priv->ctx=sws_getContextFromCmdLine(width, height, outfmt,
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
45 d_width, d_height, IMGFMT_BGR24);
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
46
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
47 vf->priv->dw = d_width;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
48 vf->priv->dh = d_height;
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
49 vf->priv->stride = (3*vf->priv->dw+15)&~15;
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
50
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
51 if (vf->priv->buffer) free(vf->priv->buffer); // probably reconfigured
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
52 vf->priv->buffer = NULL;
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
53
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
54 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
55 }
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
56
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
57 static int write_png(char *fname, unsigned char *buffer, int width, int height, int stride)
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
58 {
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
59 FILE * fp;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
60 png_structp png_ptr;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
61 png_infop info_ptr;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
62 png_byte **row_pointers;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
63 int k;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
64
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
65 png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
66 info_ptr = png_create_info_struct(png_ptr);
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
67 fp = NULL;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
68
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
69 if (setjmp(png_ptr->jmpbuf)) {
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
70 png_destroy_write_struct(&png_ptr, &info_ptr);
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
71 fclose(fp);
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
72 return 0;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
73 }
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
74
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
75 fp = fopen (fname, "wb");
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
76 if (fp == NULL) {
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
77 mp_msg(MSGT_VFILTER,MSGL_ERR,"\nPNG Error opening %s for writing!\n", fname);
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
78 return 0;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
79 }
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
80
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
81 png_init_io(png_ptr, fp);
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
82 png_set_compression_level(png_ptr, 0);
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
83
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
84 png_set_IHDR(png_ptr, info_ptr, width, height,
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
85 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
86 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
87
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
88 png_write_info(png_ptr, info_ptr);
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
89
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
90 png_set_bgr(png_ptr);
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
91
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
92 row_pointers = (png_byte**)malloc(height*sizeof(png_byte*));
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
93 for (k = 0; k < height; k++) {
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
94 unsigned char* s=buffer + stride*k;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
95 row_pointers[k] = s;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
96 }
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
97
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
98 png_write_image(png_ptr, row_pointers);
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
99 png_write_end(png_ptr, info_ptr);
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
100 png_destroy_write_struct(&png_ptr, &info_ptr);
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
101
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
102 free(row_pointers);
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
103
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
104 fclose (fp);
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
105 }
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
106
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
107 static int fexists(char *fname)
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
108 {
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
109 struct stat dummy;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
110 if (stat(fname, &dummy) == 0) return 1;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
111 else return 0;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
112 }
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
113
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
114 static void gen_fname(struct vf_priv_s* priv)
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
115 {
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
116 do {
40222952440f DR and slice support
henry
parents: 16446
diff changeset
117 snprintf (priv->fname, 100, "shot%04d.png", ++priv->frameno);
40222952440f DR and slice support
henry
parents: 16446
diff changeset
118 } while (fexists(priv->fname) && priv->frameno < 100000);
16457
5ab14fa7a019 do nothing if no free filenames are available
henry
parents: 16456
diff changeset
119 if (fexists(priv->fname)) {
5ab14fa7a019 do nothing if no free filenames are available
henry
parents: 16456
diff changeset
120 priv->fname[0] = '\0';
5ab14fa7a019 do nothing if no free filenames are available
henry
parents: 16456
diff changeset
121 return;
5ab14fa7a019 do nothing if no free filenames are available
henry
parents: 16456
diff changeset
122 }
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
123
40222952440f DR and slice support
henry
parents: 16446
diff changeset
124 mp_msg(MSGT_VFILTER,MSGL_INFO,"*** screenshot '%s' ***\n",priv->fname);
40222952440f DR and slice support
henry
parents: 16446
diff changeset
125
40222952440f DR and slice support
henry
parents: 16446
diff changeset
126 }
40222952440f DR and slice support
henry
parents: 16446
diff changeset
127
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
128 static void scale_image(struct vf_priv_s* priv, mp_image_t *mpi)
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
129 {
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
130 uint8_t *dst[3];
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
131 int dst_stride[3];
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
132
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
133 dst_stride[0] = priv->stride;
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
134 dst_stride[1] = dst_stride[2] = 0;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
135 if (!priv->buffer)
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
136 priv->buffer = (uint8_t*)memalign(16, dst_stride[0]*priv->dh);
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
137
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
138 dst[0] = priv->buffer;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
139 dst[1] = dst[2] = 0;
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
140 sws_scale_ordered(priv->ctx, mpi->planes, mpi->stride, 0, mpi->height, dst, dst_stride);
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
141 }
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
142
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
143 static void start_slice(struct vf_instance_s* vf, mp_image_t *mpi){
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
144 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
145 mpi->type, mpi->flags, mpi->width, mpi->height);
40222952440f DR and slice support
henry
parents: 16446
diff changeset
146 if (vf->priv->shot) {
40222952440f DR and slice support
henry
parents: 16446
diff changeset
147 vf->priv->store_slices = 1;
40222952440f DR and slice support
henry
parents: 16446
diff changeset
148 if (!vf->priv->buffer)
40222952440f DR and slice support
henry
parents: 16446
diff changeset
149 vf->priv->buffer = (uint8_t*)memalign(16, vf->priv->stride*vf->priv->dh);
40222952440f DR and slice support
henry
parents: 16446
diff changeset
150 }
40222952440f DR and slice support
henry
parents: 16446
diff changeset
151
40222952440f DR and slice support
henry
parents: 16446
diff changeset
152 }
40222952440f DR and slice support
henry
parents: 16446
diff changeset
153
40222952440f DR and slice support
henry
parents: 16446
diff changeset
154 static void draw_slice(struct vf_instance_s* vf,
40222952440f DR and slice support
henry
parents: 16446
diff changeset
155 unsigned char** src, int* stride, int w,int h, int x, int y){
40222952440f DR and slice support
henry
parents: 16446
diff changeset
156 if (vf->priv->store_slices) {
40222952440f DR and slice support
henry
parents: 16446
diff changeset
157 uint8_t *dst[3];
40222952440f DR and slice support
henry
parents: 16446
diff changeset
158 int dst_stride[3];
40222952440f DR and slice support
henry
parents: 16446
diff changeset
159 dst_stride[0] = vf->priv->stride;
40222952440f DR and slice support
henry
parents: 16446
diff changeset
160 dst_stride[1] = dst_stride[2] = 0;
40222952440f DR and slice support
henry
parents: 16446
diff changeset
161 dst[0] = vf->priv->buffer;
40222952440f DR and slice support
henry
parents: 16446
diff changeset
162 dst[1] = dst[2] = 0;
40222952440f DR and slice support
henry
parents: 16446
diff changeset
163 sws_scale_ordered(vf->priv->ctx, src, stride, y, h, dst, dst_stride);
40222952440f DR and slice support
henry
parents: 16446
diff changeset
164 }
40222952440f DR and slice support
henry
parents: 16446
diff changeset
165 vf_next_draw_slice(vf,src,stride,w,h,x,y);
40222952440f DR and slice support
henry
parents: 16446
diff changeset
166 }
40222952440f DR and slice support
henry
parents: 16446
diff changeset
167
40222952440f DR and slice support
henry
parents: 16446
diff changeset
168 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
169 // FIXME: should vf.c really call get_image when using slices??
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
170 if (mpi->flags & MP_IMGFLAG_DRAW_CALLBACK)
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
171 return;
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
172 vf->dmpi= vf_get_image(vf->next, mpi->imgfmt,
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
173 mpi->type, mpi->flags/* | MP_IMGFLAG_READABLE*/, mpi->width, mpi->height);
16456
34eb986b7e4a use slices if DR isn't available
henry
parents: 16452
diff changeset
174
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
175 mpi->planes[0]=vf->dmpi->planes[0];
40222952440f DR and slice support
henry
parents: 16446
diff changeset
176 mpi->stride[0]=vf->dmpi->stride[0];
40222952440f DR and slice support
henry
parents: 16446
diff changeset
177 if(mpi->flags&MP_IMGFLAG_PLANAR){
40222952440f DR and slice support
henry
parents: 16446
diff changeset
178 mpi->planes[1]=vf->dmpi->planes[1];
40222952440f DR and slice support
henry
parents: 16446
diff changeset
179 mpi->planes[2]=vf->dmpi->planes[2];
40222952440f DR and slice support
henry
parents: 16446
diff changeset
180 mpi->stride[1]=vf->dmpi->stride[1];
40222952440f DR and slice support
henry
parents: 16446
diff changeset
181 mpi->stride[2]=vf->dmpi->stride[2];
40222952440f DR and slice support
henry
parents: 16446
diff changeset
182 }
40222952440f DR and slice support
henry
parents: 16446
diff changeset
183 mpi->width=vf->dmpi->width;
40222952440f DR and slice support
henry
parents: 16446
diff changeset
184
40222952440f DR and slice support
henry
parents: 16446
diff changeset
185 mpi->flags|=MP_IMGFLAG_DIRECT;
40222952440f DR and slice support
henry
parents: 16446
diff changeset
186
40222952440f DR and slice support
henry
parents: 16446
diff changeset
187 mpi->priv=(void*)vf->dmpi;
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
188 }
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
189
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
190 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi)
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
191 {
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
192 mp_image_t *dmpi = (mp_image_t *)mpi->priv;
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
193
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
194 if (mpi->flags & MP_IMGFLAG_DRAW_CALLBACK)
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
195 dmpi = vf->dmpi;
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
196 else
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
197 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
198 dmpi=vf_get_image(vf->next,mpi->imgfmt,
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
199 MP_IMGTYPE_EXPORT, 0,
40222952440f DR and slice support
henry
parents: 16446
diff changeset
200 mpi->width, mpi->height);
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
201 vf_clone_mpi_attributes(dmpi, mpi);
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
202 dmpi->planes[0]=mpi->planes[0];
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
203 dmpi->planes[1]=mpi->planes[1];
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
204 dmpi->planes[2]=mpi->planes[2];
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
205 dmpi->stride[0]=mpi->stride[0];
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
206 dmpi->stride[1]=mpi->stride[1];
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
207 dmpi->stride[2]=mpi->stride[2];
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
208 dmpi->width=mpi->width;
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
209 dmpi->height=mpi->height;
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
210 }
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
211
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
212 if(vf->priv->shot) {
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
213 vf->priv->shot=0;
40222952440f DR and slice support
henry
parents: 16446
diff changeset
214 gen_fname(vf->priv);
16457
5ab14fa7a019 do nothing if no free filenames are available
henry
parents: 16456
diff changeset
215 if (vf->priv->fname[0]) {
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
216 if (!vf->priv->store_slices)
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
217 scale_image(vf->priv, dmpi);
16457
5ab14fa7a019 do nothing if no free filenames are available
henry
parents: 16456
diff changeset
218 write_png(vf->priv->fname, vf->priv->buffer, vf->priv->dw, vf->priv->dh, vf->priv->stride);
5ab14fa7a019 do nothing if no free filenames are available
henry
parents: 16456
diff changeset
219 }
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
220 vf->priv->store_slices = 0;
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
221 }
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
222
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
223 return vf_next_put_image(vf, dmpi);
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
224 }
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
225
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
226 int control (vf_instance_t *vf, int request, void *data)
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
227 {
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
228 if(request==VFCTRL_SCREENSHOT) {
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
229 vf->priv->shot=1;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
230 return CONTROL_TRUE;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
231 }
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
232 return vf_next_control (vf, request, data);
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
233 }
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
234
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
235
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
236 //===========================================================================//
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
237
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
238 static int query_format(struct vf_instance_s* vf, unsigned int fmt)
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
239 {
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
240 switch(fmt){
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
241 case IMGFMT_YV12:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
242 case IMGFMT_I420:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
243 case IMGFMT_IYUV:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
244 case IMGFMT_UYVY:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
245 case IMGFMT_YUY2:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
246 case IMGFMT_BGR32:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
247 case IMGFMT_BGR24:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
248 case IMGFMT_BGR16:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
249 case IMGFMT_BGR15:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
250 case IMGFMT_RGB32:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
251 case IMGFMT_RGB24:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
252 case IMGFMT_Y800:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
253 case IMGFMT_Y8:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
254 case IMGFMT_YVU9:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
255 case IMGFMT_IF09:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
256 case IMGFMT_444P:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
257 case IMGFMT_422P:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
258 case IMGFMT_411P:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
259 return vf_next_query_format(vf, fmt);
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
260 }
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
261 return 0;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
262 }
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
263
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
264 // open conflicts with stdio.h at least under MinGW
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
265 static int screenshot_open(vf_instance_t *vf, char* args)
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
266 {
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
267 vf->config=config;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
268 vf->control=control;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
269 vf->put_image=put_image;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
270 vf->query_format=query_format;
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
271 vf->start_slice=start_slice;
40222952440f DR and slice support
henry
parents: 16446
diff changeset
272 vf->draw_slice=draw_slice;
40222952440f DR and slice support
henry
parents: 16446
diff changeset
273 vf->get_image=get_image;
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
274 vf->priv=malloc(sizeof(struct vf_priv_s));
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
275 vf->priv->frameno=0;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
276 vf->priv->shot=0;
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
277 vf->priv->store_slices=0;
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
278 vf->priv->buffer=0;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
279 vf->priv->ctx=0;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
280 return 1;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
281 }
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
282
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
283 static void uninit(vf_instance_t *vf)
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
284 {
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
285 if(vf->priv->ctx) sws_freeContext(vf->priv->ctx);
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
286 if (vf->priv->buffer) free(vf->priv->buffer);
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
287 free(vf->priv);
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
288 }
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
289
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
290
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
291 vf_info_t vf_info_screenshot = {
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
292 "screenshot to file",
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
293 "screenshot",
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
294 "A'rpi, Jindrich Makovicka",
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
295 "",
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
296 screenshot_open,
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
297 NULL
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
298 };
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
299
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
300 //===========================================================================//
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
301
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
302 #endif /* HAVE_PNG */