bool DeepData::copy_deep_pixel (int pixel, const DeepData &src, int srcpixel) { if (pixel < 0 || pixel >= pixels()) { // std::cout << "dst pixel was " << pixel << "\n"; DASSERT (0 && "Out of range pixel index"); return false; } if (srcpixel < 0 || srcpixel >= src.pixels()) { // Copying empty pixel -- set samples to 0 and we're done // std::cout << "Source pixel was " << srcpixel << "\n"; set_samples (pixel, 0); return true; } int nchans = channels(); if (nchans != src.channels()) { DASSERT (0 && "Number of channels don't match."); return false; } int nsamples = src.samples(srcpixel); set_samples (pixel, nsamples); if (nsamples == 0) return true; bool sametypes = samplesize() == src.samplesize(); if (sametypes) for (int c = 0; c < nchans; ++c) sametypes &= (channeltype(c) == src.channeltype(c)); if (sametypes) memcpy (data_ptr (pixel, 0, 0), src.data_ptr (srcpixel, 0, 0), samplesize()*nsamples); else { for (int c = 0; c < nchans; ++c) { if (channeltype(c) == TypeDesc::UINT32 && src.channeltype(c) == TypeDesc::UINT32) for (int s = 0; s < nsamples; ++s) set_deep_value (pixel, c, s, src.deep_value_uint (srcpixel, c, s)); else for (int s = 0; s < nsamples; ++s) set_deep_value (pixel, c, s, src.deep_value (srcpixel, c, s)); } } return true; }
bool DeepData::copy_deep_sample (int pixel, int sample, const DeepData &src, int srcpixel, int srcsample) { const void *srcdata = src.data_ptr (srcpixel, 0, srcsample); int nchans = channels(); if (! srcdata || nchans != src.channels()) return false; int nsamples = src.samples(srcpixel); set_samples (pixel, std::max (samples(pixel), nsamples)); for (int c = 0; c < m_nchannels; ++c) { if (channeltype(c) == TypeDesc::UINT32 && src.channeltype(c) == TypeDesc::UINT32) set_deep_value (pixel, c, sample, src.deep_value_uint (srcpixel, c, srcsample)); else set_deep_value (pixel, c, sample, src.deep_value (srcpixel, c, srcsample)); } return true; }
static void dump_data (ImageInput *input, const print_info_options &opt) { const ImageSpec &spec (input->spec()); if (spec.deep) { // Special handling of deep data DeepData dd; if (! input->read_native_deep_image (dd)) { printf (" dump data: could not read image\n"); return; } int nc = spec.nchannels; for (int z = 0, pixel = 0; z < spec.depth; ++z) { for (int y = 0; y < spec.height; ++y) { for (int x = 0; x < spec.width; ++x, ++pixel) { int nsamples = dd.samples(pixel); if (nsamples == 0 && ! opt.dumpdata_showempty) continue; std::cout << " Pixel ("; if (spec.depth > 1 || spec.z != 0) std::cout << Strutil::format("%d, %d, %d", x+spec.x, y+spec.y, z+spec.z); else std::cout << Strutil::format("%d, %d", x+spec.x, y+spec.y); std::cout << "): " << nsamples << " samples" << (nsamples ? ":" : ""); for (int s = 0; s < nsamples; ++s) { if (s) std::cout << " / "; for (int c = 0; c < nc; ++c) { std::cout << " " << spec.channelnames[c] << "="; if (dd.channeltype(c) == TypeDesc::UINT) std::cout << dd.deep_value_uint(pixel, c, s); else std::cout << dd.deep_value (pixel, c, s); } } std::cout << "\n"; } } } } else { std::vector<float> buf(spec.image_pixels() * spec.nchannels); if (! input->read_image (TypeDesc::FLOAT, &buf[0])) { printf (" dump data: could not read image\n"); return; } const float *ptr = &buf[0]; for (int z = 0; z < spec.depth; ++z) { for (int y = 0; y < spec.height; ++y) { for (int x = 0; x < spec.width; ++x) { if (! opt.dumpdata_showempty) { bool allzero = true; for (int c = 0; c < spec.nchannels && allzero; ++c) allzero &= (ptr[c] == 0.0f); if (allzero) { ptr += spec.nchannels; continue; } } if (spec.depth > 1 || spec.z != 0) std::cout << Strutil::format(" Pixel (%d, %d, %d):", x+spec.x, y+spec.y, z+spec.z); else std::cout << Strutil::format(" Pixel (%d, %d):", x+spec.x, y+spec.y); for (int c = 0; c < spec.nchannels; ++c, ++ptr) { std::cout << ' ' << (*ptr); } std::cout << "\n"; } } } } }