sprint 1-alpha
|
00001 /****************************************************************************** 00002 * SPRINT::image 00003 * 00004 * Copyright (C) 2005-2011 Paolo Medici <www.pmx.it> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 * 00020 *******************************************************************************/ 00021 00022 #ifndef _SPRINT_IMAGE_H 00023 #define _SPRINT_IMAGE_H 00024 00029 #include <sprint/container/shared_ptr.h> 00030 #include <sprint/image/types.h> 00031 #include <sprint/image/imageview.h> 00032 #include <sprint/cpptraits.h> 00033 00034 namespace sprint { 00035 00036 // fw 00037 struct iimage; 00038 class image; 00039 00040 /***** Defaul alloc ****************/ 00041 00043 void delete_heap_image_buffer(iimage *); 00045 void alloc_heap_image_buffer(iimage *); 00047 void dummy_image_buffer(iimage *); 00048 00050 struct iimage: public sprint::sharable, public sprint::uncopiable, public sprint::imageview { 00051 public: 00052 00055 void (* release)(iimage *obj); 00056 00057 public: 00059 iimage() : release(dummy_image_buffer) { } 00060 00068 iimage(unsigned int width, unsigned int height, unsigned int type) : release(dummy_image_buffer) 00069 { 00070 realloc(width, height, type); 00071 } 00072 00074 ~iimage() { this->release(this); } 00075 00077 void realloc(unsigned int swidth, unsigned int sheight, long sstride, unsigned int stype); 00079 void realloc(unsigned int swidth, unsigned int sheight, long sstride, unsigned int stype, unsigned int spalettetype); 00080 00082 void realloc(unsigned int swidth, unsigned int sheight, unsigned int stype) 00083 { 00084 realloc(swidth, sheight, image_byte_per_pixel[stype] * swidth, stype); 00085 } 00086 }; 00087 00089 void copy(sprint::iimage& dst, const sprint::imageview & src); 00090 00092 void copy(sprint::iimage& dst, const sprint::imageview & src, int x0, int y0, int x1, int y1); 00093 00101 class image { 00102 00104 imageview view; 00105 00107 sprint::shared_ptr<iimage> m_source; 00108 00109 public: 00110 00116 image(iimage *src) : view(*src), m_source(src) { } 00118 image(iimage * src, int x0, int y0, int x1, int y1); 00119 00120 ~image() { } 00121 00123 inline unsigned int width() const { return view.width; } 00125 inline unsigned int height() const { return view.height; } 00127 inline unsigned int bpp() const { return view.bpp; } 00129 inline unsigned int type() const { return view.type; } 00131 inline long stride() const { return view.stride; } 00132 00134 inline bool unique() const { return m_source->use_count() == 1; } 00136 inline long use_count() const { return m_source->use_count(); } 00137 00139 void be_unique(); 00140 00142 void restore() { view = *m_source; } 00143 00145 image clone() const { 00146 image i(new iimage); 00147 copy(*i.m_source, view); 00148 return i; 00149 } 00150 00152 operator const imageview & () const { return view; } 00154 operator iimage & () const { return *m_source; } 00155 }; 00156 00157 00158 } // sprint 00159 00160 #endif