hds Advocate
Joined: 21 Aug 2004 Posts: 2629 Location: Sprockhoevel [GER]
|
Posted: Tue Aug 24, 2004 9:14 pm Post subject: mplayer screencapture patch |
|
|
hi,
short question:
does the mplayer in portage have the screencapture patch included? if not - could it be implemented? i am using it fine in 1.0pre4 since weeks.
Code: |
diff -ruw MPlayer-1.0pre3/libvo/vo_jpeg.c MPlayer-1.0pre3.screenshotext/libvo/vo_jpeg.c
--- MPlayer-1.0pre3/libvo/vo_jpeg.c 2003-04-26 05:37:26.000000000 +0900
+++ MPlayer-1.0pre3.screenshotext/libvo/vo_jpeg.c 2004-02-16 03:54:10.000000000 +0900
@@ -47,7 +47,7 @@
return 0;
}
-static uint32_t jpeg_write( uint8_t * name,uint8_t * buffer )
+static uint32_t jpeg_write( uint8_t * name,uint8_t * buffer,uint32_t w,uint32_t h )
{
FILE * o;
struct jpeg_compress_struct cinfo;
@@ -62,8 +62,8 @@
jpeg_create_compress(&cinfo);
jpeg_stdio_dest( &cinfo,o );
- cinfo.image_width=image_width;
- cinfo.image_height=image_height;
+ cinfo.image_width=w;
+ cinfo.image_height=h;
cinfo.input_components=3;
cinfo.in_color_space=JCS_RGB;
@@ -75,7 +75,7 @@
if ( jpeg_progressive_mode ) jpeg_simple_progression( &cinfo );
jpeg_start_compress( &cinfo,TRUE );
- row_stride = image_width * 3;
+ row_stride = w * 3;
while ( cinfo.next_scanline < cinfo.image_height )
{
row_pointer[0]=&buffer[ cinfo.next_scanline * row_stride ];
@@ -96,7 +96,7 @@
snprintf (buf, 256, "%s/%08d.jpg", jpeg_outdir, ++framenum);
- return jpeg_write( buf,src[0] );
+ return jpeg_write( buf,src[0],image_width,image_height );
}
static void draw_osd(void)
@@ -142,3 +142,7 @@
}
return VO_NOTIMPL;
}
+
+void vo_screenshot_jpeg(char *ofilename,uint8_t *src,uint32_t w,uint32_t h){
+ jpeg_write(ofilename,src,w,h);
+}
diff -ruw MPlayer-1.0pre3/libvo/vo_png.c MPlayer-1.0pre3.screenshotext/libvo/vo_png.c
--- MPlayer-1.0pre3/libvo/vo_png.c 2002-11-12 00:20:26.000000000 +0900
+++ MPlayer-1.0pre3.screenshotext/libvo/vo_png.c 2004-02-16 03:54:10.000000000 +0900
@@ -226,3 +226,24 @@
}
return VO_NOTIMPL;
}
+
+void vo_screenshot_png(char *ofilename,uint8_t *src,uint32_t w,uint32_t h){
+ int k;
+ struct pngdata png;
+ png_byte *row_pointers[h];
+
+ png = create_png(ofilename,w,h,0);
+
+ if(png.status){
+ printf("PNG Error in create_png\n");
+ exit(0);
+ }
+
+ if(verbose > 1) printf("PNG Creating Row Pointers\n");
+ for ( k = 0; k < h; k++ )
+ row_pointers[k] = src+3*w*k;
+
+ if(verbose > 1) printf("PNG Writing Image Data\n");
+ png_write_image(png.png_ptr, row_pointers);
+ destroy_png(png);
+}
diff -ruw MPlayer-1.0pre3/libvo/vo_x11.c MPlayer-1.0pre3.screenshotext/libvo/vo_x11.c
--- MPlayer-1.0pre3/libvo/vo_x11.c 2003-12-01 01:36:10.000000000 +0900
+++ MPlayer-1.0pre3.screenshotext/libvo/vo_x11.c 2004-02-16 03:54:10.000000000 +0900
@@ -89,7 +89,6 @@
static void check_events(){
int ret = vo_x11_check_events(mDisplay);
-
/* clear left over borders and redraw frame if we are paused */
if ( ret & VO_EVENT_EXPOSE && int_pause)
{
@@ -663,6 +662,9 @@
case VOCTRL_ONTOP:
vo_x11_ontop();
return VO_TRUE;
+ case VOCTRL_SCREENSHOT:
+ vo_x11_screenshot(myximage);
+ return VO_TRUE;
case VOCTRL_FULLSCREEN:
{
vo_x11_fullscreen();
diff -ruw MPlayer-1.0pre3/libvo/vo_xv.c MPlayer-1.0pre3.screenshotext/libvo/vo_xv.c
--- MPlayer-1.0pre3/libvo/vo_xv.c 2003-12-01 01:36:10.000000000 +0900
+++ MPlayer-1.0pre3.screenshotext/libvo/vo_xv.c 2004-02-16 03:54:10.000000000 +0900
@@ -32,6 +32,11 @@
#include "x11_common.h"
+#include "../postproc/swscale.h"
+#include "../postproc/swscale_internal.h" //FIXME
+#include "../postproc/rgb2rgb.h"
+#include "../libmpcodecs/vf_scale.h"
+
#include "fastmemcpy.h"
#include "sub.h"
#include "aspect.h"
@@ -40,6 +45,18 @@
#include "../Gui/interface.h"
#endif
+#include <sys/time.h>
+#include <time.h>
+
+#ifdef HAVE_GD
+#include <gd.h>
+#elif defined(HAVE_PNG)
+#include <png.h>
+#elif defined(HAVE_JPEG)
+#include <jpeglib.h>
+#elif defined(HAVE_GIF)
+#endif
+
static vo_info_t info =
{
"X11/Xv",
@@ -92,6 +109,15 @@
static void (*draw_alpha_fnc)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride);
+static void vo_xv_screenshot(void);
+#ifdef HAVE_GD
+void vo_screenshot_gd(char *,uint8_t *,uint32_t,uint32_t);
+#elif defined(HAVE_PNG)
+extern void vo_screenshot_png(char *,uint8_t *,uint32_t,uint32_t);
+#elif defined(HAVE_JPEG)
+extern void vo_screenshot_jpeg(char *,uint8_t *,uint32_t,uint32_t);
+#endif
+
static void draw_alpha_yv12(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){
x0+=image_width*(vo_panscan_x>>1)/(vo_dwidth+vo_panscan_x);
vo_draw_alpha_yv12(w,h,src,srca,stride,
@@ -755,6 +781,58 @@
case VOCTRL_ONTOP:
vo_x11_ontop();
return VO_TRUE;
+ case VOCTRL_SCREENSHOT:
+ vo_xv_screenshot();
+ return VO_TRUE;
}
return VO_NOTIMPL;
}
+
+static void convert_image_format(uint8_t *dst[],long w,long h){
+ int dststride[3];
+ uint8_t *src[3];
+ int srcstride[3];
+ SwsContext *swsContext=NULL;
+
+ srcstride[0]=xvimage[current_buf]->pitches[0];
+ srcstride[1]=xvimage[current_buf]->pitches[1];
+ srcstride[2]=xvimage[current_buf]->pitches[2];
+ dststride[0]=3*w;
+ dststride[1]=0;
+ dststride[2]=0;
+ src[0]=xvimage[current_buf]->data+xvimage[current_buf]->offsets[0];
+ src[1]=xvimage[current_buf]->data+xvimage[current_buf]->offsets[1];
+ src[2]=xvimage[current_buf]->data+xvimage[current_buf]->offsets[2];
+ dst[0]=(uint8_t *)malloc(sizeof(uint8_t)*w*h*3);
+ dst[1]=NULL;
+ dst[2]=NULL;
+
+ swsContext=sws_getContext(w,h,xv_format,w,h,IMGFMT_RGB24,2,NULL,NULL);
+ sws_scale(swsContext,src,srcstride,0,h,dst,dststride);
+ sws_freeContext(swsContext);
+}
+
+static void vo_xv_screenshot(){
+ char ofilename[256];
+ struct timeval curtime;
+ struct timezone tzp;
+ uint8_t *src[3];
+ long w,h;
+
+ w=xvimage[current_buf]->width;
+ h=xvimage[current_buf]->height;
+
+ gettimeofday (&curtime, &tzp);
+ convert_image_format(src,w,h);
+#ifdef HAVE_GD
+ snprintf(ofilename,256,"mplayer-%d%010d.png",curtime.tv_sec,curtime.tv_usec);
+ vo_x11_screenshot_gd(ofilename,src[0],w,h);
+#elif defined(HAVE_PNG)
+ snprintf(ofilename,256,"mplayer-%d%010d.png",curtime.tv_sec,curtime.tv_usec);
+ vo_screenshot_png(ofilename,src[0],w,h);
+#elif defined(HAVE_JPEG)
+ snprintf(ofilename,256,"mplayer-%d%010d.jpg",curtime.tv_sec,curtime.tv_usec);
+ vo_screenshot_jpeg(ofilename,src[0],w,h);
+#endif
+ free(src[0]);
+}
diff -ruw MPlayer-1.0pre3/libvo/x11_common.c MPlayer-1.0pre3.screenshotext/libvo/x11_common.c
--- MPlayer-1.0pre3/libvo/x11_common.c 2003-12-08 21:03:03.000000000 +0900
+++ MPlayer-1.0pre3.screenshotext/libvo/x11_common.c 2004-02-16 03:54:10.000000000 +0900
@@ -50,6 +50,18 @@
#include "../mplayer.h"
#endif
+#include <sys/time.h>
+#include <time.h>
+
+#ifdef HAVE_GD
+#include <gd.h>
+#elif defined(HAVE_PNG)
+#include <png.h>
+#elif defined(HAVE_JPEG)
+#include <jpeglib.h>
+#elif defined(HAVE_GIF)
+#endif
+
#define WIN_LAYER_ONBOTTOM 2
#define WIN_LAYER_NORMAL 4
#define WIN_LAYER_ONTOP 6
@@ -901,6 +913,68 @@
XFlush(mDisplay);
}
+#ifdef HAVE_GD
+void vo_x11_screenshot_gd(char *ofilename,uint8_t *src,uint32_t w,uint32_t h)
+{
+ FILE *ofile;
+ long i,j;
+ gdImagePtr im;
+ int color;
+
+ im = gdImageCreateTrueColor(w,h);
+ for(i=0;i<h;i++){
+ for(j=0;j<w;j++){
+ color=gdImageColorResolve(im,
+ *(src+i*w*3+j*3),
+ *(src+i*w*3+j*3+1),
+ *(src+i*w*3+j*3+2));
+ gdImageSetPixel(im,j,i,color);
+ }
+ }
+ ofile=fopen(ofilename,"w");
+ gdImagePng ( im, ofile );
+ gdImageDestroy ( im );
+ fclose(ofile);
+}
+#endif
+
+void vo_x11_screenshot( XImage *myximage )
+{
+ char ofilename[256];
+ struct timeval curtime;
+ struct timezone tzp;
+ uint32_t buf;
+ long w,h,i,j;
+ uint8_t *src;
+
+ w=myximage->width;
+ h=myximage->height;
+
+ src=(uint8_t *)malloc(sizeof(uint8_t)*w*h*3);
+
+ gettimeofday (&curtime, &tzp);
+
+ for(i=0;i<h;i++){
+ for(j=0;j<w;j++){
+ buf=XGetPixel(myximage,j,i);
+ *(src+i*w*3+j*3)=(buf&myximage->red_mask)>>16;
+ *(src+i*w*3+j*3+1)=(buf&myximage->green_mask)>>8;
+ *(src+i*w*3+j*3+2)=buf&myximage->blue_mask;
+ }
+ }
+
+#ifdef HAVE_GD
+ snprintf(ofilename,256,"mplayer-%d%010d.png",curtime.tv_sec,curtime.tv_usec);
+ vo_x11_screenshot_gd(ofilename,src,w,h);
+#elif defined(HAVE_PNG)
+ snprintf(ofilename,256,"mplayer-%d%010d.png",curtime.tv_sec,curtime.tv_usec);
+ vo_screenshot_png(ofilename,src,w,h);
+#elif defined(HAVE_JPEG)
+ snprintf(ofilename,256,"mplayer-%d%010d.jpg",curtime.tv_sec,curtime.tv_usec);
+ vo_screenshot_jpeg(ofilename,src,w,h);
+#endif
+ free(src);
+}
void vo_x11_setlayer( Display * mDisplay,Window vo_window,int layer )
{
diff -ruw MPlayer-1.0pre3/libvo/x11_common.h MPlayer-1.0pre3.screenshotext/libvo/x11_common.h
--- MPlayer-1.0pre3/libvo/x11_common.h 2003-12-01 01:36:10.000000000 +0900
+++ MPlayer-1.0pre3.screenshotext/libvo/x11_common.h 2004-02-16 03:54:12.000000000 +0900
@@ -63,8 +63,11 @@
extern void vo_x11_clearwindow( Display *mDisplay, Window vo_window );
extern void vo_x11_ontop();
+
#endif
+extern void vo_x11_screenshot( XImage *myximage );
+
extern Window vo_window;
extern GC vo_gc;
extern XSizeHints vo_hint;
@@ -95,3 +98,6 @@
#endif
+#ifdef HAVE_GD
+extern void vo_x11_screenshot_gd(char *,uint8_t *,uint32_t,uint32_t);
+#endif
|
|
|