Simple Image Loading LibrarY 0.1.0
SILLYPNGImageContext.cpp
1/***********************************************************************
2 filename: SILLYPNGImageContext.cpp
3 created: 11 Jun 2006
4 author: Olivier Delannoy
5
6 purpose: Definition of PNGImageContext methods
7*************************************************************************/
8/***************************************************************************
9 * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining
12 * a copy of this software and associated documentation files (the
13 * "Software"), to deal in the Software without restriction, including
14 * without limitation the rights to use, copy, modify, merge, publish,
15 * distribute, sublicense, and/or sell copies of the Software, and to
16 * permit persons to whom the Software is furnished to do so, subject to
17 * the following conditions:
18 *
19 * The above copyright notice and this permission notice shall be
20 * included in all copies or substantial portions of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
26 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 * OTHER DEALINGS IN THE SOFTWARE.
29 ***************************************************************************/
30#ifdef HAVE_CONFIG_H
31#include <config.h>
32#endif
33
34#include "loaders/SILLYPNGImageContext.h"
35
36#ifndef SILLY_OPT_INLINE
37#define inline
38#include "loaders/SILLYPNGImageContext.icpp"
39#undef inline
40#endif
41#include <string.h>
42
43// Start section of namespace SILLY
44namespace SILLY
45{
46int PNGImageContext::read(png_bytep data, png_size_t length)
47{
48 //printf("PNG Read: %d bytes offset: %d, size %d\n",
49 // length, d_offset, d_data->getSize());
50
51 if (d_offset + length > d_data->getSize())
52 return -1;
53 memcpy(data, d_data->getDataPtr() + d_offset, length);
54 d_offset += length;
55 return length;
56}
57
58
59PNGImageContext::PNGImageContext(DataSource* data)
60 : ImageContext(0,0), d_offset(0), d_data(data), d_png_ptr(0), d_info_ptr(0)
61{
62
63}
64
65PNGImageContext::~PNGImageContext()
66{
67 if (d_info_ptr)
68 png_destroy_read_struct(&d_png_ptr, &d_info_ptr, 0);
69 if (d_png_ptr)
70 png_destroy_read_struct(&d_png_ptr, 0, 0);
71}
72
73
74void PNGImageContext::setImageSize()
75{
76 setWidth(png_get_image_width(d_png_ptr, d_info_ptr));
77 setHeight(png_get_image_height(d_png_ptr, d_info_ptr));
78
79}
80
81
82} // End section of namespace SILLY
Simple Image Loading LibrarY namespace.
virtual size_t getSize() const =0
Return the size of the data.
virtual const byte * getDataPtr() const =0
Get raw access to the image data.