Browse Source

Get rid of annoying unsigned byte arrays.

`char*` is now the default type for byte arrays. Results in shorter
code, less annoyances and more convenient testing. As is the case with
Corrade, I'm not doing any compatibility/deprecation layer, as most of
these functions is not widely used anyway.
pull/87/merge
Vladimír Vondruš 11 years ago
parent
commit
fd0bfcb465
  1. 6
      src/Magnum/Audio/AbstractImporter.cpp
  2. 8
      src/Magnum/Audio/AbstractImporter.h
  3. 6
      src/Magnum/Audio/Test/AbstractImporterTest.cpp
  4. 4
      src/Magnum/Buffer.h
  5. 2
      src/Magnum/Image.cpp
  6. 16
      src/Magnum/Image.h
  7. 10
      src/Magnum/ImageReference.h
  8. 14
      src/Magnum/Test/BufferImageGLTest.cpp
  9. 8
      src/Magnum/Test/ImageReferenceTest.cpp
  10. 18
      src/Magnum/Test/ImageTest.cpp
  11. 8
      src/Magnum/Text/AbstractFont.cpp
  12. 8
      src/Magnum/Text/AbstractFont.h
  13. 32
      src/Magnum/Text/AbstractFontConverter.cpp
  14. 28
      src/Magnum/Text/AbstractFontConverter.h
  15. 16
      src/Magnum/Text/Renderer.cpp
  16. 72
      src/Magnum/Text/Test/AbstractFontConverterTest.cpp
  17. 6
      src/Magnum/Text/Test/AbstractFontTest.cpp
  18. 2
      src/Magnum/Text/Test/RendererGLTest.cpp
  19. 4
      src/Magnum/Trade/AbstractImageConverter.cpp
  20. 4
      src/Magnum/Trade/AbstractImageConverter.h
  21. 4
      src/Magnum/Trade/AbstractImporter.cpp
  22. 4
      src/Magnum/Trade/AbstractImporter.h
  23. 14
      src/Magnum/Trade/ImageData.h
  24. 7
      src/Magnum/Trade/Test/AbstractImageConverterTest.cpp
  25. 4
      src/Magnum/Trade/Test/AbstractImporterTest.cpp
  26. 12
      src/Magnum/Trade/Test/ImageDataTest.cpp
  27. 4
      src/MagnumPlugins/MagnumFont/MagnumFont.cpp
  28. 2
      src/MagnumPlugins/MagnumFont/MagnumFont.h
  29. 8
      src/MagnumPlugins/MagnumFontConverter/MagnumFontConverter.cpp
  30. 4
      src/MagnumPlugins/MagnumFontConverter/MagnumFontConverter.h
  31. 4
      src/MagnumPlugins/ObjImporter/ObjImporter.cpp
  32. 2
      src/MagnumPlugins/ObjImporter/ObjImporter.h
  33. 4
      src/MagnumPlugins/TgaImageConverter/Test/TgaImageConverterTest.cpp
  34. 4
      src/MagnumPlugins/TgaImageConverter/TgaImageConverter.cpp
  35. 2
      src/MagnumPlugins/TgaImageConverter/TgaImageConverter.h
  36. 36
      src/MagnumPlugins/TgaImporter/Test/TgaImporterTest.cpp
  37. 4
      src/MagnumPlugins/TgaImporter/TgaImporter.cpp
  38. 2
      src/MagnumPlugins/TgaImporter/TgaImporter.h
  39. 22
      src/MagnumPlugins/WavAudioImporter/Test/WavImporterTest.cpp
  40. 8
      src/MagnumPlugins/WavAudioImporter/WavImporter.cpp
  41. 6
      src/MagnumPlugins/WavAudioImporter/WavImporter.h

6
src/Magnum/Audio/AbstractImporter.cpp

