[core] standardize on uint16_t for texture sizes

This commit is contained in:
Konstantin Käfer
2016-08-22 17:57:22 +02:00
parent 512037cfdc
commit 63e53de157
15 changed files with 42 additions and 36 deletions

View File

@@ -52,7 +52,7 @@ public:
// Reads the pixel data from the current framebuffer. If your View implementation
// doesn't support reading from the framebuffer, return a null pointer.
virtual PremultipliedImage readStillImage();
virtual PremultipliedImage readStillImage(std::array<uint16_t, 2> size = {{ 0, 0 }});
// Notifies a watcher of map x/y/scale/rotation changes.
virtual void notifyMapChange(MapChange change);

View File

@@ -45,7 +45,7 @@ public:
void deactivate() override;
void notifyMapChange(MapChange) override;
PremultipliedImage readStillImage() override;
PremultipliedImage readStillImage(std::array<uint16_t, 2> size = {{ 0, 0 }}) override;
void resize(uint16_t width, uint16_t height);
void setMapChangeCallback(std::function<void(MapChange)>&& cb) { mapChangeCallback = std::move(cb); }

View File

@@ -18,12 +18,12 @@ class Image : private util::noncopyable {
public:
Image() = default;
Image(size_t w, size_t h)
Image(uint16_t w, uint16_t h)
: width(w),
height(h),
data(std::make_unique<uint8_t[]>(size())) {}
Image(size_t w, size_t h, std::unique_ptr<uint8_t[]> data_)
Image(uint16_t w, uint16_t h, std::unique_ptr<uint8_t[]> data_)
: width(w),
height(h),
data(std::move(data_)) {}
@@ -46,11 +46,11 @@ public:
rhs.data.get() + rhs.size());
}
size_t stride() const { return width * 4; }
size_t size() const { return width * height * 4; }
size_t stride() const { return static_cast<size_t>(width) * 4; }
size_t size() const { return static_cast<size_t>(width) * height * 4; }
size_t width = 0;
size_t height = 0;
uint16_t width = 0;
uint16_t height = 0;
std::unique_ptr<uint8_t[]> data;
};

View File

@@ -208,7 +208,7 @@ void NativeMapView::render() {
// take snapshot
const unsigned int w = fbWidth;
const unsigned int h = fbHeight;
mbgl::PremultipliedImage image { w, h };
mbgl::PremultipliedImage image { static_cast<uint16_t>(w), static_cast<uint16_t>(h) };
MBGL_CHECK_ERROR(glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, image.data.get()));
const size_t stride = image.stride();
auto tmp = std::make_unique<uint8_t[]>(stride);

View File

@@ -92,7 +92,8 @@ PremultipliedImage decodeImage(const std::string &source_data) {
throw std::runtime_error("CGColorSpaceCreateDeviceRGB failed");
}
PremultipliedImage result { CGImageGetWidth(image), CGImageGetHeight(image) };
PremultipliedImage result{ static_cast<uint16_t>(CGImageGetWidth(image)),
static_cast<uint16_t>(CGImageGetHeight(image)) };
CGContextRef context = CGBitmapContextCreate(result.data.get(), result.width, result.height, 8, result.stride(),
color_space, kCGImageAlphaPremultipliedLast);

View File

