D:/Projects/CEGUI/Silly/src/loaders/SILLYPNGImageContext.cpp

00001 /***********************************************************************
00002     filename:   SILLYPNGImageContext.cpp
00003     created:    11 Jun 2006
00004     author:     Olivier Delannoy 
00005 
00006     purpose:    Definition of PNGImageContext methods  
00007 *************************************************************************/
00008 /***************************************************************************
00009  *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
00010  *
00011  *   Permission is hereby granted, free of charge, to any person obtaining
00012  *   a copy of this software and associated documentation files (the
00013  *   "Software"), to deal in the Software without restriction, including
00014  *   without limitation the rights to use, copy, modify, merge, publish,
00015  *   distribute, sublicense, and/or sell copies of the Software, and to
00016  *   permit persons to whom the Software is furnished to do so, subject to
00017  *   the following conditions:
00018  *
00019  *   The above copyright notice and this permission notice shall be
00020  *   included in all copies or substantial portions of the Software.
00021  *
00022  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00023  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00024  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00025  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
00026  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00027  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00028  *   OTHER DEALINGS IN THE SOFTWARE.
00029  ***************************************************************************/
00030 #ifdef HAVE_CONFIG_H
00031 #include <config.h>
00032 #endif
00033 
00034 #include "loaders/SILLYPNGImageContext.h"
00035 
00036 #ifndef SILLY_OPT_INLINE
00037 #define inline 
00038 #include "loaders/SILLYPNGImageContext.icpp"
00039 #undef inline
00040 #endif
00041 #include <string.h>
00042 
00043 // Start section of namespace SILLY
00044 namespace SILLY
00045 {
00046 int PNGImageContext::read(png_bytep data, png_size_t length)
00047 {
00048     //printf("PNG Read: %d bytes offset: %d, size %d\n", 
00049     //       length, d_offset, d_data->getSize());
00050     
00051     if (d_offset + length > d_data->getSize())
00052         return -1;
00053     memcpy(data, d_data->getDataPtr() + d_offset, length);
00054     d_offset += length;
00055     return length;
00056 }
00057 
00058   
00059 PNGImageContext::PNGImageContext(DataSource* data)
00060     : ImageContext(0,0), d_offset(0), d_data(data), d_png_ptr(0), d_info_ptr(0)
00061 {
00062     
00063 }
00064 
00065 PNGImageContext::~PNGImageContext()
00066 {
00067     if (d_info_ptr)
00068         png_destroy_read_struct(&d_png_ptr, &d_info_ptr, 0);    
00069     if (d_png_ptr)
00070         png_destroy_read_struct(&d_png_ptr, 0, 0);    
00071 }
00072 
00073 
00074 void PNGImageContext::setImageSize()
00075 {
00076     setWidth(png_get_image_width(d_png_ptr, d_info_ptr));
00077     setHeight(png_get_image_height(d_png_ptr, d_info_ptr));
00078     
00079 }
00080 
00081 
00082 } // End section of namespace SILLY 

Generated on Sun Apr 6 14:47:06 2008 for Simple Image Loading LibrarY by  doxygen 1.5.2