Commit fe3a7201 authored by shadow_walker's avatar shadow_walker
Browse files

use vector in png scaling

parent 8bdadce9
...@@ -391,37 +391,25 @@ int PngIO::write_data(float *data, int image_index, const Region*, ...@@ -391,37 +391,25 @@ int PngIO::write_data(float *data, int image_index, const Region*,
* But PNG use bottom-left corner as image origin */ * But PNG use bottom-left corner as image origin */
if (depth_type == PNG_CHAR_DEPTH) { if (depth_type == PNG_CHAR_DEPTH) {
auto [rendered_data, count] = getRenderedDataAndRendertrunc<unsigned char>(data, nx*ny); auto [rendered_data, count] = getRenderedDataAndRendertrunc<unsigned char>(data, nx*ny);
unsigned char *cdata = new unsigned char[nx]; vector<unsigned char> cdata(nx);
for (int y = (int)ny-1; y >= 0; y--) { for (int y = (int)ny-1; y >= 0; y--) {
for (int x = 0; x < (int)nx; x++) { for (int x = 0; x < (int)nx; x++) {
cdata[x] = (unsigned char)rendered_data[y * nx + x]; cdata[x] = (unsigned char)rendered_data[y * nx + x];
} }
png_write_row(png_ptr, (png_byte *) cdata); png_write_row(png_ptr, (png_byte *) cdata.data());
}
if( cdata )
{
delete[]cdata;
cdata = 0;
} }
} }
else if (depth_type == PNG_SHORT_DEPTH) { else if (depth_type == PNG_SHORT_DEPTH) {
auto [rendered_data, count] = getRenderedDataAndRendertrunc<unsigned short>(data, nx*ny); auto [rendered_data, count] = getRenderedDataAndRendertrunc<unsigned short>(data, nx*ny);
unsigned short *sdata = new unsigned short[nx]; vector<unsigned short> sdata(nx);
for (int y = (int)ny-1; y >= 0 ; y--) { for (int y = (int)ny-1; y >= 0 ; y--) {
for (int x = 0; x < (int)nx; x++) { for (int x = 0; x < (int)nx; x++) {
sdata[x] = (unsigned short)rendered_data[y * nx + x]; sdata[x] = (unsigned short)rendered_data[y * nx + x];
} }
png_write_row(png_ptr, (png_byte *) sdata); png_write_row(png_ptr, (png_byte *) sdata.data());
}
if( sdata )
{
delete[]sdata;
sdata = 0;
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment