1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-23 11:47:45 +00:00

One-time cosmetics update.

I finally got rid of the horrible one-space indentation. Changed it to four
spaces. Also changed all function calls, assignments, et cetera, to conform
to a certain 'standard'. Removed all trailing whitespace. No more tabs (width
can be different from editor to editor), it's all spaces now. Next
semi-cosmetics stop will be doxygen comments.

Tested: It compiles to exactly the same object as before. No functional
change has been made.


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@13218 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
ivo 2004-09-01 02:31:24 +00:00
parent 60a0375a75
commit d5d36f90c9

View File

@ -1,18 +1,34 @@
/* ------------------------------------------------------------------------- */
/* /*
* vo_jpeg.c, JPEG Renderer for MPlayer * vo_jpeg.c, JPEG Renderer for MPlayer
* *
* Copyright 2002 by Pontscho (pontscho@makacs.poliod.hu) *
* 25/04/2003: Spring cleanup -- alex * Changelog
* 04/08/2004: Added multiple subdirectory support -- ivop@euronet.nl *
* Original version: Copyright 2002 by Pontscho (pontscho@makacs.poliod.hu)
* 2003-04-25 Spring cleanup -- Alex
* 2004-08-04 Added multiple subdirectory support -- Ivo (ivop@euronet.nl)
* 2004-09-01 Cosmetics update -- Ivo
* *
*/ */
/* ------------------------------------------------------------------------- */
/* Global Includes */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <jpeglib.h> #include <jpeglib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
/* ------------------------------------------------------------------------- */
/* Local Includes */
#include "config.h" #include "config.h"
#include "mp_msg.h" #include "mp_msg.h"
@ -21,13 +37,17 @@
#include "mplayer.h" /* for exit_player() */ #include "mplayer.h" /* for exit_player() */
#include "help_mp.h" #include "help_mp.h"
#include <sys/stat.h> /* ------------------------------------------------------------------------- */
#include <sys/types.h>
#include <unistd.h> /* Defines */
/* Used for temporary buffers to store file- and pathnames */ /* Used for temporary buffers to store file- and pathnames */
#define BUFLENGTH 512 #define BUFLENGTH 512
/* ------------------------------------------------------------------------- */
/* Info */
static vo_info_t info= static vo_info_t info=
{ {
"JPEG file", "JPEG file",
@ -38,6 +58,10 @@ static vo_info_t info=
LIBVO_EXTERN (jpeg) LIBVO_EXTERN (jpeg)
/* ------------------------------------------------------------------------- */
/* Global Variables */
static int image_width; static int image_width;
static int image_height; static int image_height;
@ -46,200 +70,258 @@ int jpeg_progressive_mode = 0;
int jpeg_optimize = 100; int jpeg_optimize = 100;
int jpeg_smooth = 0; int jpeg_smooth = 0;
int jpeg_quality = 75; int jpeg_quality = 75;
char * jpeg_outdir = "."; char *jpeg_outdir = ".";
char * jpeg_subdirs = NULL; char *jpeg_subdirs = NULL;
int jpeg_maxfiles=1000; int jpeg_maxfiles = 1000;
static int framenum=0; static int framenum = 0;
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) /* ------------------------------------------------------------------------- */
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)
{ {
char buf[BUFLENGTH]; char buf[BUFLENGTH];
struct stat stat_p; struct stat stat_p;
/* Create outdir. If it already exists, test if it's a writable directory */ /* Create outdir.
* If it already exists, test if it's a writable directory */
snprintf (buf, BUFLENGTH, "%s", jpeg_outdir); snprintf(buf, BUFLENGTH, "%s", jpeg_outdir);
if (mkdir (buf, 0755)<0) { if ( mkdir(buf, 0755) < 0 ) {
switch (errno) { /* use switch in case other errors need to be caught and handled in the future */ switch (errno) { /* use switch in case other errors need to be caught
case EEXIST: and handled in the future */
if ( stat(buf, &stat_p) < 0 ) { case EEXIST:
mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, MSGTR_VO_JPEG_GenericError, strerror(errno) ); if ( stat(buf, &stat_p ) < 0 ) {
mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name, MSGTR_VO_JPEG_UnableToAccess,buf); mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name,
exit_player(MSGTR_Exit_error); MSGTR_VO_JPEG_GenericError, strerror(errno) );
} mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name,
if ( !S_ISDIR(stat_p.st_mode) ) { MSGTR_VO_JPEG_UnableToAccess,buf);
mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name, buf, MSGTR_VO_JPEG_ExistsButNoDirectory); exit_player(MSGTR_Exit_error);
exit_player(MSGTR_Exit_error); }
} if ( !S_ISDIR(stat_p.st_mode) ) {
if ( !(stat_p.st_mode & S_IWUSR) ) { mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name,
mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name, MSGTR_VO_JPEG_DirExistsButNotWritable); buf, MSGTR_VO_JPEG_ExistsButNoDirectory);
exit_player(MSGTR_Exit_error); exit_player(MSGTR_Exit_error);
} }
if ( !(stat_p.st_mode & S_IWUSR) ) {
mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name,
MSGTR_VO_JPEG_DirExistsButNotWritable);
exit_player(MSGTR_Exit_error);
}
mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name, MSGTR_VO_JPEG_DirExistsAndIsWritable); mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name,
break; MSGTR_VO_JPEG_DirExistsAndIsWritable);
break;
default: default:
mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, MSGTR_VO_JPEG_GenericError, strerror(errno) ); mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name,
mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name, MSGTR_VO_JPEG_CantCreateDirectory); MSGTR_VO_JPEG_GenericError, strerror(errno) );
exit_player(MSGTR_Exit_error); mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name,
} /* end switch */ MSGTR_VO_JPEG_CantCreateDirectory);
} else { exit_player(MSGTR_Exit_error);
mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name, MSGTR_VO_JPEG_DirectoryCreateSuccess); } /* end switch */
} /* end if */ } else {
mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name,
MSGTR_VO_JPEG_DirectoryCreateSuccess);
} /* end if */
image_height=height; image_height = height;
image_width=width; image_width = width;
return 0; return 0;
} }
static uint32_t jpeg_write( uint8_t * name,uint8_t * buffer ) /* ------------------------------------------------------------------------- */
static uint32_t jpeg_write(uint8_t * name, uint8_t * buffer)
{ {
FILE * o; FILE *outfile;
struct jpeg_compress_struct cinfo; struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr; struct jpeg_error_mgr jerr;
JSAMPROW row_pointer[1]; JSAMPROW row_pointer[1];
int row_stride; int row_stride;
if ( !buffer ) return 1; if ( !buffer ) return 1;
if ( (o=fopen( name,"wb" )) == NULL ) return 1; if ( (outfile = fopen(name, "wb") ) == NULL ) {
return 1;
}
cinfo.err=jpeg_std_error(&jerr); cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo); jpeg_create_compress(&cinfo);
jpeg_stdio_dest( &cinfo,o ); jpeg_stdio_dest(&cinfo, outfile);
cinfo.image_width=image_width; cinfo.image_width = image_width;
cinfo.image_height=image_height; cinfo.image_height = image_height;
cinfo.input_components=3; cinfo.input_components = 3;
cinfo.in_color_space=JCS_RGB; cinfo.in_color_space = JCS_RGB;
jpeg_set_defaults( &cinfo ); jpeg_set_defaults(&cinfo);
jpeg_set_quality( &cinfo,jpeg_quality,jpeg_baseline ); jpeg_set_quality(&cinfo,jpeg_quality, jpeg_baseline);
cinfo.optimize_coding=jpeg_optimize; cinfo.optimize_coding = jpeg_optimize;
cinfo.smoothing_factor=jpeg_smooth; cinfo.smoothing_factor = jpeg_smooth;
if ( jpeg_progressive_mode ) jpeg_simple_progression( &cinfo ); if ( jpeg_progressive_mode ) {
jpeg_start_compress( &cinfo,TRUE ); jpeg_simple_progression(&cinfo);
}
row_stride = image_width * 3; jpeg_start_compress(&cinfo, TRUE);
while ( cinfo.next_scanline < cinfo.image_height )
{
row_pointer[0]=&buffer[ cinfo.next_scanline * row_stride ];
(void)jpeg_write_scanlines( &cinfo,row_pointer,1 );
}
jpeg_finish_compress( &cinfo ); row_stride = image_width * 3;
fclose( o ); while (cinfo.next_scanline < cinfo.image_height) {
jpeg_destroy_compress( &cinfo ); row_pointer[0] = &buffer[cinfo.next_scanline * row_stride];
(void)jpeg_write_scanlines(&cinfo, row_pointer,1);
}
return 0; jpeg_finish_compress(&cinfo);
fclose(outfile);
jpeg_destroy_compress(&cinfo);
return 0;
} }
static uint32_t draw_frame(uint8_t * src[]) /* ------------------------------------------------------------------------- */
static uint32_t draw_frame(uint8_t *src[])
{ {
static uint32_t framecounter=0, subdircounter=0; static uint32_t framecounter = 0, subdircounter = 0;
char buf[BUFLENGTH]; char buf[BUFLENGTH];
uint8_t *dst= src[0]; uint8_t *dst = src[0];
static char subdirname[BUFLENGTH] = ""; static char subdirname[BUFLENGTH] = "";
struct stat stat_p; struct stat stat_p;
/* Start writing to new subdirectory after a certain amount of frames */ /* Start writing to new subdirectory after a certain amount of frames */
if ( framecounter == jpeg_maxfiles ) { if ( framecounter == jpeg_maxfiles ) {
framecounter = 0; framecounter = 0;
} }
/* If framecounter is zero (or reset to zero), increment subdirectory number /* If framecounter is zero (or reset to zero), increment subdirectory
* and create the subdirectory. * number and create the subdirectory.
* If jpeg_subdirs is not set, do nothing and resort to old behaviour. */ * If jpeg_subdirs is not set, do nothing and resort to old behaviour. */
if ( !framecounter && jpeg_subdirs ) { if ( !framecounter && jpeg_subdirs ) {
snprintf (subdirname, BUFLENGTH, "%s%08d", jpeg_subdirs, ++subdircounter); snprintf(subdirname, BUFLENGTH, "%s%08d", jpeg_subdirs,
snprintf (buf, BUFLENGTH, "%s/%s", jpeg_outdir, subdirname); ++subdircounter);
if (mkdir (buf, 0755)<0) { snprintf(buf, BUFLENGTH, "%s/%s", jpeg_outdir, subdirname);
switch (errno) { /* use switch in case other errors need to be caught and handled in the future */ if ( mkdir(buf, 0755) < 0 ) {
case EEXIST: switch (errno) { /* use switch in case other errors need to be
if ( stat(buf, &stat_p) < 0 ) { caught and handled in the future */
mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, MSGTR_VO_JPEG_GenericError, strerror(errno) ); case EEXIST:
mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name, MSGTR_VO_JPEG_UnableToAccess, buf); if ( stat(buf, &stat_p) < 0 ) {
exit_player(MSGTR_Exit_error); mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n",
} info.short_name, MSGTR_VO_JPEG_GenericError,
if ( !S_ISDIR(stat_p.st_mode) ) { strerror(errno) );
mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s %s\n", info.short_name, buf, MSGTR_VO_JPEG_ExistsButNoDirectory); mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n",
exit_player(MSGTR_Exit_error); info.short_name, MSGTR_VO_JPEG_UnableToAccess,
} buf);
if ( !(stat_p.st_mode & S_IWUSR) ) { exit_player(MSGTR_Exit_error);
mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s - %s\n", info.short_name, buf, MSGTR_VO_JPEG_DirExistsButNotWritable); }
exit_player(MSGTR_Exit_error); if ( !S_ISDIR(stat_p.st_mode) ) {
} mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s %s\n",
info.short_name, buf,
MSGTR_VO_JPEG_ExistsButNoDirectory);
exit_player(MSGTR_Exit_error);
}
if ( !(stat_p.st_mode & S_IWUSR) ) {
mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s - %s\n",
info.short_name, buf,
MSGTR_VO_JPEG_DirExistsButNotWritable);
exit_player(MSGTR_Exit_error);
}
mp_msg(MSGT_VO, MSGL_INFO, "\n%s: %s - %s\n", info.short_name, buf, MSGTR_VO_JPEG_DirExistsAndIsWritable); mp_msg(MSGT_VO, MSGL_INFO, "\n%s: %s - %s\n",
break; info.short_name, buf,
MSGTR_VO_JPEG_DirExistsAndIsWritable);
break;
default: default:
mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, MSGTR_VO_JPEG_GenericError, strerror(errno) ); mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name,
mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s - %s.\n", info.short_name, buf, MSGTR_VO_JPEG_CantCreateDirectory); MSGTR_VO_JPEG_GenericError, strerror(errno) );
exit_player(MSGTR_Exit_error); mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s - %s.\n",
break; info.short_name, buf,
} MSGTR_VO_JPEG_CantCreateDirectory);
} /* switch */ exit_player(MSGTR_Exit_error);
} /* if !framecounter && jpeg_subdirs */ break;
}
} /* switch */
} /* if !framecounter && jpeg_subdirs */
framenum++;
framenum++; /* snprintf the full pathname of the outputfile */
snprintf(buf, BUFLENGTH, "%s/%s/%08d.jpg", jpeg_outdir, subdirname,
framenum);
/* snprintf the full pathname of the outputfile */ framecounter++;
snprintf (buf, BUFLENGTH, "%s/%s/%08d.jpg", jpeg_outdir, subdirname, framenum);
framecounter++; return jpeg_write(buf, src[0]);
return jpeg_write( buf,src[0] );
} }
/* ------------------------------------------------------------------------- */
static void draw_osd(void) static void draw_osd(void)
{ {
} }
/* ------------------------------------------------------------------------- */
static void flip_page (void) static void flip_page (void)
{ {
} }
static uint32_t draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y ) /* ------------------------------------------------------------------------- */
static uint32_t draw_slice(uint8_t *src[], int stride[], int w, int h,
int x, int y)
{ {
return 0; return 0;
} }
/* ------------------------------------------------------------------------- */
static uint32_t query_format(uint32_t format) static uint32_t query_format(uint32_t format)
{ {
if (format == IMGFMT_RGB24) if (format == IMGFMT_RGB24) {
return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW; return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW;
}
return 0; return 0;
} }
/* ------------------------------------------------------------------------- */
static void uninit(void) static void uninit(void)
{ {
} }
/* ------------------------------------------------------------------------- */
static void check_events(void) static void check_events(void)
{ {
} }
/* ------------------------------------------------------------------------- */
static uint32_t preinit(const char *arg) static uint32_t preinit(const char *arg)
{ {
return 0; return 0;
} }
/* ------------------------------------------------------------------------- */
static uint32_t control(uint32_t request, void *data, ...) static uint32_t control(uint32_t request, void *data, ...)
{ {
switch (request) switch (request) {
{ case VOCTRL_QUERY_FORMAT:
case VOCTRL_QUERY_FORMAT: return query_format(*((uint32_t*)data));
return query_format(*((uint32_t*)data)); }
} return VO_NOTIMPL;
return VO_NOTIMPL;
} }
/* ------------------------------------------------------------------------- */
#undef BUFLENGTH #undef BUFLENGTH
/* ------------------------------------------------------------------------- */