| 103 | |
| 104 | |
| 105 | bool |
| 106 | ImageBufAlgo::IBAprep (ROI &roi, ImageBuf *dst, |
| 107 | const ImageBuf *A, const ImageBuf *B, |
| 108 | ImageSpec *force_spec, int prepflags) |
| 109 | { |
| 110 | if ((A && !A->initialized()) || (B && !B->initialized())) { |
| 111 | if (dst) |
| 112 | dst->error ("Uninitialized input image"); |
| 113 | return false; |
| 114 | } |
| 115 | if (dst->initialized()) { |
| 116 | // Valid destination image. Just need to worry about ROI. |
| 117 | if (roi.defined()) { |
| 118 | // Shrink-wrap ROI to the destination (including chend) |
| 119 | roi = roi_intersection (roi, get_roi(dst->spec())); |
| 120 | } else { |
| 121 | // No ROI? Set it to all of dst's pixel window. |
| 122 | roi = get_roi (dst->spec()); |
| 123 | } |
| 124 | // If the dst is initialized but is a cached image, we'll need |
| 125 | // to fully read it into allocated memory so that we're able |
| 126 | // to write to it subsequently. |
| 127 | if (dst->storage() == ImageBuf::IMAGECACHE) { |
| 128 | dst->read (dst->subimage(), dst->miplevel(), true /*force*/); |
| 129 | ASSERT (dst->storage() == ImageBuf::LOCALBUFFER); |
| 130 | } |
| 131 | } else { |
| 132 | // Not an initialized destination image! |
| 133 | ASSERT ((A || roi.defined()) && |
| 134 | "ImageBufAlgo without any guess about region of interest"); |
| 135 | ROI full_roi; |
| 136 | if (! roi.defined()) { |
| 137 | // No ROI -- make it the union of the pixel regions of the inputs |
| 138 | roi = get_roi (A->spec()); |
| 139 | full_roi = get_roi_full (A->spec()); |
| 140 | if (B) { |
| 141 | roi = roi_union (roi, get_roi (B->spec())); |
| 142 | full_roi = roi_union (full_roi, get_roi_full (B->spec())); |
| 143 | } |
| 144 | } else { |
| 145 | if (A) |
| 146 | roi.chend = std::min (roi.chend, A->nchannels()); |
| 147 | full_roi = roi; |
| 148 | } |
| 149 | // Now we allocate space for dst. Give it A's spec, but adjust |
| 150 | // the dimensions to match the ROI. |
| 151 | ImageSpec spec; |
| 152 | if (A) { |
| 153 | // If there's an input image, give dst A's spec (with |
| 154 | // modifications detailed below...) |
| 155 | spec = force_spec ? (*force_spec) : A->spec(); |
| 156 | // For two inputs, if they aren't the same data type, punt and |
| 157 | // allocate a float buffer. If the user wanted something else, |
| 158 | // they should have pre-allocated dst with their desired format. |
| 159 | if (B && A->spec().format != B->spec().format) |
| 160 | spec.set_format (TypeDesc::FLOAT); |
| 161 | // No good can come from automatically polluting an ImageBuf |
| 162 | // with some other ImageBuf's tile sizes. |
nothing calls this directly
no test coverage detected