summaryrefslogtreecommitdiff
path: root/platform/default
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-11-23 16:35:32 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-11-23 17:28:44 -0800
commit6ff3ef55f8406d45d24cb5b280fc19b888c2138e (patch)
tree8e216120d36e27ed4538a108e19159573e4477a9 /platform/default
parent36081f6486201d9bd316f3a8ceb5a38ad2e97310 (diff)
downloadqtlocation-mapboxgl-6ff3ef55f8406d45d24cb5b280fc19b888c2138e.tar.gz
[core] Remove unused
Diffstat (limited to 'platform/default')
-rw-r--r--platform/default/image.cpp3
-rw-r--r--platform/default/jpeg_reader.cpp19
-rw-r--r--platform/default/png_reader.cpp71
3 files changed, 39 insertions, 54 deletions
diff --git a/platform/default/image.cpp b/platform/default/image.cpp
index bbd5d02b6f..4da607d97a 100644
--- a/platform/default/image.cpp
+++ b/platform/default/image.cpp
@@ -81,8 +81,7 @@ Image::Image(std::string const& data)
auto reader = getImageReader(reinterpret_cast<const uint8_t*>(data.c_str()), data.size());
width = reader->width();
height = reader->height();
- img = std::make_unique<uint8_t[]>(width * height * 4);
- reader->read(0, 0, width, height, img.get());
+ img = reader->read();
}
catch (ImageReaderException const& ex)
{
diff --git a/platform/default/jpeg_reader.cpp b/platform/default/jpeg_reader.cpp
index dac18f32d2..a537eeeb08 100644
--- a/platform/default/jpeg_reader.cpp
+++ b/platform/default/jpeg_reader.cpp
@@ -145,8 +145,10 @@ unsigned JpegReader<T>::height() const
}
template <typename T>
-void JpegReader<T>::read(unsigned x0, unsigned y0, unsigned w, unsigned h, uint8_t* image)
+std::unique_ptr<uint8_t[]> JpegReader<T>::read()
{
+ std::unique_ptr<uint8_t[]> image = std::make_unique<uint8_t[]>(width_ * height_ * 4);
+
stream_.clear();
stream_.seekg(0, std::ios_base::beg);
@@ -167,19 +169,16 @@ void JpegReader<T>::read(unsigned x0, unsigned y0, unsigned w, unsigned h, uint8
row_stride = cinfo.output_width * cinfo.output_components;
buffer = (*cinfo.mem->alloc_sarray) ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
- w = std::min(w,width_ - x0);
- h = std::min(h,height_ - y0);
-
- const std::unique_ptr<unsigned int[]> out_row(new unsigned int[w]);
+ const std::unique_ptr<unsigned int[]> out_row(new unsigned int[width_]);
unsigned row = 0;
while (cinfo.output_scanline < cinfo.output_height)
{
jpeg_read_scanlines(&cinfo, buffer, 1);
- if (row >= y0 && row < y0 + h)
+ if (row < height_)
{
- for (unsigned int x = 0; x < w; ++x)
+ for (unsigned int x = 0; x < width_; ++x)
{
- unsigned col = x + x0;
+ unsigned col = x;
r = buffer[0][cinfo.output_components * col];
if (cinfo.output_components > 2)
{
@@ -191,11 +190,13 @@ void JpegReader<T>::read(unsigned x0, unsigned y0, unsigned w, unsigned h, uint8
}
out_row[x] = (0xff << 24) | (b << 16) | (g << 8) | r;
}
- std::copy((char*)out_row.get(), (char*)out_row.get() + w*4, image + (row - y0)*width_*4);
+ std::copy((char*)out_row.get(), (char*)out_row.get() + width_*4, image.get() + row*width_*4);
}
++row;
}
jpeg_finish_decompress(&cinfo);
+
+ return image;
}
template class JpegReader<boost::iostreams::array_source>;
diff --git a/platform/default/png_reader.cpp b/platform/default/png_reader.cpp
index 204c4874f2..1f7207337c 100644
--- a/platform/default/png_reader.cpp
+++ b/platform/default/png_reader.cpp
@@ -115,8 +115,10 @@ unsigned PngReader<T>::height() const
}
template <typename T>
-void PngReader<T>::read(unsigned x0, unsigned y0, unsigned w, unsigned h, uint8_t* image)
+std::unique_ptr<uint8_t[]> PngReader<T>::read()
{
+ std::unique_ptr<uint8_t[]> image = std::make_unique<uint8_t[]>(width_ * height_ * 4);
+
stream_.clear();
stream_.seekg(0, std::ios_base::beg);
@@ -162,54 +164,37 @@ void PngReader<T>::read(unsigned x0, unsigned y0, unsigned w, unsigned h, uint8_
png_set_alpha_mode(png_ptr, PNG_ALPHA_PREMULTIPLIED, PNG_GAMMA_LINEAR);
#endif
- if (x0 == 0 && y0 == 0 && w >= width_ && h >= height_)
+ if (png_get_interlace_type(png_ptr,info_ptr) == PNG_INTERLACE_ADAM7)
{
- if (png_get_interlace_type(png_ptr,info_ptr) == PNG_INTERLACE_ADAM7)
- {
- png_set_interlace_handling(png_ptr); // FIXME: libpng bug?
- // according to docs png_read_image
- // "..automatically handles interlacing,
- // so you don't need to call png_set_interlace_handling()"
- }
- png_read_update_info(png_ptr, info_ptr);
- // we can read whole image at once
- // alloc row pointers
- const std::unique_ptr<png_bytep[]> rows(new png_bytep[height_]);
- for (unsigned row = 0; row < height_; ++row)
- rows[row] = (png_bytep)image + row * width_ * 4 ;
- png_read_image(png_ptr, rows.get());
+ png_set_interlace_handling(png_ptr); // FIXME: libpng bug?
+ // according to docs png_read_image
+ // "..automatically handles interlacing,
+ // so you don't need to call png_set_interlace_handling()"
+ }
+ png_read_update_info(png_ptr, info_ptr);
+ // we can read whole image at once
+ // alloc row pointers
+ const std::unique_ptr<png_bytep[]> rows(new png_bytep[height_]);
+ for (unsigned row = 0; row < height_; ++row)
+ rows[row] = (png_bytep)image.get() + row * width_ * 4 ;
+ png_read_image(png_ptr, rows.get());
#ifndef PNG_ALPHA_PREMULTIPLIED
- // Manually premultiply the image if libpng didn't do it for us.
- for (unsigned row = 0; row < height_; ++row) {
- for (unsigned x = 0; x < width_; x++) {
- png_byte* ptr = &(rows[row][x * 4]);
- const float a = ptr[3] / 255.0f;
- ptr[0] *= a;
- ptr[1] *= a;
- ptr[2] *= a;
- }
- }
-#endif
- }
- else
- {
- png_read_update_info(png_ptr, info_ptr);
- w=std::min(w, width_ - x0);
- h=std::min(h, height_ - y0);
- unsigned rowbytes=png_get_rowbytes(png_ptr, info_ptr);
- const std::unique_ptr<png_byte[]> row(new png_byte[rowbytes]);
- for (unsigned i = 0; i < height_; ++i)
- {
- png_read_row(png_ptr,row.get(),0);
- if (i >= y0 && i < (y0 + h))
- {
- // TODO: premultiply this
- std::copy(&row[x0 * 4], &row[x0 * 4] + w * 4, image + i * width_* 4);
- }
+ // Manually premultiply the image if libpng didn't do it for us.
+ for (unsigned row = 0; row < height_; ++row) {
+ for (unsigned x = 0; x < width_; x++) {
+ png_byte* ptr = &(rows[row][x * 4]);
+ const float a = ptr[3] / 255.0f;
+ ptr[0] *= a;
+ ptr[1] *= a;
+ ptr[2] *= a;
}
}
+#endif
+
png_read_end(png_ptr,0);
+
+ return image;
}
template class PngReader<boost::iostreams::array_source>;