Simple Image Loading LibrarY 0.1.0
SILLYJPGImageContext.cpp
1/***********************************************************************
2 filename: SILLYJPGImageContext.cpp
3 created: 11 Jun 2006
4 author: Olivier Delannoy
5
6 purpose: Definition of the JPGImageContext class 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/SILLYJPGImageContext.h"
35
36#ifndef SILLY_OPT_INLINE
37#define inline
38#include "loaders/SILLYJPGImageContext.icpp"
39#undef inline
40#endif
41
42#include <jpeglib.h>
43
44// Start section of namespace SILLY
45namespace SILLY
46{
47
48
49void JPG_init_source(j_decompress_ptr cinfo)
50{
51 // Nothing to do
52}
53
54boolean JPG_fill_input_buffer(j_decompress_ptr cinfo)
55{
56 JPGImageContext* jpg = reinterpret_cast<JPGImageContext*>(cinfo->client_data);
57 cinfo->src->next_input_byte = jpg->d_source->getDataPtr();
58 cinfo->src->bytes_in_buffer = jpg->d_source->getSize();
59 return TRUE;
60}
61
62void JPG_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
63{
64 if (num_bytes > 0)
65 {
66 cinfo->src->next_input_byte += (size_t)num_bytes;
67 cinfo->src->bytes_in_buffer -= (size_t)num_bytes;
68 }
69}
70
71void JPG_term_source(j_decompress_ptr cinfo)
72{
73 // Nothing to do
74}
75
76void JPG_error_exit(j_common_ptr cinfo)
77{
78 JPGImageContext* jpg = reinterpret_cast<JPGImageContext*>(cinfo->client_data);
79 // TODO
80 longjmp(jpg->setjmp_buffer, 1);
81
82}
83
84void JPG_emit_message(j_common_ptr cinfo, int msg_level)
85{
86 // Ignore
87}
88
89
90JPGImageContext::JPGImageContext()
91 : ImageContext(0, 0)
92{
93 src_mgr.bytes_in_buffer = 0;
94 src_mgr.next_input_byte = 0;
95 src_mgr.init_source = JPG_init_source;
96 src_mgr.fill_input_buffer = JPG_fill_input_buffer;
97 src_mgr.skip_input_data = JPG_skip_input_data;
98 src_mgr.resync_to_restart = jpeg_resync_to_restart;
99 src_mgr.term_source = JPG_term_source;
100 jpeg_create_decompress(&cinfo);
101 cinfo.src = &src_mgr;
102 cinfo.client_data = this;
103 cinfo.err = jpeg_std_error(&d_error_mgr);
104 d_error_mgr.error_exit = JPG_error_exit;
105
106}
107
108
109JPGImageContext::~JPGImageContext()
110{
111 jpeg_destroy_decompress(&cinfo);
112}
113
114
115void JPGImageContext::setImageSize()
116{
117 setWidth(cinfo.output_width);
118 setHeight(cinfo.output_height);
119}
120
121} // End section of namespace SILLY
Simple Image Loading LibrarY namespace.
Image Context for JPG image loader.
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.
Store the data needed by an ImageLoader object during the parsing of an image.