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*, ...@@ -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 /**Flip the image vertically, since EMAN use top-left corner as image origin
* 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);
unsigned char *cdata = new unsigned char[nx]; unsigned char *cdata = new unsigned char[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++) {
if(data[y * nx + x] <= rendermin){ cdata[x] = (unsigned char)rendered_data[y * nx + x];
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);
}
} }
png_write_row(png_ptr, (png_byte *) cdata); png_write_row(png_ptr, (png_byte *) cdata);
} }
...@@ -415,20 +407,12 @@ int PngIO::write_data(float *data, int image_index, const Region*, ...@@ -415,20 +407,12 @@ int PngIO::write_data(float *data, int image_index, const Region*,
} }
} }
else if (depth_type == PNG_SHORT_DEPTH) { else if (depth_type == PNG_SHORT_DEPTH) {
auto [rendered_data, count] = getRenderedDataAndRendertrunc<unsigned short>(data, nx*ny);
unsigned short *sdata = new unsigned short[nx]; unsigned short *sdata = new unsigned short[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++) {
if(data[y * nx + x] <= rendermin){ sdata[x] = (unsigned short)rendered_data[y * nx + x];
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);
}
} }
png_write_row(png_ptr, (png_byte *) sdata); png_write_row(png_ptr, (png_byte *) sdata);
......
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