[Mplayer-cvslog] CVS: main/TOOLS/mwallp README,NONE,1.1 compile.sh,NONE,1.1 jpeg.c,NONE,1.1 mwallp.c,NONE,1.1
Arpi of Ize
arpi at mplayerhq.hu
Mon Jun 17 16:13:14 CEST 2002
Update of /cvsroot/mplayer/main/TOOLS/mwallp
In directory mail:/var/tmp.root/cvs-serv31204
Added Files:
README compile.sh jpeg.c mwallp.c
Log Message:
mwallp - simple wallpaper setting tool using MPlayer codebase
--- NEW FILE ---
mwallp - mplayer's wallpaper setting utility
======
Usage: mwallp file1.jpg [file2.jpg file3.jpg ...]
~~~~~
About:
~~~~~
MWallp is a simple tool to set .jpg images as background/wallpaper on the
desktop. It scales (bicubic) and convert the given jpg image to desktop
size/bpp and set as background of Root window.
If more than 1 filenames given, it randomly selects one, so running something
like 'mwallp ~/.wallpapers/*.jpg' from cron will randomly changes wallpaper.
Why?
~~~
I've tried several programs, and as most of them used Imlib, their quality
sucks (Imlib uses neares-neighbour scaling...).
So I've decided to put together something very simple but efficient built
using the MPlayer codebase.
A'rpi
--- NEW FILE ---
gcc -g mwallp.c jpeg.c ../../libvo/aclib.o ../../libmpcodecs/img_format.o \
../../cpudetect.o ../../mp_msg.o ../../postproc/libpostproc.a \
-I../../libmpcodecs -I../.. -I../../postproc \
-L/usr/X11/lib -lX11 -ljpeg -o mwallp
--- NEW FILE ---
// based on vd_ijpg.c by Pontscho
#include <stdio.h>
#include <stdlib.h>
#include <jpeglib.h>
#define UINT16 IJPG_UINT16
#define INT16 IJPG_INT16
#include <setjmp.h>
#include <inttypes.h>
#include "img_format.h"
#include "swscale.h"
#include "rgb2rgb.h"
static SwsContext *swsContext=NULL;
typedef struct
{
struct jpeg_source_mgr pub;
unsigned char * inbuf;
int bufsize;
} my_source_mgr;
typedef my_source_mgr * my_src_ptr;
METHODDEF(void) init_source (j_decompress_ptr cinfo)
{
}
METHODDEF(boolean) fill_input_buffer (j_decompress_ptr cinfo)
{
my_src_ptr src = (my_src_ptr) cinfo->src;
size_t nbytes;
src->pub.next_input_byte = src->inbuf;
src->pub.bytes_in_buffer = src->bufsize;
return TRUE;
}
METHODDEF(void) skip_input_data (j_decompress_ptr cinfo, long num_bytes)
{
my_src_ptr src = (my_src_ptr) cinfo->src;
if (num_bytes > 0)
{
while (num_bytes > (long) src->pub.bytes_in_buffer)
{
num_bytes -= (long) src->pub.bytes_in_buffer;
(void) fill_input_buffer(cinfo);
}
src->pub.next_input_byte += (size_t) num_bytes;
src->pub.bytes_in_buffer -= (size_t) num_bytes;
}
}
METHODDEF(void) term_source (j_decompress_ptr cinfo) { }
GLOBAL(void) jpeg_buf_src ( j_decompress_ptr cinfo, char * inbuf,int bufsize )
{
my_src_ptr src;
if (cinfo->src == NULL) cinfo->src=malloc( sizeof( my_source_mgr ) );
src = (my_src_ptr) cinfo->src;
src->pub.init_source = init_source;
src->pub.fill_input_buffer = fill_input_buffer;
src->pub.skip_input_data = skip_input_data;
src->pub.resync_to_restart = jpeg_resync_to_restart;
src->pub.term_source = term_source;
src->inbuf = inbuf;
src->bufsize=bufsize;
src->pub.bytes_in_buffer = 0;
src->pub.next_input_byte = NULL;
}
struct my_error_mgr
{
struct jpeg_error_mgr pub;
jmp_buf setjmp_buffer;
};
typedef struct my_error_mgr * my_error_ptr;
METHODDEF(void) my_error_exit (j_common_ptr cinfo)
{
my_error_ptr myerr=(my_error_ptr) cinfo->err;
(*cinfo->err->output_message) (cinfo);
longjmp(myerr->setjmp_buffer, 1);
}
static struct jpeg_decompress_struct cinfo;
static struct my_error_mgr jerr;
// decode a frame
int decode_jpeg(void* data,int len,char* dbuffer,int dwidth,int dheight, int dstride,int dbpp){
int width,height,depth,i;
int row_stride;
unsigned char* img=NULL;
int in_fmt=0;
if ( len <= 0 ) return 0; // skipped frame
cinfo.err=jpeg_std_error( &jerr.pub );
jerr.pub.error_exit=my_error_exit;
if( setjmp( jerr.setjmp_buffer ) )
{
return 0;
}
jpeg_create_decompress( &cinfo );
jpeg_buf_src( &cinfo,data,len );
jpeg_read_header( &cinfo,TRUE );
width=cinfo.image_width;
height=cinfo.image_height;
jpeg_start_decompress( &cinfo );
depth=cinfo.output_components * 8;
switch( depth ) {
case 8: in_fmt=IMGFMT_Y8;break;
case 24: in_fmt=IMGFMT_RGB|24;break;
default: return 0;
}
row_stride=cinfo.output_width * cinfo.output_components;
img=malloc(row_stride * (height+1));
for ( i=0;i < height;i++ ){
// char* row=dbuffer+i*dstride;
char* row=img+row_stride*i;
jpeg_read_scanlines( &cinfo,(JSAMPLE**)&row,1 );
}
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
swsContext= getSwsContextFromCmdLine(width,height, in_fmt,
dwidth,dheight, IMGFMT_BGR|dbpp);
swsContext->swScale(swsContext,&img,&row_stride,0,height,&dbuffer, &dstride);
freeSwsContext(swsContext);
free(img);
return 1;
}
--- NEW FILE ---
// based on x11_common.c/vo_x11.c from libvo
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <X11/Xmd.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include "cpudetect.h"
char* mDisplayName=NULL;
Display* mDisplay=NULL;
Window mRootWin=None;
int mScreen=0;
XImage * mXImage = NULL;
GC vo_gc = NULL;
Pixmap mPixmap=0;
int vo_depthonscreen=0;
int vo_screenwidth=0;
int vo_screenheight=0;
int verbose=0;
int namecnt=0;
int main(int argc,char* argv[]){
unsigned int mask;
int bpp,depth;
mp_msg_init();
mp_msg_set_level(5);
GetCpuCaps(&gCpuCaps);
mDisplayName = XDisplayName(mDisplayName);
mDisplay=XOpenDisplay(mDisplayName);
if ( !mDisplay )
{
printf("vo: couldn't open the X11 display (%s)!\n",mDisplayName );
return 0;
}
mScreen=DefaultScreen( mDisplay ); // Screen ID.
mRootWin=RootWindow( mDisplay,mScreen );// Root window ID.
vo_screenwidth=DisplayWidth( mDisplay,mScreen );
vo_screenheight=DisplayHeight( mDisplay,mScreen );
// get color depth (from root window, or the best visual):
{ XWindowAttributes attribs;
XGetWindowAttributes(mDisplay, mRootWin, &attribs);
depth=vo_depthonscreen=attribs.depth;
}
mXImage=XGetImage( mDisplay,mRootWin,0,0,vo_screenwidth,vo_screenheight,AllPlanes,ZPixmap );
bpp=mXImage->bits_per_pixel;
if((vo_depthonscreen+7)/8 != (bpp+7)/8) vo_depthonscreen=bpp; // by A'rpi
mask=mXImage->red_mask|mXImage->green_mask|mXImage->blue_mask;
if(((vo_depthonscreen+7)/8)==2){
if(mask==0x7FFF) vo_depthonscreen=15; else
if(mask==0xFFFF) vo_depthonscreen=16;
}
printf("X11 running at %d x %d, %d bpp \n",vo_screenwidth,vo_screenheight,vo_depthonscreen);
mPixmap=XCreatePixmap(mDisplay,mRootWin,vo_screenwidth,vo_screenheight,depth);
{ XGCValues xgcv;
vo_gc=XCreateGC( mDisplay,mRootWin,0L,&xgcv );
}
if(argc<2){ printf("no filenames!\n");return;}
srand(time(NULL));
while(1){
FILE *f;
char* data;
int len;
int ret;
namecnt=1+(long long)rand()*(argc-1)/RAND_MAX;
//++namecnt; if(namecnt>=argc) namecnt=1;
if(namecnt<1 || namecnt>=argc) continue; // ???
f=fopen(argv[namecnt],"rb");if(!f) continue;
fseek(f,0,SEEK_END); len=ftell(f); fseek(f,0,SEEK_SET);
data=malloc(len);
len=fread(data,1,len,f);
fclose(f);
ret=decode_jpeg(data,len,mXImage->data,vo_screenwidth,vo_screenheight,
((vo_depthonscreen+7)/8)*vo_screenwidth,vo_depthonscreen);
free(data);
if(!ret) continue; // failed to load
XPutImage( mDisplay,mPixmap,vo_gc,mXImage,
0,0, 0,0, vo_screenwidth,vo_screenheight);
XSetWindowBackgroundPixmap(mDisplay,mRootWin,mPixmap);
XClearWindow(mDisplay,mRootWin);
XSync(mDisplay, True);
break; // DONE!
}
}
More information about the MPlayer-cvslog
mailing list