2009-02-08 03:27:30 +00:00
|
|
|
/*
|
|
|
|
* Portable Network Graphics renderer
|
2001-04-19 20:12:24 +00:00
|
|
|
*
|
2001-04-19 20:23:28 +00:00
|
|
|
* Copyright 2001 by Felix Buenemann <atmosfear@users.sourceforge.net>
|
2001-04-19 20:12:24 +00:00
|
|
|
*
|
2001-04-19 20:23:28 +00:00
|
|
|
* Uses libpng (which uses zlib), so see according licenses.
|
2001-04-19 20:12:24 +00:00
|
|
|
*
|
2009-02-08 03:27:30 +00:00
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2001-04-19 20:12:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2001-04-24 10:21:12 +00:00
|
|
|
#include <errno.h>
|
2001-04-19 20:12:24 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
2006-04-24 04:23:53 +00:00
|
|
|
#include "mp_msg.h"
|
2008-03-14 16:46:13 +00:00
|
|
|
#include "mp_msg.h"
|
2001-04-19 20:12:24 +00:00
|
|
|
#include "video_out.h"
|
|
|
|
#include "video_out_internal.h"
|
2005-01-10 15:51:55 +00:00
|
|
|
#include "subopt-helper.h"
|
2010-01-03 16:26:30 +00:00
|
|
|
#include "libavcodec/avcodec.h"
|
2010-01-07 23:55:42 +00:00
|
|
|
#include "fmt-conversion.h"
|
2001-04-19 20:12:24 +00:00
|
|
|
|
2009-07-06 23:26:13 +00:00
|
|
|
static const vo_info_t info =
|
2001-04-19 20:12:24 +00:00
|
|
|
{
|
|
|
|
"PNG file",
|
|
|
|
"png",
|
|
|
|
"Felix Buenemann <atmosfear@users.sourceforge.net>",
|
|
|
|
""
|
|
|
|
};
|
|
|
|
|
2007-12-02 14:39:15 +00:00
|
|
|
const LIBVO_EXTERN (png)
|
2002-11-11 15:22:10 +00:00
|
|
|
|
2010-01-03 16:26:30 +00:00
|
|
|
static int z_compression;
|
|
|
|
static int framenum;
|
2008-12-10 16:44:12 +00:00
|
|
|
static int use_alpha;
|
2010-01-03 16:26:30 +00:00
|
|
|
static AVCodecContext *avctx;
|
|
|
|
static uint8_t *outbuffer;
|
|
|
|
int outbuffer_size;
|
2002-01-02 17:50:03 +00:00
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
static int
|
2005-04-18 15:52:38 +00:00
|
|
|
config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format)
|
2001-04-19 20:12:24 +00:00
|
|
|
{
|
|
|
|
if(z_compression == 0) {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_PNG] Warning: compression level set to 0, compression disabled!\n");
|
|
|
|
mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_PNG] Info: Use -vo png:z=<n> to set compression level from 0 to 9.\n");
|
|
|
|
mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_PNG] Info: (0 = no compression, 1 = fastest, lowest - 9 best, slowest compression)\n");
|
2009-07-06 23:26:13 +00:00
|
|
|
}
|
|
|
|
|
2007-10-03 11:55:30 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_DBG2, "PNG Compression level %i\n", z_compression);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2001-04-19 20:12:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-10 00:04:25 +00:00
|
|
|
static uint32_t draw_image(mp_image_t* mpi){
|
2010-01-03 16:26:30 +00:00
|
|
|
AVFrame pic;
|
|
|
|
int buffersize;
|
|
|
|
int res;
|
2001-04-19 20:12:24 +00:00
|
|
|
char buf[100];
|
2010-01-03 16:26:30 +00:00
|
|
|
FILE *outfile;
|
2002-10-10 00:04:25 +00:00
|
|
|
|
|
|
|
// if -dr or -slices then do nothing:
|
|
|
|
if(mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK)) return VO_TRUE;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2001-06-09 17:53:54 +00:00
|
|
|
snprintf (buf, 100, "%08d.png", ++framenum);
|
2010-01-03 16:26:30 +00:00
|
|
|
outfile = fopen(buf, "wb");
|
|
|
|
if (!outfile) {
|
2010-01-07 23:54:09 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_WARN, "\n[VO_PNG] Error opening '%s' for writing!\n", strerror(errno));
|
2010-01-03 16:26:30 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2001-04-19 20:12:24 +00:00
|
|
|
|
2010-01-03 16:26:30 +00:00
|
|
|
avctx->width = mpi->w;
|
|
|
|
avctx->height = mpi->h;
|
|
|
|
avctx->pix_fmt = imgfmt2pixfmt(mpi->imgfmt);
|
|
|
|
pic.data[0] = mpi->planes[0];
|
|
|
|
pic.linesize[0] = mpi->stride[0];
|
|
|
|
buffersize = mpi->w * mpi->h * 8;
|
|
|
|
if (outbuffer_size < buffersize) {
|
|
|
|
av_freep(&outbuffer);
|
|
|
|
outbuffer = av_malloc(buffersize);
|
|
|
|
outbuffer_size = buffersize;
|
|
|
|
}
|
|
|
|
res = avcodec_encode_video(avctx, outbuffer, outbuffer_size, &pic);
|
2001-04-19 20:12:24 +00:00
|
|
|
|
2010-01-03 16:26:30 +00:00
|
|
|
if(res < 0){
|
2010-01-07 23:54:09 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_WARN, "[VO_PNG] Error in create_png.\n");
|
2010-01-03 16:26:30 +00:00
|
|
|
fclose(outfile);
|
2001-04-19 20:12:24 +00:00
|
|
|
return 1;
|
2009-07-06 23:26:13 +00:00
|
|
|
}
|
2001-04-19 20:12:24 +00:00
|
|
|
|
2010-01-03 16:26:30 +00:00
|
|
|
fwrite(outbuffer, res, 1, outfile);
|
|
|
|
fclose(outfile);
|
2001-04-19 20:12:24 +00:00
|
|
|
|
2002-10-10 00:04:25 +00:00
|
|
|
return VO_TRUE;
|
2001-04-19 20:12:24 +00:00
|
|
|
}
|
|
|
|
|
2002-10-26 16:05:47 +00:00
|
|
|
static void draw_osd(void){}
|
2001-04-19 20:12:24 +00:00
|
|
|
|
2002-10-26 16:05:47 +00:00
|
|
|
static void flip_page (void){}
|
2001-04-19 20:12:24 +00:00
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
static int draw_frame(uint8_t * src[])
|
2002-10-26 16:05:47 +00:00
|
|
|
{
|
|
|
|
return -1;
|
2001-04-19 20:12:24 +00:00
|
|
|
}
|
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
static int draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y )
|
2001-04-19 20:12:24 +00:00
|
|
|
{
|
2002-10-26 16:05:47 +00:00
|
|
|
return -1;
|
2001-04-19 20:12:24 +00:00
|
|
|
}
|
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
static int
|
2001-04-19 20:12:24 +00:00
|
|
|
query_format(uint32_t format)
|
|
|
|
{
|
2008-12-10 16:44:12 +00:00
|
|
|
const int supported_flags = VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_ACCEPT_STRIDE;
|
2001-04-19 20:12:24 +00:00
|
|
|
switch(format){
|
2008-11-13 19:05:07 +00:00
|
|
|
case IMGFMT_RGB24:
|
2008-12-10 16:44:12 +00:00
|
|
|
return use_alpha ? 0 : supported_flags;
|
2010-01-03 16:26:30 +00:00
|
|
|
case IMGFMT_BGR32:
|
2008-12-10 16:44:12 +00:00
|
|
|
return use_alpha ? supported_flags : 0;
|
2001-04-19 20:12:24 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-20 13:13:02 +00:00
|
|
|
static void uninit(void){
|
2010-01-03 16:26:30 +00:00
|
|
|
avcodec_close(avctx);
|
|
|
|
av_freep(&avctx);
|
|
|
|
av_freep(&outbuffer);
|
|
|
|
outbuffer_size = 0;
|
2008-09-20 13:13:02 +00:00
|
|
|
}
|
2001-04-19 20:12:24 +00:00
|
|
|
|
2002-10-26 16:05:47 +00:00
|
|
|
static void check_events(void){}
|
2002-01-26 16:01:26 +00:00
|
|
|
|
2010-01-01 13:18:49 +00:00
|
|
|
static int int_zero_to_nine(void *value)
|
2005-01-10 15:51:55 +00:00
|
|
|
{
|
2010-01-01 13:18:49 +00:00
|
|
|
int *sh = value;
|
2010-01-01 13:23:16 +00:00
|
|
|
return *sh >= 0 && *sh <= 9;
|
2005-01-10 15:51:55 +00:00
|
|
|
}
|
|
|
|
|
2009-03-07 08:51:40 +00:00
|
|
|
static const opt_t subopts[] = {
|
2009-03-15 10:03:09 +00:00
|
|
|
{"alpha", OPT_ARG_BOOL, &use_alpha, NULL},
|
2010-01-01 13:18:49 +00:00
|
|
|
{"z", OPT_ARG_INT, &z_compression, int_zero_to_nine},
|
2005-01-10 15:51:55 +00:00
|
|
|
{NULL}
|
|
|
|
};
|
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
static int preinit(const char *arg)
|
2002-01-26 16:01:26 +00:00
|
|
|
{
|
2005-01-10 15:51:55 +00:00
|
|
|
z_compression = 0;
|
2008-12-10 16:44:12 +00:00
|
|
|
use_alpha = 0;
|
2005-01-10 15:51:55 +00:00
|
|
|
if (subopt_parse(arg, subopts) != 0) {
|
|
|
|
return -1;
|
2002-02-17 08:24:43 +00:00
|
|
|
}
|
2010-01-03 16:26:30 +00:00
|
|
|
avctx = avcodec_alloc_context();
|
|
|
|
if (avcodec_open(avctx, avcodec_find_encoder(CODEC_ID_PNG)) < 0) {
|
|
|
|
uninit();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
avctx->compression_level = z_compression;
|
2002-02-17 08:24:43 +00:00
|
|
|
return 0;
|
2002-01-26 16:01:26 +00:00
|
|
|
}
|
|
|
|
|
2008-04-02 16:38:34 +00:00
|
|
|
static int control(uint32_t request, void *data)
|
2002-01-26 16:01:26 +00:00
|
|
|
{
|
2002-02-09 00:47:26 +00:00
|
|
|
switch (request) {
|
2002-10-10 00:04:25 +00:00
|
|
|
case VOCTRL_DRAW_IMAGE:
|
|
|
|
return draw_image(data);
|
2002-02-09 00:47:26 +00:00
|
|
|
case VOCTRL_QUERY_FORMAT:
|
|
|
|
return query_format(*((uint32_t*)data));
|
|
|
|
}
|
|
|
|
return VO_NOTIMPL;
|
2002-01-26 16:01:26 +00:00
|
|
|
}
|