gif.cpp
Go to the documentation of this file.
/*
CLAW - a C++ Library Absolutely Wonderful
CLAW is a free library without any particular aim but being useful to
anyone.
Copyright (C) 2005-2011 Julien Jorge
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
contact: julien.jorge@gamned.org
*/
#include "claw/gif.hpp"
#include <algorithm>
#include <claw/functional.hpp>
/*----------------------------------------------------------------------------*/
bool claw::graphic::gif::screen_descriptor::has_global_color_table() const
{
return (packed & 0x80) != 0;
} // gif::screen_descriptor::has_global_color_table()
/*----------------------------------------------------------------------------*/
unsigned int claw::graphic::gif::screen_descriptor::color_palette_size() const
{
if ( !has_global_color_table() )
return 0;
else
return 1 << ((packed & 0x07) + 1);
} // gif::screen_descriptor::color_palette_size()
/*----------------------------------------------------------------------------*/
claw::graphic::gif::graphic_control_extension::disposal_method
claw::graphic::gif::graphic_control_extension::get_disposal_method() const
{
switch( (packed & 0x1C) >> 2 )
{
case 0: return dispose_none;
case 1: return dispose_do_not_dispose;
case 2: return dispose_background;
case 3: return dispose_previous;
default:
return dispose_previous;
}
} // gif::graphic_control_extension::get_disposal_method()
/*----------------------------------------------------------------------------*/
bool
claw::graphic::gif::graphic_control_extension::has_transparent_color() const
{
return (packed & 0x01) != 0;
} // gif::graphic_control_extension::has_transparent_color()
/*----------------------------------------------------------------------------*/
bool claw::graphic::gif::image_descriptor::has_color_table() const
{
return (packed & 0x80) != 0;
} // gif::image_descriptor::has_color_table()
/*----------------------------------------------------------------------------*/
bool claw::graphic::gif::image_descriptor::is_interlaced() const
{
return (packed & 0x40) != 0;
} // gif::image_descriptor::is_interlaced()
/*----------------------------------------------------------------------------*/
unsigned int claw::graphic::gif::image_descriptor::color_palette_size() const
{
if ( !has_color_table() )
return 0;
else
return 1 << ((packed & 0x07) + 1);
} // gif::image_descriptor::color_palette_size()
/*----------------------------------------------------------------------------*/
claw::graphic::gif::gif()
{
} // gif::gif() [copy constructor]
/*----------------------------------------------------------------------------*/
claw::graphic::gif::gif( const gif& that )
: image(that)
{
frame_list::const_iterator it;
for (it=that.m_frame.begin(); it!=that.m_frame.end(); ++it)
m_frame.push_back( new frame(**it) );
} // gif::gif() [copy constructor]
/*----------------------------------------------------------------------------*/
claw::graphic::gif::gif( std::istream& f )
{
reader(*this, m_frame, f);
} // gif::gif() [constructor, from file]
/*----------------------------------------------------------------------------*/
claw::graphic::gif::~gif()
{
std::for_each
( m_frame.begin(), m_frame.end(), claw::delete_function<frame*>() );
m_frame.clear();
} // gif::~gif()
/*----------------------------------------------------------------------------*/
claw::graphic::gif& claw::graphic::gif::operator=( const gif& that )
{
gif tmp(that);
std::swap(tmp, *this);
return *this;
} // gif::operator=()
/*----------------------------------------------------------------------------*/
void claw::graphic::gif::swap( gif& that )
{
super::swap(that);
std::swap(m_frame, that.m_frame);
} // gif::swap()
/*----------------------------------------------------------------------------*/
claw::graphic::gif::frame_iterator claw::graphic::gif::frame_begin()
{
return frame_iterator(m_frame.begin());
} // gif::begin()
/*----------------------------------------------------------------------------*/
claw::graphic::gif::frame_iterator claw::graphic::gif::frame_end()
{
return frame_iterator(m_frame.end());
} // gif::end()
/*----------------------------------------------------------------------------*/
claw::graphic::gif::const_frame_iterator claw::graphic::gif::frame_begin() const
{
return const_frame_iterator(m_frame.begin());
} // gif::begin()
/*----------------------------------------------------------------------------*/
claw::graphic::gif::const_frame_iterator claw::graphic::gif::frame_end() const
{
return const_frame_iterator(m_frame.end());
} // gif::end()
/*----------------------------------------------------------------------------*/
void std::swap( claw::graphic::gif& a, claw::graphic::gif& b )
{
a.swap(b);
} // swap()
claw::delete_function
Function object that deletes a pointer.
Definition functional.hpp:256
claw::graphic::gif::frame
One frame in the animation.
Definition gif.hpp:57
claw::graphic::gif::reader
This class reads data from a gif file. The image is resized to the size of the screen (as defined in ...
Definition gif.hpp:280
claw::graphic::gif
A class for gif pictures.
Definition gif.hpp:52
claw::graphic::gif::frame_end
frame_iterator frame_end()
Get an iterator on the end of the frame sequence.
Definition gif.cpp:203
claw::graphic::gif::~gif
~gif()
Destructor.
Definition gif.cpp:160
claw::graphic::gif::swap
void swap(gif &that)
Swap the content of two gifs.
Definition gif.cpp:184
claw::graphic::gif::operator=
gif & operator=(const gif &that)
Assignment.
Definition gif.cpp:172
claw::graphic::gif::frame_iterator
wrapped_iterator< frame, frame_list::iterator, claw::dereference< frame > >::iterator_type frame_iterator
Iterator on the content of the gif.
Definition gif.hpp:88
claw::graphic::gif::const_frame_iterator
wrapped_iterator< constframe, frame_list::const_iterator, claw::const_dereference< frame > >::iterator_type const_frame_iterator
Iterator on the content of the gif.
Definition gif.hpp:94
claw::graphic::gif::gif
gif()
Constructor.
Definition gif.cpp:127
claw::graphic::gif::frame_begin
frame_iterator frame_begin()
Get an iterator on the beginning of the frame sequence.
Definition gif.cpp:194
claw::graphic::image::swap
void swap(image &that)
Swap the content of two images.
Definition image.cpp:138
claw::graphic::image::image
image()
Constructor. Creates an image without datas.
Definition image.cpp:106
functional.hpp
Some function object classes.
gif.hpp
Image class for gif files.
std::swap
void swap(claw::graphic::gif &a, claw::graphic::gif &b)
Swap the content of two gifs.
Definition gif.cpp:235