void DeepData::merge_deep_pixels (int pixel, const DeepData &src, int srcpixel) { int srcsamples = src.samples(srcpixel); if (srcsamples == 0) return; // No samples to merge int dstsamples = samples(pixel); if (dstsamples == 0) { // Nothing in our pixel yet, so just copy src's pixel copy_deep_pixel (pixel, src, srcpixel); return; } // Need to merge the pixels // First, merge all of src's samples into our pixel set_samples (pixel, dstsamples+srcsamples); for (int i = 0; i < srcsamples; ++i) copy_deep_sample (pixel, dstsamples+i, src, srcpixel, i); // Now ALL the samples from both images are in our pixel. // Mutually split the samples against each other. sort (pixel); // sort first so we only loop once int zchan = m_impl->m_z_channel; int zbackchan = m_impl->m_zback_channel; for (int s = 0; s < samples(pixel); ++s) { float z = deep_value (pixel, zchan, s); float zback = deep_value (pixel, zbackchan, s); split (pixel, z); split (pixel, zback); } sort (pixel); // Now merge the overlaps merge_overlaps (pixel); }
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"; } } } } }