PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: ImageData.h * 00003 * 00004 * Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/) 00005 * 00006 * This file is part of PixelLight. 00007 * 00008 * PixelLight is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * PixelLight is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with PixelLight. If not, see <http://www.gnu.org/licenses/>. 00020 \*********************************************************/ 00021 00022 00023 #ifndef __PLGRAPHICS_IMAGEDATA_H__ 00024 #define __PLGRAPHICS_IMAGEDATA_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include <PLCore/Core/RefCount.h> 00032 #include <PLMath/Vector3i.h> 00033 #include "PLGraphics/PLGraphics.h" 00034 00035 00036 //[-------------------------------------------------------] 00037 //[ Namespace ] 00038 //[-------------------------------------------------------] 00039 namespace PLGraphics { 00040 00041 00042 //[-------------------------------------------------------] 00043 //[ Forward declarations ] 00044 //[-------------------------------------------------------] 00045 class ImagePalette; 00046 00047 00048 //[-------------------------------------------------------] 00049 //[ Classes ] 00050 //[-------------------------------------------------------] 00051 /** 00052 * @brief 00053 * Image data, contains the actual data of an image buffer 00054 * 00055 * @note 00056 * - Implementation of the proxy design pattern, this class is the real subject 00057 */ 00058 class ImageData : protected PLCore::RefCount<ImageData> { 00059 00060 00061 //[-------------------------------------------------------] 00062 //[ Friends ] 00063 //[-------------------------------------------------------] 00064 friend class ImageBuffer; 00065 00066 00067 //[-------------------------------------------------------] 00068 //[ Private functions ] 00069 //[-------------------------------------------------------] 00070 private: 00071 /** 00072 * @brief 00073 * Constructor 00074 */ 00075 inline ImageData(); 00076 00077 /** 00078 * @brief 00079 * Copy constructor 00080 * 00081 * @param[in] cSource 00082 * Source to copy from 00083 */ 00084 ImageData(const ImageData &cSource); 00085 00086 /** 00087 * @brief 00088 * Destructor 00089 */ 00090 inline virtual ~ImageData(); 00091 00092 /** 00093 * @brief 00094 * Assignment operator 00095 * 00096 * @param[in] cSource 00097 * Source to copy from 00098 * 00099 * @return 00100 * Reference to this object 00101 */ 00102 PLGRAPHICS_API ImageData &operator =(const ImageData &cSource); 00103 00104 /** 00105 * @brief 00106 * Create image 00107 * 00108 * @param[in] nDataFormat 00109 * Desired data format 00110 * @param[in] nColorFormat 00111 * Desired color format 00112 * @param[in] vSize 00113 * Image size 00114 * @param[in] nCompression 00115 * Compression type 00116 * 00117 * @remarks 00118 * Please note that a call to Create() will not immediately create the image buffer itself. 00119 * The image buffer is created on the first call to GetData() or GetCompressedData() respectively. 00120 */ 00121 PLGRAPHICS_API void CreateImage(EDataFormat nDataFormat, EColorFormat nColorFormat, const PLMath::Vector3i &vSize, ECompression nCompression = CompressionNone); 00122 00123 /** 00124 * @brief 00125 * Clear data 00126 */ 00127 PLGRAPHICS_API void Clear(); 00128 00129 /** 00130 * @brief 00131 * Create a test image 00132 * 00133 * @param[in] nTestImage 00134 * ID of test image 00135 * 00136 * @remarks 00137 * Only 2D and 3D test images are allowed here. For images containing more than 00138 * one image buffer, you have to use Image::CreateTestImage(). 00139 */ 00140 PLGRAPHICS_API void CreateTestImage(ETestImage nTestImage = TestImage2DSimple); 00141 00142 /** 00143 * @brief 00144 * Get data format 00145 * 00146 * @return 00147 * Data format 00148 */ 00149 inline EDataFormat GetDataFormat() const; 00150 00151 /** 00152 * @brief 00153 * Get color format 00154 * 00155 * @return 00156 * Color format 00157 */ 00158 inline EColorFormat GetColorFormat() const; 00159 00160 /** 00161 * @brief 00162 * Get compression type 00163 * 00164 * @return 00165 * Compression type 00166 */ 00167 inline ECompression GetCompression() const; 00168 00169 /** 00170 * @brief 00171 * Set compression type 00172 * 00173 * @param[in] nCompression 00174 * Compression type 00175 * 00176 * @remarks 00177 * This will invalidate the compressed image data buffer 00178 */ 00179 PLGRAPHICS_API void SetCompression(ECompression nCompression); 00180 00181 /** 00182 * @brief 00183 * Get image size 00184 * 00185 * @return 00186 * Size of image 00187 */ 00188 inline PLMath::Vector3i GetSize() const; 00189 00190 /** 00191 * @brief 00192 * Check if uncompressed or compressed data is available 00193 * 00194 * @return 00195 * 'true' if image data is available, else 'false' 00196 */ 00197 inline bool HasAnyData() const; 00198 00199 /** 00200 * @brief 00201 * Check if uncompressed data is available 00202 * 00203 * @return 00204 * 'true' if image data is available, else 'false' 00205 */ 00206 inline bool HasData() const; 00207 00208 /** 00209 * @brief 00210 * Get size of image data 00211 * 00212 * @return 00213 * Size of image data in bytes 00214 */ 00215 inline PLCore::uint32 GetDataSize() const; 00216 00217 /** 00218 * @brief 00219 * Get image data 00220 * 00221 * @return 00222 * Pointer to image data, a null pointer on error 00223 * 00224 * @remarks 00225 * If the image contains no uncompressed data, but compressed image data is available the data, 00226 * will be decompressed automatically and stored in the decompressed image buffer this method returns. 00227 */ 00228 PLGRAPHICS_API const PLCore::uint8 *GetData() const; 00229 PLGRAPHICS_API PLCore::uint8 *GetData(); 00230 00231 /** 00232 * @brief 00233 * Check if compressed data is available 00234 * 00235 * @return 00236 * 'true' if compressed image data is available, else 'false' 00237 */ 00238 inline bool HasCompressedData() const; 00239 00240 /** 00241 * @brief 00242 * Get size of compressed image data 00243 * 00244 * @return 00245 * Size of compressed image data in bytes 00246 */ 00247 inline PLCore::uint32 GetCompressedDataSize() const; 00248 00249 /** 00250 * @brief 00251 * Get compressed image data 00252 * 00253 * @return 00254 * Pointer to compressed image data, a null pointer on error 00255 */ 00256 PLGRAPHICS_API const PLCore::uint8 *GetCompressedData() const; 00257 PLGRAPHICS_API PLCore::uint8 *GetCompressedData(); 00258 00259 /** 00260 * @brief 00261 * Compress image data 00262 * 00263 * @remarks 00264 * If the image contains uncompressed image data, the data will be 00265 * compressed and stored in the compressed image buffer. 00266 */ 00267 PLGRAPHICS_API bool Compress(); 00268 00269 /** 00270 * @brief 00271 * Decompress image data 00272 * 00273 * @remarks 00274 * If the image contains compressed image data, the data will be 00275 * decompressed and stored in the decompressed image buffer. 00276 */ 00277 PLGRAPHICS_API bool Decompress(); 00278 00279 /** 00280 * @brief 00281 * Set color palette 00282 * 00283 * @param[in] pPalette 00284 * Pointer to color palette, or a null pointer if the image has no palette 00285 */ 00286 PLGRAPHICS_API void SetPalette(ImagePalette *pPalette); 00287 00288 /** 00289 * @brief 00290 * Get color palette 00291 * 00292 * @return 00293 * Pointer to color palette, or a null pointer if the image has no palette 00294 */ 00295 inline const ImagePalette *GetPalette() const; 00296 inline ImagePalette *GetPalette(); 00297 00298 /** 00299 * @brief 00300 * Copy provided uncompressed image data into this image data 00301 * 00302 * @param[in] pnData 00303 * Data to copy into this image data, must have enough bytes to fill the whole image! The given pointer must be valid! 00304 */ 00305 PLGRAPHICS_API void CopyData(const PLCore::uint8 *pnData); 00306 00307 /** 00308 * @brief 00309 * Let this image data takeover provided uncompressed image data 00310 * 00311 * @param[in] pnData 00312 * Pointer to the image data to be taken over by this image data, must have enough bytes to fill the whole image data! The given pointer must be valid! 00313 */ 00314 PLGRAPHICS_API void TakeoverData(PLCore::uint8 *pnData); 00315 00316 /** 00317 * @brief 00318 * Let this image data share provided uncompressed image data 00319 * 00320 * @param[in] pnData 00321 * Pointer to the image data to be shared by this image data, must have enough bytes to fill the whole image data! The given pointer must be valid! 00322 */ 00323 PLGRAPHICS_API void ShareData(PLCore::uint8 *pnData); 00324 00325 /** 00326 * @brief 00327 * Create image buffer 00328 * 00329 * @remarks 00330 * The buffer is only created, if it doesn't exist before. So it's safe to call it 00331 * in order to get a valid buffer before accessing it, this won't destroy anything. 00332 */ 00333 inline void CreateBuffer(); 00334 00335 /** 00336 * @brief 00337 * Create compressed image buffer 00338 * 00339 * @remarks 00340 * The buffer is only created, if it doesn't exist before. So it's safe to call it 00341 * in order to get a valid buffer before accessing it, this won't destroy anything. 00342 */ 00343 inline void CreateCompressedBuffer(); 00344 00345 /** 00346 * @brief 00347 * Destroy image buffer 00348 */ 00349 inline void DestroyBuffer(); 00350 00351 /** 00352 * @brief 00353 * Destroy compressed image buffer 00354 */ 00355 inline void DestroyCompressedBuffer(); 00356 00357 /** 00358 * @brief 00359 * Calculates the size of the compressed image buffer 00360 */ 00361 void CalculateCompressedImageBufferSize(); 00362 00363 /** 00364 * @brief 00365 * Decodes a DXT color block 00366 * 00367 * @param[out] pnDestination 00368 * Receives the decompressed data 00369 * @param[in] pnSource 00370 * Compressed source data 00371 * @param[in] nBlockWidth 00372 * Width of the block, not allowed to be above 4 pixel 00373 * @param[in] nBlockHeight 00374 * Height of the block, not allowed to be above 4 pixel 00375 * @param[in] nXOffset 00376 * Current x position offset inside the image 00377 * @param[in] nYOffset 00378 * Current y position offset inside the image 00379 * @param[in] nCompression 00380 * Used compression 00381 * @param[in] nRedIndex 00382 * Index of the red color component 00383 * @param[in] nBlueIndex 00384 * Index of the blue color component 00385 * 00386 * @note 00387 * - Please note that in this method, there's no destination buffer overflow test, so correct the block size if required before calling this method! 00388 */ 00389 void DecodeDXTColorBlock(PLCore::uint8 *pnDestination, const PLCore::uint8 *pnSource, int nBlockWidth, int nBlockHeight, int nXOffset, int nYOffset, ECompression nCompression, int nRedIndex, int nBlueIndex) const; 00390 00391 /** 00392 * @brief 00393 * Decodes a DXT3 alpha block 00394 * 00395 * @param[out] pnDestination 00396 * Receives the decompressed data 00397 * @param[in] pnSource 00398 * Compressed source data 00399 * @param[in] nBlockWidth 00400 * Width of the block, not allowed to be above 4 pixel 00401 * @param[in] nBlockHeight 00402 * Height of the block, not allowed to be above 4 pixel 00403 * @param[in] nXOffset 00404 * Current x position offset inside the image 00405 * @param[in] nYOffset 00406 * Current y position offset inside the image 00407 * 00408 * @note 00409 * - Please note that in this method, there's no destination buffer overflow test, so correct the block size if required before calling this method! 00410 */ 00411 void DecodeDXT3AlphaBlock(PLCore::uint8 *pnDestination, const PLCore::uint8 *pnSource, int nBlockWidth, int nBlockHeight, int nXOffset, int nYOffset) const; 00412 00413 /** 00414 * @brief 00415 * Decodes a DXT5 alpha block 00416 * 00417 * @param[out] pnDestination 00418 * Receives the decompressed data 00419 * @param[in] pnSource 00420 * Compressed source data 00421 * @param[in] nBlockWidth 00422 * Width of the block, not allowed to be above 4 pixel 00423 * @param[in] nBlockHeight 00424 * Height of the block, not allowed to be above 4 pixel 00425 * @param[in] nXOffset 00426 * Current x position offset inside the image 00427 * @param[in] nYOffset 00428 * Current y position offset inside the image 00429 * 00430 * @note 00431 * - Please note that in this method, there's no destination buffer overflow test, so correct the block size if required before calling this method! 00432 */ 00433 void DecodeDXT5AlphaBlock(PLCore::uint8 *pnDestination, const PLCore::uint8 *pnSource, int nBlockWidth, int nBlockHeight, int nXOffset, int nYOffset) const; 00434 00435 00436 //[-------------------------------------------------------] 00437 //[ Private data ] 00438 //[-------------------------------------------------------] 00439 private: 00440 EDataFormat m_nDataFormat; /**< Data format of the image */ 00441 EColorFormat m_nColorFormat; /**< Color format of the image */ 00442 ECompression m_nCompression; /**< Compression format */ 00443 PLMath::Vector3i m_vSize; /**< Size of the image */ 00444 PLCore::uint8 *m_pData; /**< Uncompressed image data, can be a null pointer */ 00445 PLCore::uint32 m_nDataSize; /**< Size of uncompressed image data in bytes */ 00446 bool m_bDataShared; /**< If 'true', the uncompressed image data is just shared and this image data instance is not allowed to deleted it (the user keeps the image data ownership) */ 00447 PLCore::uint8 *m_pCompressedData; /**< Compressed image data, can be a null pointer */ 00448 PLCore::uint32 m_nCompressedSize; /**< Size of compressed image data in bytes */ 00449 ImagePalette *m_pPalette; /**< Color palette, can be a null pointer */ 00450 00451 00452 }; 00453 00454 00455 //[-------------------------------------------------------] 00456 //[ Namespace ] 00457 //[-------------------------------------------------------] 00458 } // PLGraphics 00459 00460 00461 //[-------------------------------------------------------] 00462 //[ Implementation ] 00463 //[-------------------------------------------------------] 00464 #include "PLGraphics/Image/ImageData.inl" 00465 00466 00467 #endif // __PLGRAPHICS_IMAGEDATA_H__
|