1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
13 /*---------------------------------------------------------------------------*\
16 * This library is free software; you can redistribute it and/or modify it *
17 * under the terms of the GNU Library General Public License as published *
18 * by the Free Software Foundation, version 2. *
20 * This library is distributed in the hope that it will be useful, but *
21 * WITHOUT ANY WARRANTY; without even the implied warranty of *
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
23 * Library General Public License for more details. *
25 * You should have received a copy of the GNU Library General Public *
26 * License along with this library; if not, write to the Free Software *
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
29 \*---------------------------------------------------------------------------*/
31 /*---------------------------------------------------------------------------*\
39 \*---------------------------------------------------------------------------*/
43 template<class SrcImageStore> inline
44 bool createComposedImage (const SrcImageStore &imageVec,
46 SliceDataType sliceDataType,
49 UInt32 dataSize, i, n = imageVec.size();
54 Image::PixelFormat pf = Image::OSG_INVALID_PF;
55 Image::Type dt = Image::OSG_INVALID_IMAGEDATATYPE;
56 bool needColor = false, needAlpha = false, needCopy = false;
57 ImageUnrecPtr copy = Image::create();
58 UInt32 depth, frameCount, sideCount;
62 for (i = 0; i < n; i++)
66 pf = Image::PixelFormat(imageVec[0]->getPixelFormat());
67 dt = Image::Type(imageVec[0]->getDataType());
68 w = imageVec[0]->getWidth();
69 h = imageVec[0]->getHeight();
70 needAlpha = imageVec[0]->hasAlphaChannel();
71 needColor = imageVec[0]->hasColorChannel();
75 needAlpha |= imageVec[i]->hasAlphaChannel();
76 needColor |= imageVec[i]->hasColorChannel();
77 if (Image::PixelFormat(imageVec[i]->getPixelFormat()) != pf)
80 FWARNING (( "Image has different PF while composing\n" ));
81 pf = Image::OSG_INVALID_PF;
83 if (Image::Type(imageVec[i]->getDataType()) != dt)
86 FWARNING (( "Image has different DT while composing\n" ));
87 dt = Image::OSG_INVALID_IMAGEDATATYPE;
89 if (imageVec[i]->getWidth() != w)
92 FWARNING(("Image has different width while composing\n"));
93 w = osgMax ( w, imageVec[i]->getWidth());
95 if (imageVec[i]->getHeight() != h)
98 FWARNING(("Image has different height while composing\n"));
99 h = osgMax ( h, imageVec[i]->getHeight());
104 if (pf == Image::OSG_INVALID_PF)
108 pf = OSG::Image::OSG_RGBA_PF;
110 pf = OSG::Image::OSG_RGB_PF;
113 pf = OSG::Image::OSG_LA_PF;
115 pf = OSG::Image::OSG_L_PF;
118 if (dt == Image::OSG_INVALID_IMAGEDATATYPE)
119 dt = Image::OSG_UINT8_IMAGEDATA;
121 depth = frameCount = sideCount = 1;
122 switch (sliceDataType)
137 image->set( pf, w, h, depth, 1, frameCount, 0.0,
138 0, dt, true, sideCount );
140 destData = image->editData();
141 dataSize = image->getSize() / n;
142 UInt32 bpl = dataSize / h;
147 FLOG (("Image data/type/size missmatch while composing\n"));
150 for (i = 0; i < n; i++)
154 copy->set(imageVec[i]);
155 if ( Image::PixelFormat(copy->getPixelFormat()) != pf )
157 if ( Image::Type(copy->getDataType()) != dt )
158 copy->convertDataTypeTo(dt);
159 if ( (w != copy->getWidth()) || (h != copy->getHeight()))
160 copy->scale(w,h,copy->getDepth());
161 srcData = copy->getData();
165 srcData = imageVec[i]->getData();
171 for(Int32 y = 0; y < h; ++y)
174 memcpy ( destData, srcData, bpl );
180 memcpy ( destData, srcData, dataSize );
181 destData += dataSize;
192 template<class ValueT> inline
193 void swapImageByteOrder(Image * const pImage)
198 void *pData = static_cast<void *>(pImage->editData());
199 UInt32 uiSize = pImage->getSize() / sizeof(ValueT);
201 osgSwapMem<sizeof(ValueT)>(pData, uiSize);
204 template<class ValueT, ValueT (*ConvF)(ValueT)> inline
205 void swapAndConvertImageByteOrder(Image * const pImage)
210 ValueT *pData = reinterpret_cast<ValueT *>(pImage->editData());
211 UInt32 uiSize = pImage->getSize() / sizeof(ValueT);
213 for(UInt32 i = 0; i < uiSize; ++i)
215 osgSwapMem<sizeof(ValueT)>(&pData[i], 1);
216 pData[i] = ConvF(pData[i]);
220 template<class ValueT, ValueT MinVal> inline
221 ValueT clampMin(ValueT val)
229 template<class ValueT, ValueT CompVal, ValueT ReplaceVal> inline
230 ValueT clampMin(ValueT val)
238 template<class ValueT> inline
239 ValueT doNothing(ValueT val)