Browse Source

Reordered *Image parameters.

First format, then type, then size, then data. Seems more intuitive this
way, also the data are laid out in the structure this way.
pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
eb3de49e75
  1. 2
      src/AbstractFramebuffer.cpp
  2. 2
      src/AbstractTexture.cpp
  3. 2
      src/Image.cpp
  4. 10
      src/Image.h
  5. 8
      src/ImageReference.h
  6. 6
      src/Test/ImageTest.cpp
  7. 6
      src/Trade/ImageData.h
  8. 2
      src/Trade/Test/AbstractImageConverterTest.cpp
  9. 8
      src/Trade/Test/ImageDataTest.cpp

2
src/AbstractFramebuffer.cpp

@ -150,7 +150,7 @@ void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, Ima
const std::size_t dataSize = image.pixelSize()*size.product(); const std::size_t dataSize = image.pixelSize()*size.product();
char* const data = new char[dataSize]; char* const data = new char[dataSize];
readImplementation(offset, size, image.format(), image.type(), dataSize, data); readImplementation(offset, size, image.format(), image.type(), dataSize, data);
image.setData(size, image.format(), image.type(), data); image.setData(image.format(), image.type(), size, data);
} }
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2

2
src/AbstractTexture.cpp

@ -954,7 +954,7 @@ template<UnsignedInt dimensions> void AbstractTexture::image(GLenum target, GLin
const std::size_t dataSize = size.product()*image.pixelSize(); const std::size_t dataSize = size.product()*image.pixelSize();
char* data = new char[dataSize]; char* data = new char[dataSize];
(this->*getImageImplementation)(target, level, image.format(), image.type(), dataSize, data); (this->*getImageImplementation)(target, level, image.format(), image.type(), dataSize, data);
image.setData(size, image.format(), image.type(), data); image.setData(image.format(), image.type(), size, data);
} }
template void AbstractTexture::image<1>(GLenum, GLint, Image<1>&); template void AbstractTexture::image<1>(GLenum, GLint, Image<1>&);

2
src/Image.cpp

