Commit 8bdadce9 authored by shadow_walker's avatar shadow_walker
Browse files

new scaling in png

parent a73d9bb9
......@@ -390,20 +390,12 @@ int PngIO::write_data(float *data, int image_index, const Region*,
/**Flip the image vertically, since EMAN use top-left corner as image origin
* But PNG use bottom-left corner as image origin */
if (depth_type == PNG_CHAR_DEPTH) {
auto [rendered_data, count] = getRenderedDataAndRendertrunc<unsigned char>(data, nx*ny);
unsigned char *cdata = new unsigned char[nx];
for (int y = (int)ny-1; y >= 0; y--) {
for (int x = 0; x < (int)nx; x++) {
if(data[y * nx + x] <= rendermin){
cdata[x] = 0;
}
else if(data[y * nx + x] >= rendermax) {
cdata[x] = UCHAR_MAX;
}
else {
cdata[x] = (unsigned char)((data[y * nx + x] - rendermin) /
(rendermax - rendermin) * 256);
}
cdata[x] = (unsigned char)rendered_data[y * nx + x];
}
png_write_row(png_ptr, (png_byte *) cdata);
}
......@@ -415,20 +407,12 @@ int PngIO::write_data(float *data, int image_index, const Region*,
}
}
else if (depth_type == PNG_SHORT_DEPTH) {
auto [rendered_data, count] = getRenderedDataAndRendertrunc<unsigned short>(data, nx*ny);
unsigned short *sdata = new unsigned short[nx];
for (int y = (int)ny-1; y >= 0 ; y--) {
for (int x = 0; x < (int)nx; x++) {
if(data[y * nx + x] <= rendermin){
sdata[x] = 0;
}
else if(data[y * nx + x] >= rendermax) {
sdata[x] = USHRT_MAX;
}
else {
sdata[x] = (unsigned short)((data[y * nx + x] - rendermin) /
(rendermax - rendermin) * 65536);
}
sdata[x] = (unsigned short)rendered_data[y * nx + x];
}
png_write_row(png_ptr, (png_byte *) sdata);
......
Markdown is supported
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