Browse Source

Made ImageReference data pointer constant.

ImageReference is supposed to be wrapper around existing data array of
some type which is passed to Magnum functions. Thus modifying the
original data array (which must be kept somewhere for proper deletion)
is much better option than casting the pointer returned by data() to
some proper type and then operating on that. Hopefully this won't break
any existing code.
pull/34/head
Vladimír Vondruš 13 years ago
parent
commit
3b03da5d5e
  1. 12
      src/ImageReference.h
  2. 3
      src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp

12
src/ImageReference.h

@ -48,7 +48,6 @@ to change image properties, only data pointer.
Interchangeable with Image, BufferImage or Trade::ImageData. Interchangeable with Image, BufferImage or Trade::ImageData.
@see ImageReference1D, ImageReference2D, ImageReference3D @see ImageReference1D, ImageReference2D, ImageReference3D
@todo Provide const version somewhat
*/ */
template<UnsignedInt dimensions> class ImageReference: public AbstractImage { template<UnsignedInt dimensions> class ImageReference: public AbstractImage {
public: public:
@ -61,7 +60,7 @@ template<UnsignedInt dimensions> class ImageReference: public AbstractImage {
* @param size %Image size * @param size %Image size
* @param data %Image data * @param data %Image data
*/ */
constexpr explicit ImageReference(ColorFormat format, ColorType type, const typename DimensionTraits<Dimensions, Int>::VectorType& size, void* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast<unsigned char*>(data)) {} constexpr explicit ImageReference(ColorFormat format, ColorType type, const typename DimensionTraits<Dimensions, Int>::VectorType& size, const void* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast<const unsigned char*>(data)) {}
/** /**
* @brief Constructor * @brief Constructor
@ -78,8 +77,7 @@ template<UnsignedInt dimensions> class ImageReference: public AbstractImage {
constexpr typename DimensionTraits<Dimensions, Int>::VectorType size() const { return _size; } constexpr typename DimensionTraits<Dimensions, Int>::VectorType size() const { return _size; }
/** @brief Pointer to raw data */ /** @brief Pointer to raw data */
unsigned char* data() { return _data; } constexpr const unsigned char* data() const { return _data; }
constexpr const unsigned char* data() const { return _data; } /**< @overload */
/** /**
* @brief Set image data * @brief Set image data
@ -89,13 +87,13 @@ template<UnsignedInt dimensions> class ImageReference: public AbstractImage {
* passed in constructor. The data are not copied nor deleted on * passed in constructor. The data are not copied nor deleted on
* destruction. * destruction.
*/ */
void setData(void* data) { void setData(const void* data) {
_data = reinterpret_cast<unsigned char*>(data); _data = reinterpret_cast<const unsigned char*>(data);
} }
private: private:
Math::Vector<Dimensions, Int> _size; Math::Vector<Dimensions, Int> _size;
unsigned char* _data; const unsigned char* _data;
}; };
/** @brief One-dimensional image wrapper */ /** @brief One-dimensional image wrapper */

3
src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp

@ -49,8 +49,7 @@ class TgaImageConverterTest: public TestSuite::Tester {
}; };
namespace { namespace {
/** @todo `const` when ImageReference is sane */ constexpr const char originalData[] = {
char originalData[] = {
1, 2, 3, 2, 3, 4, 1, 2, 3, 2, 3, 4,
3, 4, 5, 4, 5, 6, 3, 4, 5, 4, 5, 6,
5, 6, 7, 6, 7, 8 5, 6, 7, 6, 7, 8

Loading…
Cancel
Save