@@ -40,19 +40,21 @@ void HeadlessView::resize(const uint16_t width, const uint16_t height) {
needsResize = true;
}
PremultipliedImage HeadlessView::readStillImage() {
PremultipliedImage HeadlessView::readStillImage(std::array<uint16_t, 2> size) {
assert(active);
const unsigned int w = dimensions[0] * pixelRatio;
const unsigned int h = dimensions[1] * pixelRatio;
if (!size[0] || !size[1]) {
size[0] = dimensions[0] * pixelRatio;
size[1] = dimensions[1] * pixelRatio;
}
PremultipliedImage image { w, h };
MBGL_CHECK_ERROR(glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, image.data.get()));
PremultipliedImage image { size[0], size[1] };
MBGL_CHECK_ERROR(glReadPixels(0, 0, size[0], size[1], GL_RGBA, GL_UNSIGNED_BYTE, image.data.get()));
const auto stride = image.stride();
auto tmp = std::make_unique<uint8_t[]>(stride);
uint8_t* rgba = image.data.get();
for (int i = 0, j = h - 1; i < j; i++, j--) {
for (int i = 0, j = size[1] - 1; i < j; i++, j--) {
std::memcpy(tmp.get(), rgba + i * stride, stride);
std::memcpy(rgba + i * stride, rgba + j * stride, stride);
std::memcpy(rgba + j * stride, tmp.get(), stride);

View File

@@ -119,7 +119,7 @@ PremultipliedImage decodeJPEG(const uint8_t* data, size_t size) {
size_t components = cinfo.output_components;
size_t rowStride = components * width;
PremultipliedImage image { width, height };
PremultipliedImage image { static_cast<uint16_t>(width), static_cast<uint16_t>(height) };
uint8_t* dst = image.data.get();
JSAMPARRAY buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr) &cinfo, JPOOL_IMAGE, rowStride, 1);

View File

@@ -80,7 +80,7 @@ PremultipliedImage decodePNG(const uint8_t* data, size_t size) {
int color_type = 0;
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, nullptr, nullptr, nullptr);
UnassociatedImage image { width, height };
UnassociatedImage image { static_cast<uint16_t>(width), static_cast<uint16_t>(height) };
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_expand(png_ptr);

View File

@@ -23,7 +23,8 @@ PremultipliedImage decodeWebP(const uint8_t* data, size_t size) {
throw std::runtime_error("failed to decode WebP data");
}
UnassociatedImage image { size_t(width), size_t(height), std::move(webp) };
UnassociatedImage image{ static_cast<uint16_t>(width), static_cast<uint16_t>(height),
std::move(webp) };
return util::premultiply(std::move(image));
}

View File

@@ -2523,18 +2523,18 @@ public:
[NSOpenGLContext clearCurrentContext];
}
mbgl::PremultipliedImage readStillImage() override {
auto size = getFramebufferSize();
const unsigned int w = size[0];
const unsigned int h = size[1];
mbgl::PremultipliedImage image { w, h };
MBGL_CHECK_ERROR(glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, image.data.get()));
mbgl::PremultipliedImage readStillImage(std::array<uint16_t, 2> size = {{ 0, 0 }}) override {
if (!size[0] || !size[1]) {
size = getFramebufferSize();
}
mbgl::PremultipliedImage image { size[0], size[1] };
MBGL_CHECK_ERROR(glReadPixels(0, 0, size[0], size[1], GL_RGBA, GL_UNSIGNED_BYTE, image.data.get()));
const size_t stride = image.stride();
auto tmp = std::make_unique<uint8_t[]>(stride);
uint8_t *rgba = image.data.get();
for (int i = 0, j = h - 1; i < j; i++, j--) {
for (int i = 0, j = size[1] - 1; i < j; i++, j--) {
std::memcpy(tmp.get(), rgba + i * stride, stride);
std::memcpy(rgba + i * stride, rgba + j * stride, stride);
std::memcpy(rgba + j * stride, tmp.get(), stride);

View File

@@ -57,7 +57,7 @@ PremultipliedImage decodeImage(const std::string& string) {
auto img = std::make_unique<uint8_t[]>(image.byteCount());
memcpy(img.get(), image.constBits(), image.byteCount());
return { size_t(image.width()), size_t(image.height()), std::move(img) };
return { static_cast<uint16_t>(image.width()), static_cast<uint16_t>(image.height()),
std::move(img) };
}
}

View File

@@ -119,11 +119,13 @@ std::unique_ptr<const mbgl::SpriteImage> toSpriteImage(const QImage &sprite) {
auto img = std::make_unique<uint8_t[]>(swapped.byteCount());
memcpy(img.get(), swapped.constBits(), swapped.byteCount());
return std::make_unique<mbgl::SpriteImage>(mbgl::PremultipliedImage
{ size_t(swapped.width()), size_t(swapped.height()), std::move(img) }, 1.0);
return std::make_unique<mbgl::SpriteImage>(
mbgl::PremultipliedImage{ static_cast<uint16_t>(swapped.width()),
static_cast<uint16_t>(swapped.height()), std::move(img) },
1.0);
}
}
} // namespace
/*!
\class QMapboxGLSettings

View File

@@ -10,7 +10,7 @@ void View::initialize(Map *map_) {
map = map_;
}
PremultipliedImage View::readStillImage() {
PremultipliedImage View::readStillImage(std::array<uint16_t, 2>) {
return {};
}

View File

@@ -18,7 +18,7 @@ GLuint Raster::getID() const {
return texture ? *texture : 0;
}
std::array<size_t, 2> Raster::getSize() const {
std::array<uint16_t, 2> Raster::getSize() const {
return size;
}

View File

@@ -38,12 +38,12 @@ public:
GLuint getID() const;
// size of uploaded image.
std::array<size_t, 2> getSize() const;
std::array<uint16_t, 2> getSize() const;
private:
// raw pixels have been loaded
std::atomic<bool> loaded { false };
std::array<size_t, 2> size = {{ 0, 0 }};
std::array<uint16_t, 2> size = {{ 0, 0 }};
// filters
Scaling filter = Scaling::Nearest;