2001-04-19 20:12:24 +00:00
|
|
|
/*
|
2004-07-19 23:11:06 +00:00
|
|
|
* vo_png.c, Portable Network Graphics Renderer for MPlayer
|
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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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 <png.h>
|
|
|
|
|
2006-03-24 08:12:03 +00:00
|
|
|
#include "mp_msg.h"
|
2001-04-19 20:12:24 +00:00
|
|
|
#include "config.h"
|
2006-04-24 04:23:53 +00:00
|
|
|
#include "mp_msg.h"
|
|
|
|
#include "help_mp.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"
|
2001-04-19 20:12:24 +00:00
|
|
|
|
2002-11-11 15:22:10 +00:00
|
|
|
static vo_info_t info =
|
2001-04-19 20:12:24 +00:00
|
|
|
{
|
|
|
|
"PNG file",
|
|
|
|
"png",
|
|
|
|
"Felix Buenemann <atmosfear@users.sourceforge.net>",
|
|
|
|
""
|
|
|
|
};
|
|
|
|
|
2002-11-11 15:22:10 +00:00
|
|
|
LIBVO_EXTERN (png)
|
|
|
|
|
2001-04-19 20:12:24 +00:00
|
|
|
int z_compression = Z_NO_COMPRESSION;
|
|
|
|
static int framenum = 0;
|
|
|
|
|
|
|
|
struct pngdata {
|
|
|
|
FILE * fp;
|
|
|
|
png_structp png_ptr;
|
|
|
|
png_infop info_ptr;
|
|
|
|
enum {OK,ERROR} status;
|
|
|
|
};
|
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) {
|
2006-04-24 04:23:53 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_PNG_Warning1);
|
|
|
|
mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_PNG_Warning2);
|
|
|
|
mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_PNG_Warning3);
|
2001-04-19 20:12:24 +00:00
|
|
|
}
|
|
|
|
|
2006-03-24 08:12:03 +00:00
|
|
|
if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
|
2006-04-24 04:23:53 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_DBG2, "PNG Compression level %i\n", z_compression); }
|
2001-04-19 20:12:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-08 15:26:36 +00:00
|
|
|
static struct pngdata create_png (char * fname, int image_width, int image_height, int swapped)
|
2001-04-19 20:12:24 +00:00
|
|
|
{
|
|
|
|
struct pngdata png;
|
2002-10-26 16:05:47 +00:00
|
|
|
|
2001-04-19 20:12:24 +00:00
|
|
|
/*png_structp png_ptr = png_create_write_struct
|
|
|
|
(PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
|
|
|
|
user_error_fn, user_warning_fn);*/
|
|
|
|
//png_byte *row_pointers[image_height];
|
|
|
|
png.png_ptr = png_create_write_struct
|
|
|
|
(PNG_LIBPNG_VER_STRING, NULL,
|
|
|
|
NULL, NULL);
|
|
|
|
png.info_ptr = png_create_info_struct(png.png_ptr);
|
|
|
|
|
|
|
|
if (!png.png_ptr) {
|
2006-03-24 08:12:03 +00:00
|
|
|
if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
|
2006-04-24 04:23:53 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_DBG2, "PNG Failed to init png pointer\n"); }
|
2001-04-19 20:12:24 +00:00
|
|
|
png.status = ERROR;
|
|
|
|
return png;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!png.info_ptr) {
|
2006-03-24 08:12:03 +00:00
|
|
|
if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
|
2006-04-24 04:23:53 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_DBG2, "PNG Failed to init png infopointer\n"); }
|
2001-04-19 20:12:24 +00:00
|
|
|
png_destroy_write_struct(&png.png_ptr,
|
|
|
|
(png_infopp)NULL);
|
|
|
|
png.status = ERROR;
|
|
|
|
return png;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setjmp(png.png_ptr->jmpbuf)) {
|
2006-03-24 08:12:03 +00:00
|
|
|
if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
|
2006-04-24 04:23:53 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_DBG2, "PNG Internal error!\n"); }
|
2001-04-19 20:12:24 +00:00
|
|
|
png_destroy_write_struct(&png.png_ptr, &png.info_ptr);
|
|
|
|
fclose(png.fp);
|
|
|
|
png.status = ERROR;
|
|
|
|
return png;
|
|
|
|
}
|
|
|
|
|
|
|
|
png.fp = fopen (fname, "wb");
|
|
|
|
if (png.fp == NULL) {
|
2006-04-24 04:23:53 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_PNG_ErrorOpeningForWriting, strerror(errno));
|
2001-04-19 20:12:24 +00:00
|
|
|
png.status = ERROR;
|
|
|
|
return png;
|
|
|
|
}
|
|
|
|
|
2006-03-24 08:12:03 +00:00
|
|
|
if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
|
2006-04-24 04:23:53 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_DBG2, "PNG Init IO\n"); }
|
2001-04-19 20:12:24 +00:00
|
|
|
png_init_io(png.png_ptr, png.fp);
|
|
|
|
|
|
|
|
/* set the zlib compression level */
|
|
|
|
png_set_compression_level(png.png_ptr, z_compression);
|
|
|
|
|
|
|
|
|
|
|
|
/*png_set_IHDR(png_ptr, info_ptr, width, height,
|
|
|
|
bit_depth, color_type, interlace_type,
|
|
|
|
compression_type, filter_type)*/
|
|
|
|
png_set_IHDR(png.png_ptr, png.info_ptr, image_width, image_height,
|
|
|
|
8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
|
|
|
|
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
|
|
|
|
2006-03-24 08:12:03 +00:00
|
|
|
if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
|
2006-04-24 04:23:53 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_DBG2, "PNG Write Info\n"); }
|
2001-04-19 20:12:24 +00:00
|
|
|
png_write_info(png.png_ptr, png.info_ptr);
|
|
|
|
|
2002-10-26 16:05:47 +00:00
|
|
|
if(swapped) {
|
2006-03-24 08:12:03 +00:00
|
|
|
if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
|
2006-04-24 04:23:53 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_DBG2, "PNG Set BGR Conversion\n"); }
|
2001-04-19 20:12:24 +00:00
|
|
|
png_set_bgr(png.png_ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
png.status = OK;
|
|
|
|
return png;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint8_t destroy_png(struct pngdata png) {
|
|
|
|
|
2006-03-24 08:12:03 +00:00
|
|
|
if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
|
2006-04-24 04:23:53 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_DBG2, "PNG Write End\n"); }
|
2001-04-19 20:12:24 +00:00
|
|
|
png_write_end(png.png_ptr, png.info_ptr);
|
|
|
|
|
2006-03-24 08:12:03 +00:00
|
|
|
if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
|
2006-04-24 04:23:53 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_DBG2, "PNG Destroy Write Struct\n"); }
|
2001-04-19 20:12:24 +00:00
|
|
|
png_destroy_write_struct(&png.png_ptr, &png.info_ptr);
|
|
|
|
|
|
|
|
fclose (png.fp);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-10-10 00:04:25 +00:00
|
|
|
static uint32_t draw_image(mp_image_t* mpi){
|
2001-04-19 20:12:24 +00:00
|
|
|
char buf[100];
|
2002-10-26 16:05:47 +00:00
|
|
|
int k;
|
2001-04-19 20:12:24 +00:00
|
|
|
struct pngdata png;
|
2002-10-26 16:05:47 +00:00
|
|
|
png_byte *row_pointers[mpi->h];
|
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;
|
2001-04-19 20:12:24 +00:00
|
|
|
|
2001-06-09 17:53:54 +00:00
|
|
|
snprintf (buf, 100, "%08d.png", ++framenum);
|
2001-04-19 20:12:24 +00:00
|
|
|
|
2002-10-26 16:05:47 +00:00
|
|
|
png = create_png(buf, mpi->w, mpi->h, mpi->flags&MP_IMGFLAG_SWAPPED);
|
2001-04-19 20:12:24 +00:00
|
|
|
|
|
|
|
if(png.status){
|
2006-04-24 04:23:53 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_PNG_ErrorInCreatePng);
|
2001-04-19 20:12:24 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-03-24 08:12:03 +00:00
|
|
|
if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
|
2006-04-24 04:23:53 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_DBG2, "PNG Creating Row Pointers\n"); }
|
2002-10-26 16:05:47 +00:00
|
|
|
for ( k = 0; k < mpi->h; k++ )
|
2002-10-10 00:04:25 +00:00
|
|
|
row_pointers[k] = mpi->planes[0]+mpi->stride[0]*k;
|
|
|
|
|
2001-04-19 20:12:24 +00:00
|
|
|
//png_write_flush(png.png_ptr);
|
|
|
|
//png_set_flush(png.png_ptr, nrows);
|
|
|
|
|
2006-03-24 08:12:03 +00:00
|
|
|
if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
|
2006-04-24 04:23:53 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_DBG2, "PNG Writing Image Data\n"); }
|
2001-04-19 20:12:24 +00:00
|
|
|
png_write_image(png.png_ptr, row_pointers);
|
|
|
|
|
2002-10-10 00:04:25 +00:00
|
|
|
destroy_png(png);
|
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)
|
|
|
|
{
|
|
|
|
switch(format){
|
|
|
|
case IMGFMT_RGB|24:
|
|
|
|
case IMGFMT_BGR|24:
|
2002-10-10 00:09:34 +00:00
|
|
|
return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_ACCEPT_STRIDE;
|
2001-04-19 20:12:24 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-10-26 16:05:47 +00:00
|
|
|
static void uninit(void){}
|
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
|
|
|
|
2005-01-10 15:51:55 +00:00
|
|
|
static int int_zero_to_nine(int *sh)
|
|
|
|
{
|
|
|
|
if ( (*sh < 0) || (*sh > 9) )
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static opt_t subopts[] = {
|
|
|
|
{"z", OPT_ARG_INT, &z_compression, (opt_test_f)int_zero_to_nine},
|
|
|
|
{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;
|
|
|
|
if (subopt_parse(arg, subopts) != 0) {
|
|
|
|
return -1;
|
2002-02-17 08:24:43 +00:00
|
|
|
}
|
|
|
|
return 0;
|
2002-01-26 16:01:26 +00:00
|
|
|
}
|
|
|
|
|
2005-08-05 01:24:37 +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
|
|
|
}
|