|
Carlos Lopez |
b9c525 |
/* === S Y N F I G ========================================================= */
|
|
Carlos Lopez |
b9c525 |
/*! \file mptr_cairo_png.cpp
|
|
Carlos Lopez |
b9c525 |
** \brief png Cairo Import Module
|
|
Carlos Lopez |
b9c525 |
**
|
|
Carlos Lopez |
b9c525 |
** $Id$
|
|
Carlos Lopez |
b9c525 |
**
|
|
Carlos Lopez |
b9c525 |
** \legal
|
|
Carlos Lopez |
b9c525 |
** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
|
|
Carlos Lopez |
e83454 |
** Copyright (c) 2012-2013 Carlos Lรณpez
|
|
Carlos Lopez |
b9c525 |
**
|
|
Carlos Lopez |
b9c525 |
** This package is free software; you can redistribute it and/or
|
|
Carlos Lopez |
b9c525 |
** modify it under the terms of the GNU General Public License as
|
|
Carlos Lopez |
b9c525 |
** published by the Free Software Foundation; either version 2 of
|
|
Carlos Lopez |
b9c525 |
** the License, or (at your option) any later version.
|
|
Carlos Lopez |
b9c525 |
**
|
|
Carlos Lopez |
b9c525 |
** This package is distributed in the hope that it will be useful,
|
|
Carlos Lopez |
b9c525 |
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Carlos Lopez |
b9c525 |
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Carlos Lopez |
b9c525 |
** General Public License for more details.
|
|
Carlos Lopez |
b9c525 |
** \endlegal
|
|
Carlos Lopez |
b9c525 |
**
|
|
Carlos Lopez |
b9c525 |
** === N O T E S ===========================================================
|
|
Carlos Lopez |
b9c525 |
**
|
|
Carlos Lopez |
b9c525 |
** ========================================================================= */
|
|
Carlos Lopez |
b9c525 |
|
|
Carlos Lopez |
b9c525 |
/* === H E A D E R S ======================================================= */
|
|
Carlos Lopez |
b9c525 |
|
|
Carlos Lopez |
b9c525 |
#ifdef USING_PCH
|
|
Carlos Lopez |
b9c525 |
# include "pch.h"
|
|
Carlos Lopez |
b9c525 |
#else
|
|
Carlos Lopez |
b9c525 |
#ifdef HAVE_CONFIG_H
|
|
Carlos Lopez |
b9c525 |
# include <config.h></config.h>
|
|
Carlos Lopez |
b9c525 |
#endif
|
|
Carlos Lopez |
b9c525 |
|
|
Carlos Lopez |
b9c525 |
#include "mptr_cairo_png.h"
|
|
Carlos Lopez |
b9c525 |
#include <synfig cairoimporter.h=""></synfig>
|
|
Carlos Lopez |
b9c525 |
#include <synfig time.h=""></synfig>
|
|
Carlos Lopez |
b9c525 |
#include <synfig general.h=""></synfig>
|
|
bw |
94d8a6 |
#include <synfig localization.h=""></synfig>
|
|
Carlos Lopez |
b9c525 |
|
|
Carlos Lopez |
b9c525 |
|
|
Carlos Lopez |
b9c525 |
#include <cstdio></cstdio>
|
|
Carlos Lopez |
b9c525 |
#include <algorithm></algorithm>
|
|
Carlos Lopez |
b9c525 |
#include <functional></functional>
|
|
Carlos Lopez |
b9c525 |
#endif
|
|
Carlos Lopez |
b9c525 |
|
|
Carlos Lopez |
b9c525 |
/* === M A C R O S ========================================================= */
|
|
Carlos Lopez |
b9c525 |
|
|
Carlos Lopez |
b9c525 |
using namespace synfig;
|
|
Carlos Lopez |
b9c525 |
using namespace std;
|
|
Carlos Lopez |
b9c525 |
using namespace etl;
|
|
Carlos Lopez |
b9c525 |
|
|
Carlos Lopez |
b9c525 |
/* === G L O B A L S ======================================================= */
|
|
Carlos Lopez |
b9c525 |
|
|
Carlos Lopez |
b9c525 |
SYNFIG_CAIROIMPORTER_INIT(cairo_png_mptr);
|
|
Carlos Lopez |
b9c525 |
SYNFIG_CAIROIMPORTER_SET_NAME(cairo_png_mptr,"cairo_png");
|
|
Carlos Lopez |
b9c525 |
SYNFIG_CAIROIMPORTER_SET_EXT(cairo_png_mptr,"png");
|
|
Carlos Lopez |
b9c525 |
SYNFIG_CAIROIMPORTER_SET_VERSION(cairo_png_mptr,"0.1");
|
|
Carlos Lopez |
b9c525 |
SYNFIG_CAIROIMPORTER_SET_CVS_ID(cairo_png_mptr,"$Id$");
|
|
|
292dfb |
SYNFIG_CAIROIMPORTER_SET_SUPPORTS_FILE_SYSTEM_WRAPPER(cairo_png_mptr, true);
|
|
Carlos Lopez |
b9c525 |
|
|
Carlos Lopez |
b9c525 |
/* === M E T H O D S ======================================================= */
|
|
Carlos Lopez |
b9c525 |
|
|
|
292dfb |
cairo_status_t
|
|
|
292dfb |
cairo_png_mptr::read_callback(void *closure, unsigned char *data, unsigned int length)
|
|
|
292dfb |
{
|
|
|
292dfb |
unsigned int s = closure == NULL ? 0
|
|
|
133e55 |
: ((FileSystem::ReadStream*)closure)->read_block(data, length);
|
|
|
292dfb |
if (s < length) {
|
|
|
292dfb |
memset(data + s, 0, length - s);
|
|
|
292dfb |
return CAIRO_STATUS_READ_ERROR;
|
|
|
292dfb |
}
|
|
|
292dfb |
return CAIRO_STATUS_SUCCESS;
|
|
|
292dfb |
}
|
|
Carlos Lopez |
b9c525 |
|
|
|
374cd3 |
cairo_png_mptr::cairo_png_mptr(const synfig::FileSystem::Identifier &identifier):
|
|
|
fcad0d |
CairoImporter(identifier)
|
|
Carlos Lopez |
b9c525 |
{
|
|
|
e59227 |
FileSystem::ReadStream::Handle stream = identifier.get_read_stream();
|
|
|
292dfb |
csurface_=cairo_image_surface_create_from_png_stream(read_callback, stream.get());
|
|
|
292dfb |
stream.reset();
|
|
Carlos López |
89c5d0 |
if(cairo_surface_status(csurface_))
|
|
Carlos López |
89c5d0 |
{
|
|
|
374cd3 |
throw strprintf("Unable to physically open %s",identifier.filename.c_str());
|
|
Carlos Lopez |
0d0b95 |
cairo_surface_destroy(csurface_);
|
|
Carlos Lopez |
0d0b95 |
csurface_=NULL;
|
|
Carlos López |
89c5d0 |
return;
|
|
Carlos López |
89c5d0 |
}
|
|
Carlos Lopez |
b9c525 |
}
|
|
Carlos Lopez |
b9c525 |
|
|
Carlos Lopez |
b9c525 |
cairo_png_mptr::~cairo_png_mptr()
|
|
Carlos Lopez |
b9c525 |
{
|
|
Carlos Lopez |
b9c525 |
if(csurface_ && !cairo_surface_status(csurface_))
|
|
Carlos Lopez |
b9c525 |
cairo_surface_destroy(csurface_);
|
|
Carlos Lopez |
b9c525 |
}
|
|
Carlos Lopez |
b9c525 |
|
|
Carlos Lopez |
b9c525 |
bool
|
|
Carlos Lopez |
b9c525 |
cairo_png_mptr::get_frame(cairo_surface_t *&csurface, const synfig::RendDesc &/*renddesc*/, Time, synfig::ProgressCallback */*cb*/)
|
|
Carlos Lopez |
b9c525 |
{
|
|
Carlos Lopez |
b9c525 |
if(csurface_ && !cairo_surface_status(csurface_))
|
|
Carlos Lopez |
b9c525 |
{
|
|
Carlos Lopez |
b9c525 |
csurface=cairo_surface_reference(csurface_);
|
|
Carlos Lopez |
b9c525 |
return true;
|
|
Carlos Lopez |
b9c525 |
}
|
|
Carlos Lopez |
b9c525 |
else
|
|
Carlos Lopez |
b9c525 |
return false;
|
|
Carlos Lopez |
b9c525 |
}
|
|
Carlos Lopez |
b9c525 |
|
|
Carlos Lopez |
b9c525 |
bool
|
|
Carlos Lopez |
b9c525 |
cairo_png_mptr::get_frame(cairo_surface_t *&csurface, const synfig::RendDesc &/*renddesc*/, Time,
|
|
Carlos Lopez |
b9c525 |
bool &/*trimmed*/, unsigned int &/*width*/, unsigned int &/*height*/, unsigned int &/*top*/, unsigned int &/*left*/, synfig::ProgressCallback */*cb*/)
|
|
Carlos Lopez |
b9c525 |
{
|
|
Carlos Lopez |
b9c525 |
if(csurface_ && !cairo_surface_status(csurface_))
|
|
Carlos Lopez |
b9c525 |
{
|
|
Carlos Lopez |
b9c525 |
csurface=cairo_surface_reference(csurface_);
|
|
Carlos Lopez |
b9c525 |
return true;
|
|
Carlos Lopez |
b9c525 |
}
|
|
Carlos Lopez |
b9c525 |
else
|
|
Carlos Lopez |
b9c525 |
return false;
|
|
Carlos Lopez |
b9c525 |
}
|