@ -35,7 +35,7 @@ AbstractImporter::AbstractImporter() = default;
AbstractImporter::AbstractImporter(PluginManager::AbstractManager& manager, std::string plugin): PluginManager::AbstractPlugin(manager, std::move(plugin)) {}
bool AbstractImporter::openData(Containers::ArrayReference<const unsigned char> data) {
bool AbstractImporter::openData(Containers::ArrayReference<const char> data) {
CORRADE_ASSERT(features() & Feature::OpenData,
"Audio::AbstractImporter::openData(): feature not supported", nullptr);
@ -44,7 +44,7 @@ bool AbstractImporter::openData(Containers::ArrayReference<const unsigned char>
return isOpened();
}
void AbstractImporter::doOpenData(Containers::ArrayReference<const unsigned char>) {
void AbstractImporter::doOpenData(Containers::ArrayReference<const char>) {
CORRADE_ASSERT(false, "Audio::AbstractImporter::openData(): feature advertised but not implemented", );
}
@ -83,7 +83,7 @@ UnsignedInt AbstractImporter::frequency() const {
return doFrequency();
}
Containers::Array<unsigned char> AbstractImporter::data() {
Containers::Array<char> AbstractImporter::data() {
CORRADE_ASSERT(isOpened(), "Audio::AbstractImporter::data(): no file opened", nullptr);
return doData();
}

8
src/Magnum/Audio/AbstractImporter.h

@ -103,7 +103,7 @@ class MAGNUM_AUDIO_EXPORT AbstractImporter: public PluginManager::AbstractPlugin
* `true` on success, `false` otherwise.
* @see @ref features(), @ref openFile()
*/
bool openData(Containers::ArrayReference<const unsigned char> data);
bool openData(Containers::ArrayReference<const char> data);
/**
* @brief Open file
@ -126,7 +126,7 @@ class MAGNUM_AUDIO_EXPORT AbstractImporter: public PluginManager::AbstractPlugin
UnsignedInt frequency() const;
/** @brief Sample data */
Containers::Array<unsigned char> data();
Containers::Array<char> data();
/*@}*/
@ -142,7 +142,7 @@ class MAGNUM_AUDIO_EXPORT AbstractImporter: public PluginManager::AbstractPlugin
virtual bool doIsOpened() const = 0;
/** @brief Implementation for @ref openData() */
virtual void doOpenData(Containers::ArrayReference<const unsigned char> data);
virtual void doOpenData(Containers::ArrayReference<const char> data);
/**
* @brief Implementation for @ref openFile()
@ -162,7 +162,7 @@ class MAGNUM_AUDIO_EXPORT AbstractImporter: public PluginManager::AbstractPlugin
virtual UnsignedInt doFrequency() const = 0;
/** @brief Implementation for @ref data() */
virtual Containers::Array<unsigned char> doData() = 0;
virtual Containers::Array<char> doData() = 0;
};
}}

6
src/Magnum/Audio/Test/AbstractImporterTest.cpp

@ -53,13 +53,13 @@ void AbstractImporterTest::openFile() {
bool doIsOpened() const override { return opened; }
void doClose() override {}
void doOpenData(Containers::ArrayReference<const unsigned char> data) override {
opened = (data.size() == 1 && data[0] == 0xa5);
void doOpenData(Containers::ArrayReference<const char> data) override {
opened = (data.size() == 1 && data[0] == '\xa5');
}
Buffer::Format doFormat() const override { return {}; }
UnsignedInt doFrequency() const override { return {}; }
Corrade::Containers::Array<unsigned char> doData() override { return nullptr; }
Corrade::Containers::Array<char> doData() override { return nullptr; }
bool opened;
};

4
src/Magnum/Buffer.h

@ -951,7 +951,7 @@ class MAGNUM_EXPORT Buffer: public AbstractObject {
* @requires_gl Buffer data queries are not available in OpenGL ES.
* Use @ref Magnum::Buffer::map() "map()" instead.
*/
template<class T = unsigned char> Containers::Array<T> data();
template<class T = char> Containers::Array<T> data();
/**
* @brief Buffer subdata
@ -969,7 +969,7 @@ class MAGNUM_EXPORT Buffer: public AbstractObject {
* @requires_gl Buffer data queries are not available in OpenGL ES.
* Use @ref Magnum::Buffer::map() "map()" instead.
*/
template<class T = unsigned char> Containers::Array<T> subData(GLintptr offset, GLsizeiptr size);
template<class T = char> Containers::Array<T> subData(GLintptr offset, GLsizeiptr size);
#endif
/**

2
src/Magnum/Image.cpp

@ -32,7 +32,7 @@ template<UnsignedInt dimensions> void Image<dimensions>::setData(ColorFormat for
_format = format;
_type = type;
_size = size;
_data = reinterpret_cast<unsigned char*>(data);
_data = reinterpret_cast<char*>(data);
}
#ifndef DOXYGEN_GENERATING_OUTPUT

16
src/Magnum/Image.h

@ -54,7 +54,7 @@ template<UnsignedInt dimensions> class Image: public AbstractImage {
* Note that the image data are not copied on construction, but they
* are deleted on class destruction.
*/
explicit Image(ColorFormat format, ColorType type, const VectorTypeFor<dimensions, Int>& size, void* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast<unsigned char*>(data)) {}
explicit Image(ColorFormat format, ColorType type, const VectorTypeFor<dimensions, Int>& size, void* data): AbstractImage{format, type}, _size{size}, _data{reinterpret_cast<char*>(data)} {}
/**
* @brief Constructor
@ -64,7 +64,7 @@ template<UnsignedInt dimensions> class Image: public AbstractImage {
* Dimensions are set to zero and data pointer to `nullptr`, call
* @ref setData() to fill the image with data.
*/
/*implicit*/ Image(ColorFormat format, ColorType type): AbstractImage(format, type), _data(nullptr) {}
/*implicit*/ Image(ColorFormat format, ColorType type): AbstractImage(format, type), _data{} {}
/** @brief Copying is not allowed */
Image(const Image<dimensions>&) = delete;
@ -113,12 +113,12 @@ template<UnsignedInt dimensions> class Image: public AbstractImage {
*
* @see @ref release()
*/
template<class T = unsigned char> T* data() {
template<class T = char> T* data() {
return reinterpret_cast<T*>(_data);
}
/** @overload */
template<class T = unsigned char> const T* data() const {
template<class T = char> const T* data() const {
return reinterpret_cast<const T*>(_data);
}
@ -142,11 +142,11 @@ template<UnsignedInt dimensions> class Image: public AbstractImage {
* to default. Deleting the returned array is then user responsibility.
* @see @ref setData()
*/
unsigned char* release();
char* release();
private:
Math::Vector<Dimensions, Int> _size;
unsigned char* _data;
char* _data;
};
/** @brief One-dimensional image */
@ -180,9 +180,9 @@ const
return ImageReference<dimensions>(AbstractImage::format(), AbstractImage::type(), _size, _data);
}
template<UnsignedInt dimensions> inline unsigned char* Image<dimensions>::release() {
template<UnsignedInt dimensions> inline char* Image<dimensions>::release() {
/** @todo I need `std::exchange` NOW. */
unsigned char* const data = _data;
char* const data = _data;
_size = {};
_data = nullptr;
return data;

10
src/Magnum/ImageReference.h

@ -61,7 +61,7 @@ template<UnsignedInt dimensions> class ImageReference: public AbstractImage {
* @param size Image size
* @param data Image data
*/
constexpr explicit ImageReference(ColorFormat format, ColorType type, const VectorTypeFor<dimensions, Int>& size, const void* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast<const unsigned char*>(data)) {}
constexpr explicit ImageReference(ColorFormat format, ColorType type, const VectorTypeFor<dimensions, Int>& size, const void* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast<const char*>(data)) {}
/**
* @brief Constructor
@ -83,10 +83,10 @@ template<UnsignedInt dimensions> class ImageReference: public AbstractImage {
}
/** @brief Pointer to raw data */
constexpr const unsigned char* data() const { return _data; }
constexpr const char* data() const { return _data; }
/** @overload */
template<class T = unsigned char> const T* data() const {
template<class T = char> const T* data() const {
return reinterpret_cast<const T*>(_data);
}
@ -99,12 +99,12 @@ template<UnsignedInt dimensions> class ImageReference: public AbstractImage {
* destruction.
*/
void setData(const void* data) {
_data = reinterpret_cast<const unsigned char*>(data);
_data = reinterpret_cast<const char*>(data);
}
private:
Math::Vector<Dimensions, Int> _size;
const unsigned char* _data;
const char* _data;
};
/** @brief One-dimensional image wrapper */

14
src/Magnum/Test/BufferImageGLTest.cpp

@ -50,11 +50,11 @@ BufferImageTest::BufferImageTest() {
}
void BufferImageTest::construct() {
const unsigned char data[] = { 'a', 0, 0, 0, 'b', 0, 0, 0, 'c', 0, 0, 0 };
const char data[] = { 'a', 0, 0, 0, 'b', 0, 0, 0, 'c', 0, 0, 0 };
BufferImage2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 3}, data, BufferUsage::StaticDraw);
#ifndef MAGNUM_TARGET_GLES
const auto imageData = a.buffer().data<UnsignedByte>();
const auto imageData = a.buffer().data();
#endif
MAGNUM_VERIFY_NO_ERROR();
@ -65,8 +65,8 @@ void BufferImageTest::construct() {
/** @todo How to verify the contents in ES? */
#ifndef MAGNUM_TARGET_GLES
CORRADE_COMPARE_AS(std::vector<UnsignedByte>(imageData.begin(), imageData.end()),
std::vector<UnsignedByte>(data, data + 12),
CORRADE_COMPARE_AS(std::vector<char>(imageData.begin(), imageData.end()),
std::vector<char>(data, data + 12),
TestSuite::Compare::Container);
#endif
}
@ -77,7 +77,7 @@ void BufferImageTest::constructCopy() {
}
void BufferImageTest::constructMove() {
const unsigned char data[4] = { 'a', 'b', 'c', 'd' };
const char data[4] = { 'a', 'b', 'c', 'd' };
BufferImage2D a(ColorFormat::Red, ColorType::UnsignedByte, {4, 1}, data, BufferUsage::StaticDraw);
const Int id = a.buffer().id();
@ -112,10 +112,10 @@ void BufferImageTest::constructMove() {
}
void BufferImageTest::setData() {
const unsigned char data[4] = { 'a', 'b', 'c', 'd' };
const char data[4] = { 'a', 'b', 'c', 'd' };
BufferImage2D a(ColorFormat::Red, ColorType::UnsignedByte, {4, 1}, data, BufferUsage::StaticDraw);
const unsigned short data2[2*4] = { 1, 2, 3, 4, 5, 6, 7, 8 };
const UnsignedShort data2[2*4] = { 1, 2, 3, 4, 5, 6, 7, 8 };
a.setData(ColorFormat::RGBA, ColorType::UnsignedShort, {1, 2}, data2, BufferUsage::StaticDraw);
#ifndef MAGNUM_TARGET_GLES

8
src/Magnum/Test/ImageReferenceTest.cpp

@ -43,7 +43,7 @@ ImageReferenceTest::ImageReferenceTest() {
}
void ImageReferenceTest::construct() {
const unsigned char data[3] = {};
const char data[3] = {};
ImageReference2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 3}, data);
CORRADE_COMPARE(a.format(), ColorFormat::Red);
@ -53,15 +53,15 @@ void ImageReferenceTest::construct() {
}
void ImageReferenceTest::setData() {
const unsigned char data[3] = {};
const char data[3] = {};
ImageReference2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 3}, data);
const unsigned char data2[8] = {};
const char data2[8] = {};
a.setData(data2);
CORRADE_COMPARE(a.format(), ColorFormat::Red);
CORRADE_COMPARE(a.type(), ColorType::UnsignedByte);
CORRADE_COMPARE(a.size(), Vector2i(1, 3));
CORRADE_COMPARE(a.data(), reinterpret_cast<const unsigned char*>(data2));
CORRADE_COMPARE(a.data(), data2);
}
}}

18
src/Magnum/Test/ImageTest.cpp

@ -53,7 +53,7 @@ ImageTest::ImageTest() {
}
void ImageTest::construct() {
auto data = new unsigned char[3];
auto data = new char[3];
Image2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 3}, data);
CORRADE_COMPARE(a.format(), ColorFormat::Red);
@ -68,7 +68,7 @@ void ImageTest::constructCopy() {
}
void ImageTest::constructMove() {
auto data = new unsigned char[3];
auto data = new char[3];
Image2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 3}, data);
Image2D b(std::move(a));
@ -80,7 +80,7 @@ void ImageTest::constructMove() {
CORRADE_COMPARE(b.size(), Vector2i(1, 3));
CORRADE_COMPARE(b.data(), data);
auto data2 = new unsigned char[3];
auto data2 = new char[12*4*2];
Image2D c(ColorFormat::RGBA, ColorType::UnsignedShort, {2, 6}, data2);
c = std::move(b);
@ -94,19 +94,19 @@ void ImageTest::constructMove() {
}
void ImageTest::setData() {
auto data = new unsigned char[3];
auto data = new char[3];
Image2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 3}, data);
auto data2 = new unsigned short[2*4];
auto data2 = new char[2*4];
a.setData(ColorFormat::RGBA, ColorType::UnsignedShort, {2, 1}, data2);
CORRADE_COMPARE(a.format(), ColorFormat::RGBA);
CORRADE_COMPARE(a.type(), ColorType::UnsignedShort);
CORRADE_COMPARE(a.size(), Vector2i(2, 1));
CORRADE_COMPARE(a.data(), reinterpret_cast<unsigned char*>(data2));
CORRADE_COMPARE(a.data(), data2);
}
void ImageTest::toReference() {
auto data = new unsigned char[3];
auto data = new char[3];
const Image2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 3}, data);
ImageReference2D b = a;
@ -126,9 +126,9 @@ void ImageTest::toReference() {
}
void ImageTest::release() {
unsigned char data[] = {'c', 'a', 'f', 'e'};
char data[] = {'c', 'a', 'f', 'e'};
Image2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 4}, data);
const unsigned char* const pointer = a.release();
const char* const pointer = a.release();
CORRADE_COMPARE(pointer, data);
CORRADE_COMPARE(a.data(), nullptr);

8
src/Magnum/Text/AbstractFont.cpp

@ -38,7 +38,7 @@ AbstractFont::AbstractFont(): _size(0.0f) {}
AbstractFont::AbstractFont(PluginManager::AbstractManager& manager, std::string plugin): AbstractPlugin(manager, std::move(plugin)), _size(0.0f), _lineHeight(0.0f) {}
bool AbstractFont::openData(const std::vector<std::pair<std::string, Containers::ArrayReference<const unsigned char>>>& data, const Float size) {
bool AbstractFont::openData(const std::vector<std::pair<std::string, Containers::ArrayReference<const char>>>& data, const Float size) {
CORRADE_ASSERT(features() & Feature::OpenData,
"Text::AbstractFont::openData(): feature not supported", false);
CORRADE_ASSERT(!data.empty(),
@ -50,7 +50,7 @@ bool AbstractFont::openData(const std::vector<std::pair<std::string, Containers:
return isOpened();
}
std::pair<Float, Float> AbstractFont::doOpenData(const std::vector<std::pair<std::string, Containers::ArrayReference<const unsigned char>>>& data, const Float size) {
std::pair<Float, Float> AbstractFont::doOpenData(const std::vector<std::pair<std::string, Containers::ArrayReference<const char>>>& data, const Float size) {
CORRADE_ASSERT(!(features() & Feature::MultiFile),
"Text::AbstractFont::openData(): feature advertised but not implemented", {});
CORRADE_ASSERT(data.size() == 1,
@ -60,7 +60,7 @@ std::pair<Float, Float> AbstractFont::doOpenData(const std::vector<std::pair<std
return doOpenSingleData(data[0].second, size);
}
bool AbstractFont::openSingleData(const Containers::ArrayReference<const unsigned char> data, const Float size) {
bool AbstractFont::openSingleData(const Containers::ArrayReference<const char> data, const Float size) {
CORRADE_ASSERT(features() & Feature::OpenData,
"Text::AbstractFont::openSingleData(): feature not supported", false);
CORRADE_ASSERT(!(features() & Feature::MultiFile),
@ -72,7 +72,7 @@ bool AbstractFont::openSingleData(const Containers::ArrayReference<const unsigne
return isOpened();
}
std::pair<Float, Float> AbstractFont::doOpenSingleData(Containers::ArrayReference<const unsigned char>, Float) {
std::pair<Float, Float> AbstractFont::doOpenSingleData(Containers::ArrayReference<const char>, Float) {
CORRADE_ASSERT(false, "Text::AbstractFont::openSingleData(): feature advertised but not implemented", {});
}

8
src/Magnum/Text/AbstractFont.h

@ -125,7 +125,7 @@ class MAGNUM_TEXT_EXPORT AbstractFont: public PluginManager::AbstractPlugin {
* file. Available only if @ref Feature::OpenData is supported. Returns
* `true` on success, `false` otherwise.
*/
bool openData(const std::vector<std::pair<std::string, Containers::ArrayReference<const unsigned char>>>& data, Float size);
bool openData(const std::vector<std::pair<std::string, Containers::ArrayReference<const char>>>& data, Float size);
/**
* @brief Open font from single data
@ -137,7 +137,7 @@ class MAGNUM_TEXT_EXPORT AbstractFont: public PluginManager::AbstractPlugin {
* plugin doesn't have @ref Feature::MultiFile. Returns `true` on
* success, `false` otherwise.
*/
bool openSingleData(Containers::ArrayReference<const unsigned char> data, Float size);
bool openSingleData(Containers::ArrayReference<const char> data, Float size);
/**
* @brief Open font from file
@ -243,7 +243,7 @@ class MAGNUM_TEXT_EXPORT AbstractFont: public PluginManager::AbstractPlugin {
* zeros otherwise. If the plugin doesn't have @ref Feature::MultiFile,
* default implementation calls @ref doOpenSingleData().
*/
virtual std::pair<Float, Float> doOpenData(const std::vector<std::pair<std::string, Containers::ArrayReference<const unsigned char>>>& data, Float size);
virtual std::pair<Float, Float> doOpenData(const std::vector<std::pair<std::string, Containers::ArrayReference<const char>>>& data, Float size);
/**
* @brief Implementation for @ref openSingleData()
@ -251,7 +251,7 @@ class MAGNUM_TEXT_EXPORT AbstractFont: public PluginManager::AbstractPlugin {
* Return size and line height of opened font on successful opening,
* zeros otherwise.
*/
virtual std::pair<Float, Float> doOpenSingleData(Containers::ArrayReference<const unsigned char> data, Float size);
virtual std::pair<Float, Float> doOpenSingleData(Containers::ArrayReference<const char> data, Float size);
/**
* @brief Implementation for @ref openFile()

32
src/Magnum/Text/AbstractFontConverter.cpp

@ -39,7 +39,7 @@ AbstractFontConverter::AbstractFontConverter() = default;
AbstractFontConverter::AbstractFontConverter(PluginManager::AbstractManager& manager, std::string plugin): PluginManager::AbstractPlugin(manager, std::move(plugin)) {}
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> AbstractFontConverter::exportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::string& characters) const {
std::vector<std::pair<std::string, Containers::Array<char>>> AbstractFontConverter::exportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::string& characters) const {
CORRADE_ASSERT(features() >= (Feature::ExportFont|Feature::ConvertData),
"Text::AbstractFontConverter::exportFontToData(): feature not supported", {});
@ -47,20 +47,20 @@ std::vector<std::pair<std::string, Containers::Array<unsigned char>>> AbstractFo
}
#ifndef __MINGW32__
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> AbstractFontConverter::doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::u32string& characters) const
std::vector<std::pair<std::string, Containers::Array<char>>> AbstractFontConverter::doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::u32string& characters) const
#else
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> AbstractFontConverter::doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::vector<char32_t>& characters) const
std::vector<std::pair<std::string, Containers::Array<char>>> AbstractFontConverter::doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::vector<char32_t>& characters) const
#endif
{
CORRADE_ASSERT(!(features() & Feature::MultiFile),
"Text::AbstractFontConverter::exportFontToData(): feature advertised but not implemented", {});
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> out;
std::vector<std::pair<std::string, Containers::Array<char>>> out;
out.emplace_back(filename, std::move(doExportFontToSingleData(font, cache, characters)));
return std::move(out);
}
Containers::Array<unsigned char> AbstractFontConverter::exportFontToSingleData(AbstractFont& font, GlyphCache& cache, const std::string& characters) const {
Containers::Array<char> AbstractFontConverter::exportFontToSingleData(AbstractFont& font, GlyphCache& cache, const std::string& characters) const {
CORRADE_ASSERT(features() >= (Feature::ExportFont|Feature::ConvertData),
"Text::AbstractFontConverter::exportFontToSingleData(): feature not supported", nullptr);
CORRADE_ASSERT(!(features() & Feature::MultiFile),
@ -70,9 +70,9 @@ Containers::Array<unsigned char> AbstractFontConverter::exportFontToSingleData(A
}
#ifndef __MINGW32__
Containers::Array<unsigned char> AbstractFontConverter::doExportFontToSingleData(AbstractFont&, GlyphCache&, const std::u32string&) const
Containers::Array<char> AbstractFontConverter::doExportFontToSingleData(AbstractFont&, GlyphCache&, const std::u32string&) const
#else
Containers::Array<unsigned char> AbstractFontConverter::doExportFontToSingleData(AbstractFont&, GlyphCache&, const std::vector<char32_t>&) const
Containers::Array<char> AbstractFontConverter::doExportFontToSingleData(AbstractFont&, GlyphCache&, const std::vector<char32_t>&) const
#endif
{
CORRADE_ASSERT(false,
@ -105,23 +105,23 @@ bool AbstractFontConverter::doExportFontToFile(AbstractFont& font, GlyphCache& c
return true;
}
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> AbstractFontConverter::exportGlyphCacheToData(GlyphCache& cache, const std::string& filename) const {
std::vector<std::pair<std::string, Containers::Array<char>>> AbstractFontConverter::exportGlyphCacheToData(GlyphCache& cache, const std::string& filename) const {
CORRADE_ASSERT(features() >= (Feature::ExportGlyphCache|Feature::ConvertData),
"Text::AbstractFontConverter::exportGlyphCacheToData(): feature not supported", {});
return doExportGlyphCacheToData(cache, filename);
}
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> AbstractFontConverter::doExportGlyphCacheToData(GlyphCache& cache, const std::string& filename) const {
std::vector<std::pair<std::string, Containers::Array<char>>> AbstractFontConverter::doExportGlyphCacheToData(GlyphCache& cache, const std::string& filename) const {
CORRADE_ASSERT(!(features() & Feature::MultiFile),
"Text::AbstractFontConverter::exportGlyphCacheToData(): feature advertised but not implemented", {});
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> out;
std::vector<std::pair<std::string, Containers::Array<char>>> out;
out.emplace_back(filename, std::move(doExportGlyphCacheToSingleData(cache)));
return std::move(out);
}
Containers::Array<unsigned char> AbstractFontConverter::exportGlyphCacheToSingleData(GlyphCache& cache) const {
Containers::Array<char> AbstractFontConverter::exportGlyphCacheToSingleData(GlyphCache& cache) const {
CORRADE_ASSERT(features() >= (Feature::ExportGlyphCache|Feature::ConvertData),
"Text::AbstractFontConverter::exportGlyphCacheToSingleData(): feature not supported", nullptr);
CORRADE_ASSERT(!(features() & Feature::MultiFile),
@ -130,7 +130,7 @@ Containers::Array<unsigned char> AbstractFontConverter::exportGlyphCacheToSingle
return doExportGlyphCacheToSingleData(cache);
}
Containers::Array<unsigned char> AbstractFontConverter::doExportGlyphCacheToSingleData(GlyphCache&) const {
Containers::Array<char> AbstractFontConverter::doExportGlyphCacheToSingleData(GlyphCache&) const {
CORRADE_ASSERT(false,
"Text::AbstractFontConverter::exportGlyphCacheToSingleData(): feature advertised but not implemented", nullptr);
}
@ -156,7 +156,7 @@ bool AbstractFontConverter::doExportGlyphCacheToFile(GlyphCache& cache, const st
return true;
}
std::unique_ptr<GlyphCache> AbstractFontConverter::importGlyphCacheFromData(const std::vector<std::pair<std::string, Containers::ArrayReference<const unsigned char>>>& data) const {
std::unique_ptr<GlyphCache> AbstractFontConverter::importGlyphCacheFromData(const std::vector<std::pair<std::string, Containers::ArrayReference<const char>>>& data) const {
CORRADE_ASSERT(features() >= (Feature::ImportGlyphCache|Feature::ConvertData),
"Text::AbstractFontConverter::importGlyphCacheFromData(): feature not supported", nullptr);
CORRADE_ASSERT(!data.empty(),
@ -165,7 +165,7 @@ std::unique_ptr<GlyphCache> AbstractFontConverter::importGlyphCacheFromData(cons
return doImportGlyphCacheFromData(data);
}
std::unique_ptr<GlyphCache> AbstractFontConverter::doImportGlyphCacheFromData(const std::vector<std::pair<std::string, Containers::ArrayReference<const unsigned char>>>& data) const {
std::unique_ptr<GlyphCache> AbstractFontConverter::doImportGlyphCacheFromData(const std::vector<std::pair<std::string, Containers::ArrayReference<const char>>>& data) const {
CORRADE_ASSERT(!(features() & Feature::MultiFile),
"Text::AbstractFontConverter::importGlyphCacheFromData(): feature advertised but not implemented", nullptr);
CORRADE_ASSERT(data.size() == 1,
@ -174,7 +174,7 @@ std::unique_ptr<GlyphCache> AbstractFontConverter::doImportGlyphCacheFromData(co
return doImportGlyphCacheFromSingleData(data[0].second);
}
std::unique_ptr<GlyphCache> AbstractFontConverter::importGlyphCacheFromSingleData(Containers::ArrayReference<const unsigned char> data) const {
std::unique_ptr<GlyphCache> AbstractFontConverter::importGlyphCacheFromSingleData(Containers::ArrayReference<const char> data) const {
CORRADE_ASSERT(features() >= (Feature::ImportGlyphCache|Feature::ConvertData),
"Text::AbstractFontConverter::importGlyphCacheFromSingleData(): feature not supported", nullptr);
CORRADE_ASSERT(!(features() & Feature::MultiFile),
@ -183,7 +183,7 @@ std::unique_ptr<GlyphCache> AbstractFontConverter::importGlyphCacheFromSingleDat
return doImportGlyphCacheFromSingleData(data);
}
std::unique_ptr<GlyphCache> AbstractFontConverter::doImportGlyphCacheFromSingleData(Containers::ArrayReference<const unsigned char>) const {
std::unique_ptr<GlyphCache> AbstractFontConverter::doImportGlyphCacheFromSingleData(Containers::ArrayReference<const char>) const {
CORRADE_ASSERT(false,
"Text::AbstractFontConverter::importGlyphCacheFromSingleData(): feature advertised but not implemented", nullptr);
}

28
src/Magnum/Text/AbstractFontConverter.h

@ -149,7 +149,7 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl
* @see @ref features(), @ref exportFontToFile(),
* @ref exportGlyphCacheToData()
*/
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> exportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::string& characters) const;
std::vector<std::pair<std::string, Containers::Array<char>>> exportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::string& characters) const;
/**
* @brief Export font to single raw data
@ -161,7 +161,7 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl
* @see @ref features(), @ref exportFontToFile(),
* @ref exportGlyphCacheToSingleData()
*/
Containers::Array<unsigned char> exportFontToSingleData(AbstractFont& font, GlyphCache& cache, const std::string& characters) const;
Containers::Array<char> exportFontToSingleData(AbstractFont& font, GlyphCache& cache, const std::string& characters) const;
/**
* @brief Export font to file
@ -193,7 +193,7 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl
* @see @ref features(), @ref exportGlyphCacheToFile(),
* @ref exportFontToData()
*/
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> exportGlyphCacheToData(GlyphCache& cache, const std::string& filename) const;
std::vector<std::pair<std::string, Containers::Array<char>>> exportGlyphCacheToData(GlyphCache& cache, const std::string& filename) const;
/**
* @brief Export glyph cache to single raw data
@ -205,7 +205,7 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl
* @see @ref features(), @ref exportGlyphCacheToFile(),
* @ref importGlyphCacheFromSingleData()
*/
Containers::Array<unsigned char> exportGlyphCacheToSingleData(GlyphCache& cache) const;
Containers::Array<char> exportGlyphCacheToSingleData(GlyphCache& cache) const;
/**
* @brief Export glyph cache to file
@ -232,7 +232,7 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl
* @see @ref features(), @ref importGlyphCacheFromFile(),
* @ref exportGlyphCacheToData()
*/
std::unique_ptr<GlyphCache> importGlyphCacheFromData(const std::vector<std::pair<std::string, Containers::ArrayReference<const unsigned char>>>& data) const;
std::unique_ptr<GlyphCache> importGlyphCacheFromData(const std::vector<std::pair<std::string, Containers::ArrayReference<const char>>>& data) const;
/**
* @brief Import glyph cache from single raw data
@ -244,7 +244,7 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl
* @see @ref features(), @ref importGlyphCacheFromFile(),
* @ref exportFontToSingleData()
*/
std::unique_ptr<GlyphCache> importGlyphCacheFromSingleData(Containers::ArrayReference<const unsigned char> data) const;
std::unique_ptr<GlyphCache> importGlyphCacheFromSingleData(Containers::ArrayReference<const char> data) const;
/**
* @brief Import glyph cache from file
@ -277,9 +277,9 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl
* for more information.
*/
#ifndef __MINGW32__
virtual std::vector<std::pair<std::string, Containers::Array<unsigned char>>> doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::u32string& characters) const;
virtual std::vector<std::pair<std::string, Containers::Array<char>>> doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::u32string& characters) const;
#else
virtual std::vector<std::pair<std::string, Containers::Array<unsigned char>>> doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::vector<char32_t>& characters) const;
virtual std::vector<std::pair<std::string, Containers::Array<char>>> doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::vector<char32_t>& characters) const;
#endif
/**
@ -290,9 +290,9 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl
* for more information.
*/
#ifndef __MINGW32__
virtual Containers::Array<unsigned char> doExportFontToSingleData(AbstractFont& font, GlyphCache& cache, const std::u32string& characters) const;
virtual Containers::Array<char> doExportFontToSingleData(AbstractFont& font, GlyphCache& cache, const std::u32string& characters) const;
#else
virtual Containers::Array<unsigned char> doExportFontToSingleData(AbstractFont& font, GlyphCache& cache, const std::vector<char32_t>& characters) const;
virtual Containers::Array<char> doExportFontToSingleData(AbstractFont& font, GlyphCache& cache, const std::vector<char32_t>& characters) const;
#endif
/**
@ -317,10 +317,10 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl
* If the plugin doesn't have @ref Feature::MultiFile, default
* implementation calls @ref doExportGlyphCacheToSingleData().
*/
virtual std::vector<std::pair<std::string, Containers::Array<unsigned char>>> doExportGlyphCacheToData(GlyphCache& cache, const std::string& filename) const;
virtual std::vector<std::pair<std::string, Containers::Array<char>>> doExportGlyphCacheToData(GlyphCache& cache, const std::string& filename) const;
/** @brief Implementation for @ref exportGlyphCacheToSingleData() */
virtual Containers::Array<unsigned char> doExportGlyphCacheToSingleData(GlyphCache& cache) const;
virtual Containers::Array<char> doExportGlyphCacheToSingleData(GlyphCache& cache) const;
/**
* @brief Implementation for @ref exportGlyphCacheToFile()
@ -337,10 +337,10 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl
* If the plugin doesn't have @ref Feature::MultiFile, default
* implementation calls @ref doImportGlyphCacheFromSingleData().
*/
virtual std::unique_ptr<GlyphCache> doImportGlyphCacheFromData(const std::vector<std::pair<std::string, Containers::ArrayReference<const unsigned char>>>& data) const;
virtual std::unique_ptr<GlyphCache> doImportGlyphCacheFromData(const std::vector<std::pair<std::string, Containers::ArrayReference<const char>>>& data) const;
/** @brief Implementation for @ref importGlyphCacheFromSingleData() */
virtual std::unique_ptr<GlyphCache> doImportGlyphCacheFromSingleData(Containers::ArrayReference<const unsigned char> data) const;
virtual std::unique_ptr<GlyphCache> doImportGlyphCacheFromSingleData(Containers::ArrayReference<const char> data) const;
/**
* @brief Implementation for @ref importGlyphCacheFromFile()

16
src/Magnum/Text/Renderer.cpp

@ -172,23 +172,23 @@ std::tuple<std::vector<Vertex>, Range2D> renderVerticesInternal(AbstractFont& fo
return std::make_tuple(std::move(vertices), rectangle);
}
std::pair<Containers::Array<unsigned char>, Mesh::IndexType> renderIndicesInternal(const UnsignedInt glyphCount) {
std::pair<Containers::Array<char>, Mesh::IndexType> renderIndicesInternal(const UnsignedInt glyphCount) {
const UnsignedInt vertexCount = glyphCount*4;
const UnsignedInt indexCount = glyphCount*6;
Containers::Array<unsigned char> indices;
Containers::Array<char> indices;
Mesh::IndexType indexType;
if(vertexCount <= 256) {
indexType = Mesh::IndexType::UnsignedByte;
indices = Containers::Array<unsigned char>(indexCount*sizeof(UnsignedByte));
indices = Containers::Array<char>(indexCount*sizeof(UnsignedByte));
createIndices<UnsignedByte>(indices, glyphCount);
} else if(vertexCount <= 65536) {
indexType = Mesh::IndexType::UnsignedShort;
indices = Containers::Array<unsigned char>(indexCount*sizeof(UnsignedShort));
indices = Containers::Array<char>(indexCount*sizeof(UnsignedShort));
createIndices<UnsignedShort>(indices, glyphCount);
} else {
indexType = Mesh::IndexType::UnsignedInt;
indices = Containers::Array<unsigned char>(indexCount*sizeof(UnsignedInt));
indices = Containers::Array<char>(indexCount*sizeof(UnsignedInt));
createIndices<UnsignedInt>(indices, glyphCount);
}
@ -206,7 +206,7 @@ std::tuple<Mesh, Range2D> renderInternal(AbstractFont& font, const GlyphCache& c
const UnsignedInt indexCount = glyphCount*6;
/* Render indices and upload them */
Containers::Array<unsigned char> indices;
Containers::Array<char> indices;
Mesh::IndexType indexType;
std::tie(indices, indexType) = renderIndicesInternal(glyphCount);
indexBuffer.setData(indices, usage);
@ -345,7 +345,7 @@ void AbstractRenderer::reserve(const uint32_t glyphCount, const BufferUsage vert
_mesh.setCount(0);
/* Render indices */
Containers::Array<unsigned char> indexData;
Containers::Array<char> indexData;
Mesh::IndexType indexType;
std::tie(indexData, indexType) = renderIndicesInternal(glyphCount);
@ -358,7 +358,7 @@ void AbstractRenderer::reserve(const uint32_t glyphCount, const BufferUsage vert
.setIndexBuffer(_indexBuffer, 0, indexType, 0, vertexCount);
/* Prefill index buffer */
unsigned char* const indices = static_cast<unsigned char*>(bufferMapImplementation(_indexBuffer, indexData.size()));
char* const indices = static_cast<char*>(bufferMapImplementation(_indexBuffer, indexData.size()));
CORRADE_INTERNAL_ASSERT(indices);
/** @todo Emscripten: it can be done without this copying altogether */
std::copy(indexData.begin(), indexData.end(), indices);

72
src/Magnum/Text/Test/AbstractFontConverterTest.cpp

@ -26,6 +26,7 @@
#include <Corrade/Containers/Array.h>
#include <Corrade/TestSuite/Tester.h>
#include <Corrade/TestSuite/Compare/FileToString.h>
#include <Corrade/TestSuite/Compare/Container.h>
#include <Corrade/Utility/Directory.h>
#include "Magnum/Text/AbstractFontConverter.h"
@ -65,7 +66,7 @@ AbstractFontConverterTest::AbstractFontConverterTest() {
namespace {
/* *static_cast<GlyphCache*>(nullptr) makes Clang Analyzer grumpy */
unsigned char nullData;
char nullData;
AbstractFont& nullFont = *reinterpret_cast<AbstractFont*>(nullData);
GlyphCache& nullGlyphCache = *reinterpret_cast<GlyphCache*>(nullData);
}
@ -83,9 +84,9 @@ void AbstractFontConverterTest::convertGlyphs() {
Features doFeatures() const override { return Feature::ConvertData|Feature::ExportFont; }
#ifndef __MINGW32__
Containers::Array<unsigned char> doExportFontToSingleData(AbstractFont&, GlyphCache&, const std::u32string& characters) const override
Containers::Array<char> doExportFontToSingleData(AbstractFont&, GlyphCache&, const std::u32string& characters) const override
#else
Containers::Array<unsigned char> doExportFontToSingleData(AbstractFont&, GlyphCache&, const std::vector<char32_t>& characters) const override
Containers::Array<char> doExportFontToSingleData(AbstractFont&, GlyphCache&, const std::vector<char32_t>& characters) const override
#endif
{
this->characters = characters;
@ -120,13 +121,13 @@ void AbstractFontConverterTest::exportFontToSingleData() {
Features doFeatures() const override { return Feature::ConvertData|Feature::ExportFont; }
#ifndef __MINGW32__
Containers::Array<unsigned char> doExportFontToSingleData(AbstractFont&, GlyphCache&, const std::u32string&) const override
Containers::Array<char> doExportFontToSingleData(AbstractFont&, GlyphCache&, const std::u32string&) const override
#else
Containers::Array<unsigned char> doExportFontToSingleData(AbstractFont&, GlyphCache&, const std::vector<char32_t>&) const override
Containers::Array<char> doExportFontToSingleData(AbstractFont&, GlyphCache&, const std::vector<char32_t>&) const override
#endif
{
Containers::Array<unsigned char> data(1);
data[0] = 0xee;
Containers::Array<char> data(1);
data[0] = '\xee';
return std::move(data);
}
};
@ -137,7 +138,7 @@ void AbstractFontConverterTest::exportFontToSingleData() {
CORRADE_COMPARE(ret.size(), 1);
CORRADE_COMPARE(ret[0].first, "font.out");
CORRADE_COMPARE(ret[0].second.size(), 1);
CORRADE_COMPARE(ret[0].second[0], 0xee);
CORRADE_COMPARE(ret[0].second[0], '\xee');
}
void AbstractFontConverterTest::exportFontToFile() {
@ -146,22 +147,17 @@ void AbstractFontConverterTest::exportFontToFile() {
Features doFeatures() const override { return Feature::ConvertData|Feature::ExportFont|Feature::MultiFile; }
#ifndef __MINGW32__
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> doExportFontToData(AbstractFont&, GlyphCache&, const std::string& filename, const std::u32string&) const override
std::vector<std::pair<std::string, Containers::Array<char>>> doExportFontToData(AbstractFont&, GlyphCache&, const std::string& filename, const std::u32string&) const override
#else
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> doExportFontToData(AbstractFont&, GlyphCache&, const std::string& filename, const std::vector<char32_t>&) const override
std::vector<std::pair<std::string, Containers::Array<char>>> doExportFontToData(AbstractFont&, GlyphCache&, const std::string& filename, const std::vector<char32_t>&) const override
#endif
{
Containers::Array<unsigned char> file(1);
file[0] = 0xf0;
Containers::Array<unsigned char> data(2);
data[0] = 0xfe;
data[1] = 0xed;
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> out;
out.emplace_back(filename, std::move(file));
out.emplace_back(filename + ".data", std::move(data));
return std::move(out);
/* Why the hell GCC 4.9 fails to do proper move so I need to
work around that this ugly way?! */
std::vector<std::pair<std::string, Containers::Array<char>>> ret;
ret.emplace_back(filename, Containers::Array<char>::from('\xf0'));
ret.emplace_back(filename + ".data", Containers::Array<char>::from('\xfe', '\xed'));
return ret;
}
};
@ -184,10 +180,8 @@ void AbstractFontConverterTest::exportGlyphCacheToSingleData() {
private:
Features doFeatures() const override { return Feature::ConvertData|Feature::ExportGlyphCache; }
Containers::Array<unsigned char> doExportGlyphCacheToSingleData(GlyphCache&) const override {
Containers::Array<unsigned char> data(1);
data[0] = 0xee;
return std::move(data);
Containers::Array<char> doExportGlyphCacheToSingleData(GlyphCache&) const override {
return Containers::Array<char>::from('\xee');
}
};
@ -196,8 +190,7 @@ void AbstractFontConverterTest::exportGlyphCacheToSingleData() {
auto ret = exporter.exportGlyphCacheToData(nullGlyphCache, "font.out");
CORRADE_COMPARE(ret.size(), 1);
CORRADE_COMPARE(ret[0].first, "font.out");
CORRADE_COMPARE(ret[0].second.size(), 1);
CORRADE_COMPARE(ret[0].second[0], 0xee);
CORRADE_COMPARE_AS(ret[0].second, Containers::Array<char>::from('\xee'), TestSuite::Compare::Container);
}
void AbstractFontConverterTest::exportGlyphCacheToFile() {
@ -205,18 +198,13 @@ void AbstractFontConverterTest::exportGlyphCacheToFile() {
private:
Features doFeatures() const override { return Feature::ConvertData|Feature::ExportGlyphCache|Feature::MultiFile; }
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> doExportGlyphCacheToData(GlyphCache&, const std::string& filename) const override {
Containers::Array<unsigned char> file(1);
file[0] = 0xf0;
Containers::Array<unsigned char> data(2);
data[0] = 0xfe;
data[1] = 0xed;
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> out;
out.emplace_back(filename, std::move(file));
out.emplace_back(filename + ".data", std::move(data));
return std::move(out);
std::vector<std::pair<std::string, Containers::Array<char>>> doExportGlyphCacheToData(GlyphCache&, const std::string& filename) const override {
/* Why the hell GCC 4.9 fails to do proper move so I need to
work around that this ugly way?! */
std::vector<std::pair<std::string, Containers::Array<char>>> ret;
ret.emplace_back(filename, Containers::Array<char>::from('\xf0'));
ret.emplace_back(filename + ".data", Containers::Array<char>::from('\xfe', '\xed'));
return ret;
}
};
@ -240,8 +228,8 @@ class SingleGlyphCacheDataImporter: public Text::AbstractFontConverter {
private:
Features doFeatures() const override { return Feature::ConvertData|Feature::ImportGlyphCache; }
std::unique_ptr<GlyphCache> doImportGlyphCacheFromSingleData(const Containers::ArrayReference<const unsigned char> data) const override {
if(data.size() == 1 && data[0] == 0xa5)
std::unique_ptr<GlyphCache> doImportGlyphCacheFromSingleData(const Containers::ArrayReference<const char> data) const override {
if(data.size() == 1 && data[0] == '\xa5')
return std::unique_ptr<GlyphCache>(reinterpret_cast<GlyphCache*>(0xdeadbeef));
return nullptr;
}
@ -252,7 +240,7 @@ class SingleGlyphCacheDataImporter: public Text::AbstractFontConverter {
void AbstractFontConverterTest::importGlyphCacheFromSingleData() {
/* doImportFromData() should call doImportFromSingleData() */
SingleGlyphCacheDataImporter importer;
const unsigned char data[] = {0xa5};
const char data[] = {'\xa5'};
std::unique_ptr<GlyphCache> cache = importer.importGlyphCacheFromData({{{}, data}});
CORRADE_COMPARE(cache.get(), reinterpret_cast<GlyphCache*>(0xdeadbeef));

6
src/Magnum/Text/Test/AbstractFontTest.cpp

@ -56,8 +56,8 @@ class SingleDataFont: public Text::AbstractFont {
bool doIsOpened() const override { return opened; }
void doClose() override {}
std::pair<Float, Float> doOpenSingleData(const Containers::ArrayReference<const unsigned char> data, Float) override {
opened = (data.size() == 1 && data[0] == 0xa5);
std::pair<Float, Float> doOpenSingleData(const Containers::ArrayReference<const char> data, Float) override {
opened = (data.size() == 1 && data[0] == '\xa5');
return {};
}
@ -77,7 +77,7 @@ class SingleDataFont: public Text::AbstractFont {
void AbstractFontTest::openSingleData() {
/* doOpenData() should call doOpenSingleData() */
SingleDataFont font;
const unsigned char data[] = {0xa5};
const char data[] = {'\xa5'};
CORRADE_VERIFY(!font.isOpened());
font.openData({{{}, data}}, 3.0f);
CORRADE_VERIFY(font.isOpened());

2
src/Magnum/Text/Test/RendererGLTest.cpp

@ -82,7 +82,7 @@ class TestFont: public Text::AbstractFont {
};
/* *static_cast<GlyphCache*>(nullptr) makes Clang Analyzer grumpy */
unsigned char glyphCacheData;
char glyphCacheData;
GlyphCache& nullGlyphCache = *reinterpret_cast<GlyphCache*>(&glyphCacheData);
}

4
src/Magnum/Trade/AbstractImageConverter.cpp

@ -46,14 +46,14 @@ Image2D* AbstractImageConverter::doExportToImage(const ImageReference2D&) const
CORRADE_ASSERT(false, "Trade::AbstractImageConverter::exportToImage(): feature advertised but not implemented", nullptr);
}
Containers::Array<unsigned char> AbstractImageConverter::exportToData(const ImageReference2D& image) const {
Containers::Array<char> AbstractImageConverter::exportToData(const ImageReference2D& image) const {
CORRADE_ASSERT(features() & Feature::ConvertData,
"Trade::AbstractImageConverter::exportToData(): feature not supported", nullptr);
return doExportToData(image);
}
Containers::Array<unsigned char> AbstractImageConverter::doExportToData(const ImageReference2D&) const {
Containers::Array<char> AbstractImageConverter::doExportToData(const ImageReference2D&) const {
CORRADE_ASSERT(false, "Trade::AbstractImageConverter::exportToData(): feature advertised but not implemented", nullptr);
}

4
src/Magnum/Trade/AbstractImageConverter.h

@ -107,7 +107,7 @@ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractPlugin
* data on success, zero-sized array otherwise.
* @see @ref features(), @ref exportToImage(), @ref exportToFile()
*/
Containers::Array<unsigned char> exportToData(const ImageReference2D& image) const;
Containers::Array<char> exportToData(const ImageReference2D& image) const;
/**
* @brief Export image to file
@ -129,7 +129,7 @@ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractPlugin
virtual Image2D* doExportToImage(const ImageReference2D& image) const;
/** @brief Implementation of @ref exportToData() */
virtual Containers::Array<unsigned char> doExportToData(const ImageReference2D& image) const;
virtual Containers::Array<char> doExportToData(const ImageReference2D& image) const;
/**
* @brief Implementation of @ref exportToFile()

4
src/Magnum/Trade/AbstractImporter.cpp

@ -49,7 +49,7 @@ AbstractImporter::AbstractImporter(PluginManager::Manager<AbstractImporter>& man
AbstractImporter::AbstractImporter(PluginManager::AbstractManager& manager, std::string plugin): PluginManager::AbstractManagingPlugin<AbstractImporter>(manager, std::move(plugin)) {}
bool AbstractImporter::openData(Containers::ArrayReference<const unsigned char> data) {
bool AbstractImporter::openData(Containers::ArrayReference<const char> data) {
CORRADE_ASSERT(features() & Feature::OpenData,
"Trade::AbstractImporter::openData(): feature not supported", nullptr);
@ -58,7 +58,7 @@ bool AbstractImporter::openData(Containers::ArrayReference<const unsigned char>
return isOpened();
}
void AbstractImporter::doOpenData(Containers::ArrayReference<const unsigned char>) {
void AbstractImporter::doOpenData(Containers::ArrayReference<const char>) {
CORRADE_ASSERT(false, "Trade::AbstractImporter::openData(): feature advertised but not implemented", );
}

4
src/Magnum/Trade/AbstractImporter.h

@ -116,7 +116,7 @@ class MAGNUM_EXPORT AbstractImporter: public PluginManager::AbstractManagingPlug
* `true` on success, `false` otherwise.
* @see @ref features(), @ref openFile()
*/
bool openData(Containers::ArrayReference<const unsigned char> data);
bool openData(Containers::ArrayReference<const char> data);
/**
* @brief Open file
@ -483,7 +483,7 @@ class MAGNUM_EXPORT AbstractImporter: public PluginManager::AbstractManagingPlug
virtual bool doIsOpened() const = 0;
/** @brief Implementation for @ref openData() */
virtual void doOpenData(Containers::ArrayReference<const unsigned char> data);
virtual void doOpenData(Containers::ArrayReference<const char> data);
/**
* @brief Implementation for @ref openFile()

14
src/Magnum/Trade/ImageData.h

@ -54,7 +54,7 @@ template<UnsignedInt dimensions> class ImageData: public AbstractImage {
* Note that the image data are not copied on construction, but they
* are deleted on class destruction.
*/
explicit ImageData(ColorFormat format, ColorType type, const VectorTypeFor<dimensions, Int>& size, void* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast<unsigned char*>(data)) {}
explicit ImageData(ColorFormat format, ColorType type, const VectorTypeFor<dimensions, Int>& size, void* data): AbstractImage{format, type}, _size{size}, _data{reinterpret_cast<char*>(data)} {}
/** @brief Copying is not allowed */
ImageData(const ImageData<dimensions>&) = delete;
@ -97,12 +97,12 @@ template<UnsignedInt dimensions> class ImageData: public AbstractImage {
*
* @see @ref release()
*/
template<class T = unsigned char> T* data() {
template<class T = char> T* data() {
return reinterpret_cast<T*>(_data);
}
/** @overload */
template<class T = unsigned char> const T* data() const {
template<class T = char> const T* data() const {
return reinterpret_cast<const T*>(_data);
}
@ -113,11 +113,11 @@ template<UnsignedInt dimensions> class ImageData: public AbstractImage {
* to default. Deleting the returned array is then user responsibility.
* @see @ref data()
*/
unsigned char* release();
char* release();
private:
Math::Vector<Dimensions, Int> _size;
unsigned char* _data;
char* _data;
};
/** @brief One-dimensional image */
@ -151,9 +151,9 @@ const
return ImageReference<dimensions>(AbstractImage::format(), AbstractImage::type(), _size, _data);
}
template<UnsignedInt dimensions> inline unsigned char* ImageData<dimensions>::release() {
template<UnsignedInt dimensions> inline char* ImageData<dimensions>::release() {
/** @todo I need `std::exchange` NOW. */
unsigned char* const data = _data;
char* const data = _data;
_size = {};
_data = nullptr;
return data;

7
src/Magnum/Trade/Test/AbstractImageConverterTest.cpp

@ -52,11 +52,8 @@ void AbstractImageConverterTest::exportToFile() {
private:
Features doFeatures() const override { return Feature::ConvertData; }
Containers::Array<unsigned char> doExportToData(const ImageReference2D& image) const override {
Containers::Array<unsigned char> out(2);
out[0] = static_cast<unsigned char>(image.size().x());
out[1] = static_cast<unsigned char>(image.size().y());
return out;
Containers::Array<char> doExportToData(const ImageReference2D& image) const override {
return Containers::Array<char>::from(char(image.size().x()), char(image.size().y()));
};
};

4
src/Magnum/Trade/Test/AbstractImporterTest.cpp

@ -54,8 +54,8 @@ void AbstractImporterTest::openFile() {
bool doIsOpened() const override { return opened; }
void doClose() override {}
void doOpenData(Containers::ArrayReference<const unsigned char> data) override {
opened = (data.size() == 1 && data[0] == 0xa5);
void doOpenData(Containers::ArrayReference<const char> data) override {
opened = (data.size() == 1 && data[0] == '\xa5');
}
bool opened;

12
src/Magnum/Trade/Test/ImageDataTest.cpp

@ -52,7 +52,7 @@ ImageDataTest::ImageDataTest() {
}
void ImageDataTest::construct() {
auto data = new unsigned char[3];
auto data = new char[3];
Trade::ImageData2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 3}, data);
CORRADE_COMPARE(a.format(), ColorFormat::Red);
@ -67,7 +67,7 @@ void ImageDataTest::constructCopy() {
}
void ImageDataTest::constructMove() {
auto data = new unsigned char[3];
auto data = new char[3];
Trade::ImageData2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 3}, data);
Trade::ImageData2D b(std::move(a));
@ -79,7 +79,7 @@ void ImageDataTest::constructMove() {
CORRADE_COMPARE(b.size(), Vector2i(1, 3));
CORRADE_COMPARE(b.data(), data);
auto data2 = new unsigned char[3];
auto data2 = new char[3];
Trade::ImageData2D c(ColorFormat::RGBA, ColorType::UnsignedShort, {2, 6}, data2);
c = std::move(b);
@ -93,7 +93,7 @@ void ImageDataTest::constructMove() {
}
void ImageDataTest::toReference() {
auto data = new unsigned char[3];
auto data = new char[3];
const Trade::ImageData2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 3}, data);
ImageReference2D b = a;
@ -113,9 +113,9 @@ void ImageDataTest::toReference() {
}
void ImageDataTest::release() {
unsigned char data[] = {'b', 'e', 'e', 'r'};
char data[] = {'b', 'e', 'e', 'r'};
ImageData2D a(ColorFormat::Red, ColorType::UnsignedByte, {1, 4}, data);
const unsigned char* const pointer = a.release();
const char* const pointer = a.release();
CORRADE_COMPARE(pointer, data);
CORRADE_COMPARE(a.data(), nullptr);

4
src/MagnumPlugins/MagnumFont/MagnumFont.cpp

@ -68,7 +68,7 @@ auto MagnumFont::doFeatures() const -> Features { return Feature::OpenData|Featu
bool MagnumFont::doIsOpened() const { return _opened; }
std::pair<Float, Float> MagnumFont::doOpenData(const std::vector<std::pair<std::string, Containers::ArrayReference<const unsigned char>>>& data, const Float) {
std::pair<Float, Float> MagnumFont::doOpenData(const std::vector<std::pair<std::string, Containers::ArrayReference<const char>>>& data, const Float) {
/* We need just the configuration file and image file */
if(data.size() != 2) {
Error() << "Text::MagnumFont::openData(): wanted two files, got" << data.size();
@ -76,7 +76,7 @@ std::pair<Float, Float> MagnumFont::doOpenData(const std::vector<std::pair<std::
}
/* Open the configuration file */
std::istringstream in({reinterpret_cast<const char*>(data[0].second.begin()), data[0].second.size()});
std::istringstream in({data[0].second.begin(), data[0].second.size()});
Utility::Configuration conf(in, Utility::Configuration::Flag::SkipComments);
if(!conf.isValid() || conf.isEmpty()) {
Error() << "Text::MagnumFont::openData(): cannot open file" << data[0].first;

2
src/MagnumPlugins/MagnumFont/MagnumFont.h

@ -120,7 +120,7 @@ class MagnumFont: public AbstractFont {
bool doIsOpened() const override;
std::pair<Float, Float> doOpenData(const std::vector<std::pair<std::string, Containers::ArrayReference<const unsigned char>>>& data, Float) override;
std::pair<Float, Float> doOpenData(const std::vector<std::pair<std::string, Containers::ArrayReference<const char>>>& data, Float) override;
std::pair<Float, Float> doOpenFile(const std::string& filename, Float) override;

8
src/MagnumPlugins/MagnumFontConverter/MagnumFontConverter.cpp

@ -46,9 +46,9 @@ auto MagnumFontConverter::doFeatures() const -> Features {
}
#ifndef __MINGW32__
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> MagnumFontConverter::doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::u32string& characters) const
std::vector<std::pair<std::string, Containers::Array<char>>> MagnumFontConverter::doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::u32string& characters) const
#else
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> MagnumFontConverter::doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::vector<char32_t>& characters) const
std::vector<std::pair<std::string, Containers::Array<char>>> MagnumFontConverter::doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::vector<char32_t>& characters) const
#endif
{
Utility::Configuration configuration;
@ -100,7 +100,7 @@ std::vector<std::pair<std::string, Containers::Array<unsigned char>>> MagnumFont
std::ostringstream confOut;
configuration.save(confOut);
std::string confStr = confOut.str();
Containers::Array<unsigned char> confData{confStr.size()};
Containers::Array<char> confData{confStr.size()};
std::copy(confStr.begin(), confStr.end(), confData.begin());
/* Save cache image */
@ -108,7 +108,7 @@ std::vector<std::pair<std::string, Containers::Array<unsigned char>>> MagnumFont
cache.texture().image(0, image);
auto tgaData = Trade::TgaImageConverter().exportToData(image);
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> out;
std::vector<std::pair<std::string, Containers::Array<char>>> out;
out.emplace_back(filename + ".conf", std::move(confData));
out.emplace_back(filename + ".tga", std::move(tgaData));
return std::move(out);

4
src/MagnumPlugins/MagnumFontConverter/MagnumFontConverter.h

@ -61,9 +61,9 @@ class MagnumFontConverter: public Text::AbstractFontConverter {
private:
Features doFeatures() const override;
#ifndef __MINGW32__
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::u32string& characters) const override;
std::vector<std::pair<std::string, Containers::Array<char>>> doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::u32string& characters) const override;
#else
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::vector<char32_t>& characters) const override;
std::vector<std::pair<std::string, Containers::Array<char>>> doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::vector<char32_t>& characters) const override;
#endif
};

4
src/MagnumPlugins/ObjImporter/ObjImporter.cpp

@ -132,10 +132,10 @@ void ObjImporter::doOpenFile(const std::string& filename) {
parseMeshNames();
}
void ObjImporter::doOpenData(Containers::ArrayReference<const unsigned char> data) {
void ObjImporter::doOpenData(Containers::ArrayReference<const char> data) {
/* Open file in *text* mode (to avoid \r handling) */
_file.reset(new File);
_file->in.reset(new std::istringstream{{reinterpret_cast<const char*>(data.begin()), data.size()}});
_file->in.reset(new std::istringstream{{data.begin(), data.size()}});
parseMeshNames();
}

2
src/MagnumPlugins/ObjImporter/ObjImporter.h

@ -67,7 +67,7 @@ class ObjImporter: public AbstractImporter {
Features doFeatures() const override;
bool doIsOpened() const override;
void doOpenData(Containers::ArrayReference<const unsigned char> data) override;
void doOpenData(Containers::ArrayReference<const char> data) override;
void doOpenFile(const std::string& filename) override;
void doClose() override;

4
src/MagnumPlugins/TgaImageConverter/Test/TgaImageConverterTest.cpp

@ -107,8 +107,8 @@ void TgaImageConverterTest::data() {
CORRADE_COMPARE(converted->format(), ColorFormat::RGB);
#endif
CORRADE_COMPARE(converted->type(), ColorType::UnsignedByte);
CORRADE_COMPARE(std::string(reinterpret_cast<const char*>(converted->data()), 2*3*3),
std::string(reinterpret_cast<const char*>(original.data()), 2*3*3));
CORRADE_COMPARE((std::string{converted->data(), 2*3*3}),
(std::string{original.data(), 2*3*3}));
}
}}}

4
src/MagnumPlugins/TgaImageConverter/TgaImageConverter.cpp

@ -48,7 +48,7 @@ TgaImageConverter::TgaImageConverter(PluginManager::AbstractManager& manager, st
auto TgaImageConverter::doFeatures() const -> Features { return Feature::ConvertData; }
Containers::Array<unsigned char> TgaImageConverter::doExportToData(const ImageReference2D& image) const {
Containers::Array<char> TgaImageConverter::doExportToData(const ImageReference2D& image) const {
#ifndef MAGNUM_TARGET_GLES
if(image.format() != ColorFormat::BGR &&
image.format() != ColorFormat::BGRA &&
@ -70,7 +70,7 @@ Containers::Array<unsigned char> TgaImageConverter::doExportToData(const ImageRe
/* Initialize data buffer */
const auto pixelSize = UnsignedByte(image.pixelSize());
auto data = Containers::Array<unsigned char>::zeroInitialized(sizeof(TgaHeader) + pixelSize*image.size().product());
auto data = Containers::Array<char>::zeroInitialized(sizeof(TgaHeader) + pixelSize*image.size().product());
/* Fill header */
auto header = reinterpret_cast<TgaHeader*>(data.begin());

2
src/MagnumPlugins/TgaImageConverter/TgaImageConverter.h

@ -67,7 +67,7 @@ class MAGNUM_TRADE_TGAIMAGECONVERTER_EXPORT TgaImageConverter: public AbstractIm
private:
Features MAGNUM_TRADE_TGAIMAGECONVERTER_LOCAL doFeatures() const override;
Containers::Array<unsigned char> MAGNUM_TRADE_TGAIMAGECONVERTER_LOCAL doExportToData(const ImageReference2D& image) const override;
Containers::Array<char> MAGNUM_TRADE_TGAIMAGECONVERTER_LOCAL doExportToData(const ImageReference2D& image) const override;
};
}}

36
src/MagnumPlugins/TgaImporter/Test/TgaImporterTest.cpp

@ -82,7 +82,7 @@ void TgaImporterTest::openNonexistent() {
void TgaImporterTest::openShort() {
TgaImporter importer;
const unsigned char data[] = { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
const char data[] = { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
CORRADE_VERIFY(importer.openData(data));
std::ostringstream debug;
@ -93,7 +93,7 @@ void TgaImporterTest::openShort() {
void TgaImporterTest::paletted() {
TgaImporter importer;
const unsigned char data[] = { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
const char data[] = { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
CORRADE_VERIFY(importer.openData(data));
std::ostringstream debug;
@ -104,7 +104,7 @@ void TgaImporterTest::paletted() {
void TgaImporterTest::compressed() {
TgaImporter importer;
const unsigned char data[] = { 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
const char data[] = { 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
CORRADE_VERIFY(importer.openData(data));
std::ostringstream debug;
@ -115,7 +115,7 @@ void TgaImporterTest::compressed() {
void TgaImporterTest::colorBits16() {
TgaImporter importer;
const unsigned char data[] = { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0 };
const char data[] = { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0 };
CORRADE_VERIFY(importer.openData(data));
std::ostringstream debug;
@ -126,14 +126,14 @@ void TgaImporterTest::colorBits16() {
void TgaImporterTest::colorBits24() {
TgaImporter importer;
const unsigned char data[] = {
const char data[] = {
0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 24, 0,
1, 2, 3, 2, 3, 4,
3, 4, 5, 4, 5, 6,
5, 6, 7, 6, 7, 8
};
#ifndef MAGNUM_TARGET_GLES
const char* pixels = reinterpret_cast<const char*>(data) + 18;
const char* pixels = data + 18;
#else
const char pixels[] = {
3, 2, 1, 4, 3, 2,
@ -152,19 +152,20 @@ void TgaImporterTest::colorBits24() {
#endif
CORRADE_COMPARE(image->size(), Vector2i(2, 3));
CORRADE_COMPARE(image->type(), ColorType::UnsignedByte);
CORRADE_COMPARE(std::string(reinterpret_cast<const char*>(image->data()), 2*3*3), std::string(pixels, 2*3*3));
CORRADE_COMPARE((std::string{image->data(), 2*3*3}),
(std::string{pixels, 2*3*3}));
}
void TgaImporterTest::colorBits32() {
TgaImporter importer;
const unsigned char data[] = {
const char data[] = {
0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 32, 0,
1, 2, 3, 1, 2, 3, 4, 1,
3, 4, 5, 1, 4, 5, 6, 1,
5, 6, 7, 1, 6, 7, 8, 1
};
#ifndef MAGNUM_TARGET_GLES
const char* pixels = reinterpret_cast<const char*>(data) + 18;
const char* pixels = data + 18;
#else
const char pixels[] = {
3, 2, 1, 1, 4, 3, 2, 1,
@ -183,12 +184,13 @@ void TgaImporterTest::colorBits32() {
#endif
CORRADE_COMPARE(image->size(), Vector2i(2, 3));
CORRADE_COMPARE(image->type(), ColorType::UnsignedByte);
CORRADE_COMPARE(std::string(reinterpret_cast<const char*>(image->data()), 2*3*3), std::string(pixels, 2*3*3));
CORRADE_COMPARE((std::string{image->data(), 2*3*3}),
(std::string{pixels, 2*3*3}));
}
void TgaImporterTest::grayscaleBits8() {
TgaImporter importer;
const unsigned char data[] = {
const char data[] = {
0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 8, 0,
1, 2,
3, 4,
@ -205,13 +207,13 @@ void TgaImporterTest::grayscaleBits8() {
#endif
CORRADE_COMPARE(image->size(), Vector2i(2, 3));
CORRADE_COMPARE(image->type(), ColorType::UnsignedByte);
CORRADE_COMPARE(std::string(reinterpret_cast<const char*>(image->data()), 2*3),
std::string(reinterpret_cast<const char*>(data) + 18, 2*3));
CORRADE_COMPARE((std::string{image->data(), 2*3}),
(std::string{data + 18, 2*3}));
}
void TgaImporterTest::grayscaleBits16() {
TgaImporter importer;
const unsigned char data[] = { 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0 };
const char data[] = { 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0 };
CORRADE_VERIFY(importer.openData(data));
std::ostringstream debug;
@ -222,7 +224,7 @@ void TgaImporterTest::grayscaleBits16() {
void TgaImporterTest::file() {
TgaImporter importer;
const unsigned char data[] = {
const char data[] = {
0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 8, 0,
1, 2,
3, 4,
@ -239,8 +241,8 @@ void TgaImporterTest::file() {
#endif
CORRADE_COMPARE(image->size(), Vector2i(2, 3));
CORRADE_COMPARE(image->type(), ColorType::UnsignedByte);
CORRADE_COMPARE(std::string(reinterpret_cast<const char*>(image->data()), 2*3),
std::string(reinterpret_cast<const char*>(data) + 18, 2*3));
CORRADE_COMPARE((std::string{image->data(), 2*3}),
(std::string{data + 18, 2*3}));
}
}}}

4
src/MagnumPlugins/TgaImporter/TgaImporter.cpp

@ -57,8 +57,8 @@ auto TgaImporter::doFeatures() const -> Features { return Feature::OpenData; }
bool TgaImporter::doIsOpened() const { return in; }
void TgaImporter::doOpenData(const Containers::ArrayReference<const unsigned char> data) {
in = new std::istringstream(std::string(reinterpret_cast<const char*>(data.begin()), data.size()));
void TgaImporter::doOpenData(const Containers::ArrayReference<const char> data) {
in = new std::istringstream{{data, data.size()}};
}
void TgaImporter::doOpenFile(const std::string& filename) {

2
src/MagnumPlugins/TgaImporter/TgaImporter.h

@ -78,7 +78,7 @@ class MAGNUM_TRADE_TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter {
private:
Features MAGNUM_TRADE_TGAIMPORTER_LOCAL doFeatures() const override;
bool MAGNUM_TRADE_TGAIMPORTER_LOCAL doIsOpened() const override;
void MAGNUM_TRADE_TGAIMPORTER_LOCAL doOpenData(Containers::ArrayReference<const unsigned char> data) override;
void MAGNUM_TRADE_TGAIMPORTER_LOCAL doOpenData(Containers::ArrayReference<const char> data) override;
void MAGNUM_TRADE_TGAIMPORTER_LOCAL doOpenFile(const std::string& filename) override;
void MAGNUM_TRADE_TGAIMPORTER_LOCAL doClose() override;
UnsignedInt MAGNUM_TRADE_TGAIMPORTER_LOCAL doImage2DCount() const override;

22
src/MagnumPlugins/WavAudioImporter/Test/WavImporterTest.cpp

@ -60,7 +60,7 @@ void WavImporterTest::wrongSize() {
Error::setOutput(&out);
WavImporter importer;
CORRADE_VERIFY(!importer.openData(Containers::Array<unsigned char>(43)));
CORRADE_VERIFY(!importer.openData(Containers::Array<char>(43)));
CORRADE_COMPARE(out.str(), "Audio::WavImporter::openData(): the file is too short: 43 bytes\n");
}
@ -97,12 +97,12 @@ void WavImporterTest::mono16() {
CORRADE_COMPARE(importer.format(), Buffer::Format::Mono16);
CORRADE_COMPARE(importer.frequency(), 44000);
Containers::Array<unsigned char> data = importer.data();
Containers::Array<char> data = importer.data();
CORRADE_COMPARE(data.size(), 4);
CORRADE_COMPARE(data[0], 0x1d);
CORRADE_COMPARE(data[1], 0x10);
CORRADE_COMPARE(data[2], 0x71);
CORRADE_COMPARE(data[3], 0xC5);
CORRADE_COMPARE(data[0], '\x1d');
CORRADE_COMPARE(data[1], '\x10');
CORRADE_COMPARE(data[2], '\x71');
CORRADE_COMPARE(data[3], '\xc5');
}
void WavImporterTest::stereo8() {
@ -111,12 +111,12 @@ void WavImporterTest::stereo8() {
CORRADE_COMPARE(importer.format(), Buffer::Format::Stereo8);
CORRADE_COMPARE(importer.frequency(), 96000);
Containers::Array<unsigned char> data = importer.data();
Containers::Array<char> data = importer.data();
CORRADE_COMPARE(data.size(), 4);
CORRADE_COMPARE(data[0], 0xde);
CORRADE_COMPARE(data[1], 0xfe);
CORRADE_COMPARE(data[2], 0xca);
CORRADE_COMPARE(data[3], 0x7e);
CORRADE_COMPARE(data[0], '\xde');
CORRADE_COMPARE(data[1], '\xfe');
CORRADE_COMPARE(data[2], '\xca');
CORRADE_COMPARE(data[3], '\x7e');
}
}}}

8
src/MagnumPlugins/WavAudioImporter/WavImporter.cpp

@ -43,7 +43,7 @@ auto WavImporter::doFeatures() const -> Features { return Feature::OpenData; }
bool WavImporter::doIsOpened() const { return _data; }
void WavImporter::doOpenData(Containers::ArrayReference<const unsigned char> data) {
void WavImporter::doOpenData(Containers::ArrayReference<const char> data) {
/* Check file size */
if(data.size() < sizeof(WavHeader)) {
Error() << "Audio::WavImporter::openData(): the file is too short:" << data.size() << "bytes";
@ -111,7 +111,7 @@ void WavImporter::doOpenData(Containers::ArrayReference<const unsigned char> dat
CORRADE_INTERNAL_ASSERT(!Utility::Endianness::isBigEndian());
/* Copy the data */
_data = Containers::Array<unsigned char>(header.subChunk2Size);
_data = Containers::Array<char>(header.subChunk2Size);
std::copy(data.begin()+sizeof(WavHeader), data.end(), _data.begin());
return;
}
@ -122,8 +122,8 @@ Buffer::Format WavImporter::doFormat() const { return _format; }
UnsignedInt WavImporter::doFrequency() const { return _frequency; }
Containers::Array<unsigned char> WavImporter::doData() {
Containers::Array<unsigned char> copy(_data.size());
Containers::Array<char> WavImporter::doData() {
Containers::Array<char> copy(_data.size());
std::copy(_data.begin(), _data.end(), copy.begin());
return copy;
}

6
src/MagnumPlugins/WavAudioImporter/WavImporter.h

@ -62,14 +62,14 @@ class WavImporter: public AbstractImporter {
private:
Features doFeatures() const override;
bool doIsOpened() const override;
void doOpenData(Containers::ArrayReference<const unsigned char> data) override;
void doOpenData(Containers::ArrayReference<const char> data) override;
void doClose() override;
Buffer::Format doFormat() const override;
UnsignedInt doFrequency() const override;
Containers::Array<unsigned char> doData() override;
Containers::Array<char> doData() override;
Containers::Array<unsigned char> _data;
Containers::Array<char> _data;
Buffer::Format _format;
UnsignedInt _frequency;
};

Loading…
Cancel
Save