@ -26,7 +26,7 @@
namespace Magnum { namespace Magnum {
template<UnsignedInt dimensions> void Image<dimensions>::setData(const typename DimensionTraits<Dimensions, Int>::VectorType& size, ImageFormat format, ImageType type, void* data) { template<UnsignedInt dimensions> void Image<dimensions>::setData(ImageFormat format, ImageType type, const typename DimensionTraits<Dimensions, Int>::VectorType& size, void* data) {
delete[] _data; delete[] _data;
_format = format; _format = format;
_type = type; _type = type;

10
src/Image.h

@ -45,15 +45,15 @@ template<UnsignedInt dimensions> class Image: public AbstractImage {
/** /**
* @brief Constructor * @brief Constructor
* @param size %Image size
* @param format Format of pixel data * @param format Format of pixel data
* @param type Data type of pixel data * @param type Data type of pixel data
* @param size %Image size
* @param data %Image data * @param data %Image data
* *
* Note that the image data are not copied on construction, but they * Note that the image data are not copied on construction, but they
* are deleted on class destruction. * are deleted on class destruction.
*/ */
explicit Image(const typename DimensionTraits<Dimensions, Int>::VectorType& size, ImageFormat format, ImageType type, void* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast<unsigned char*>(data)) {} explicit Image(ImageFormat format, ImageType type, const typename DimensionTraits<Dimensions, Int>::VectorType& size, void* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast<unsigned char*>(data)) {}
/** /**
* @brief Constructor * @brief Constructor
@ -96,15 +96,15 @@ template<UnsignedInt dimensions> class Image: public AbstractImage {
/** /**
* @brief Set image data * @brief Set image data
* @param size %Image size
* @param format Format of pixel data * @param format Format of pixel data
* @param type Data type of pixel data * @param type Data type of pixel data
* @param size %Image size
* @param data %Image data * @param data %Image data
* *
* Deletes previous data and replaces them with new. Note that the * Deletes previous data and replaces them with new. Note that the
* data are not copied, but they are deleted on destruction. * data are not copied, but they are deleted on destruction.
*/ */
void setData(const typename DimensionTraits<Dimensions, Int>::VectorType& size, ImageFormat format, ImageType type, void* data); void setData(ImageFormat format, ImageType type, const typename DimensionTraits<Dimensions, Int>::VectorType& size, void* data);
private: private:
Math::Vector<Dimensions, Int> _size; Math::Vector<Dimensions, Int> _size;
@ -133,7 +133,7 @@ template<UnsignedInt dimensions> inline Image<dimensions>& Image<dimensions>::op
} }
template<UnsignedInt dimensions> inline Image<dimensions>::operator ImageReference<dimensions>() const { template<UnsignedInt dimensions> inline Image<dimensions>::operator ImageReference<dimensions>() const {
return ImageReference<dimensions>(_size, this->format(), this->type(), _data); return ImageReference<dimensions>(this->format(), this->type(), _size, _data);
} }
} }

8
src/ImageReference.h

@ -55,26 +55,26 @@ template<UnsignedInt dimensions> class ImageReference: public AbstractImage {
/** /**
* @brief Constructor * @brief Constructor
* @param size %Image size
* @param format Format of pixel data * @param format Format of pixel data
* @param type Data type of pixel data * @param type Data type of pixel data
* @param size %Image size
* @param data %Image data * @param data %Image data
* *
* Note that the image data are not copied on construction, but they * Note that the image data are not copied on construction, but they
* are deleted on class destruction. * are deleted on class destruction.
*/ */
constexpr explicit ImageReference(const typename DimensionTraits<Dimensions, Int>::VectorType& size, ImageFormat format, ImageType type, void* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast<unsigned char*>(data)) {} constexpr explicit ImageReference(ImageFormat format, ImageType type, const typename DimensionTraits<Dimensions, Int>::VectorType& size, void* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast<unsigned char*>(data)) {}
/** /**
* @brief Constructor * @brief Constructor
* @param size %Image size
* @param format Format of pixel data * @param format Format of pixel data
* @param type Data type of pixel data * @param type Data type of pixel data
* @param size %Image size
* *
* Data pointer is set to zero, call setData() to fill the image with * Data pointer is set to zero, call setData() to fill the image with
* data. * data.
*/ */
constexpr explicit ImageReference(const typename DimensionTraits<Dimensions, Int>::VectorType& size, ImageFormat format, ImageType type): AbstractImage(format, type), _size(size), _data(nullptr) {} constexpr explicit ImageReference(ImageFormat format, ImageType type, const typename DimensionTraits<Dimensions, Int>::VectorType& size): AbstractImage(format, type), _size(size), _data(nullptr) {}
/** @brief %Image size */ /** @brief %Image size */
constexpr typename DimensionTraits<Dimensions, Int>::VectorType size() const { return _size; } constexpr typename DimensionTraits<Dimensions, Int>::VectorType size() const { return _size; }

6
src/Test/ImageTest.cpp

@ -46,7 +46,7 @@ ImageTest::ImageTest() {
void ImageTest::moveConstructor() { void ImageTest::moveConstructor() {
unsigned char* data = new unsigned char[3]; unsigned char* data = new unsigned char[3];
Image2D a({1, 3}, ImageFormat::Red, ImageType::UnsignedByte, data); Image2D a(ImageFormat::Red, ImageType::UnsignedByte, {1, 3}, data);
Image2D b(std::move(a)); Image2D b(std::move(a));
CORRADE_VERIFY(!a.data()); CORRADE_VERIFY(!a.data());
@ -58,7 +58,7 @@ void ImageTest::moveConstructor() {
void ImageTest::moveAssignment() { void ImageTest::moveAssignment() {
unsigned char* data = new unsigned char[3]; unsigned char* data = new unsigned char[3];
Image2D a({1, 3}, ImageFormat::Red, ImageType::UnsignedByte, data); Image2D a(ImageFormat::Red, ImageType::UnsignedByte, {1, 3}, data);
Image2D b(ImageFormat::Red, ImageType::UnsignedByte); Image2D b(ImageFormat::Red, ImageType::UnsignedByte);
b = std::move(a); b = std::move(a);
@ -71,7 +71,7 @@ void ImageTest::moveAssignment() {
void ImageTest::toReference() { void ImageTest::toReference() {
unsigned char* data = new unsigned char[3]; unsigned char* data = new unsigned char[3];
Image2D a({1, 3}, ImageFormat::Red, ImageType::UnsignedByte, data); Image2D a(ImageFormat::Red, ImageType::UnsignedByte, {1, 3}, data);
ImageReference2D b = a; ImageReference2D b = a;
CORRADE_COMPARE(b.format(), ImageFormat::Red); CORRADE_COMPARE(b.format(), ImageFormat::Red);

6
src/Trade/ImageData.h

@ -45,15 +45,15 @@ template<UnsignedInt dimensions> class ImageData: public AbstractImage {
/** /**
* @brief Constructor * @brief Constructor
* @param size %Image size
* @param format Format of pixel data * @param format Format of pixel data
* @param type Data type of pixel data * @param type Data type of pixel data
* @param size %Image size
* @param data %Image data * @param data %Image data
* *
* Note that the image data are not copied on construction, but they * Note that the image data are not copied on construction, but they
* are deleted on class destruction. * are deleted on class destruction.
*/ */
explicit ImageData(const typename DimensionTraits<Dimensions, Int>::VectorType& size, ImageFormat format, ImageType type, void* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast<unsigned char*>(data)) {} explicit ImageData(ImageFormat format, ImageType type, const typename DimensionTraits<Dimensions, Int>::VectorType& size, void* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast<unsigned char*>(data)) {}
/** @brief Copying is not allowed */ /** @brief Copying is not allowed */
ImageData(const ImageData<dimensions>&& other) = delete; ImageData(const ImageData<dimensions>&& other) = delete;
@ -111,7 +111,7 @@ template<UnsignedInt dimensions> inline ImageData<dimensions>& ImageData<dimensi
} }
template<UnsignedInt dimensions> inline ImageData<dimensions>::operator ImageReference<dimensions>() const { template<UnsignedInt dimensions> inline ImageData<dimensions>::operator ImageReference<dimensions>() const {
return ImageReference<dimensions>(_size, this->format(), this->type(), _data); return ImageReference<dimensions>(this->format(), this->type(), _size, _data);
} }
}} }}

2
src/Trade/Test/AbstractImageConverterTest.cpp

@ -64,7 +64,7 @@ void AbstractImageConverterTest::exportToFile() {
/* doExportToFile() should call doExportToData() */ /* doExportToFile() should call doExportToData() */
DataExporter exporter; DataExporter exporter;
Image2D image({0xfe, 0xed}, ImageFormat::RGBA, ImageType::UnsignedByte, nullptr); Image2D image(ImageFormat::RGBA, ImageType::UnsignedByte, {0xfe, 0xed}, nullptr);
CORRADE_VERIFY(exporter.exportToFile(&image, Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out"))); CORRADE_VERIFY(exporter.exportToFile(&image, Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out")));
CORRADE_COMPARE_AS(Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out"), CORRADE_COMPARE_AS(Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out"),
"\xFE\xED", TestSuite::Compare::FileToString); "\xFE\xED", TestSuite::Compare::FileToString);

8
src/Trade/Test/ImageDataTest.cpp

@ -46,7 +46,7 @@ ImageDataTest::ImageDataTest() {
void ImageDataTest::moveConstructor() { void ImageDataTest::moveConstructor() {
unsigned char* data = new unsigned char[3]; unsigned char* data = new unsigned char[3];
Trade::ImageData2D a({1, 3}, ImageFormat::Red, ImageType::UnsignedByte, data); Trade::ImageData2D a(ImageFormat::Red, ImageType::UnsignedByte, {1, 3}, data);
Trade::ImageData2D b(std::move(a)); Trade::ImageData2D b(std::move(a));
CORRADE_VERIFY(!a.data()); CORRADE_VERIFY(!a.data());
@ -58,9 +58,9 @@ void ImageDataTest::moveConstructor() {
void ImageDataTest::moveAssignment() { void ImageDataTest::moveAssignment() {
unsigned char* data = new unsigned char[3]; unsigned char* data = new unsigned char[3];
Trade::ImageData2D a({1, 3}, ImageFormat::Red, ImageType::UnsignedByte, data); Trade::ImageData2D a(ImageFormat::Red, ImageType::UnsignedByte, {1, 3}, data);
Trade::ImageData2D b({}, ImageFormat::Red, ImageType::UnsignedByte, nullptr); Trade::ImageData2D b(ImageFormat::Red, ImageType::UnsignedByte, {}, nullptr);
b = std::move(a); b = std::move(a);
CORRADE_VERIFY(!a.data()); CORRADE_VERIFY(!a.data());
CORRADE_COMPARE(b.format(), ImageFormat::Red); CORRADE_COMPARE(b.format(), ImageFormat::Red);
@ -71,7 +71,7 @@ void ImageDataTest::moveAssignment() {
void ImageDataTest::toReference() { void ImageDataTest::toReference() {
unsigned char* data = new unsigned char[3]; unsigned char* data = new unsigned char[3];
Trade::ImageData2D a({1, 3}, ImageFormat::Red, ImageType::UnsignedByte, data); Trade::ImageData2D a(ImageFormat::Red, ImageType::UnsignedByte, {1, 3}, data);
ImageReference2D b = a; ImageReference2D b = a;
CORRADE_COMPARE(b.format(), ImageFormat::Red); CORRADE_COMPARE(b.format(), ImageFormat::Red);

Loading…
Cancel
Save