Add the sequence of images specified by ith_image to the summary. Factoring this loop out into a helper function lets ith_image behave differently in the float and uint8 cases: the float case needs a temporary buffer which can be shared across calls to ith_image, but the uint8 case does not.
| 143 | // buffer which can be shared across calls to ith_image, but the uint8 case |
| 144 | // does not. |
| 145 | Status AddImages(const string& tag, int batch_size, int w, int h, int depth, |
| 146 | const std::function<Uint8Image(int)>& ith_image, |
| 147 | Summary* s) { |
| 148 | const int N = std::min<int>(max_images_, batch_size); |
| 149 | for (int i = 0; i < N; ++i) { |
| 150 | Summary::Value* v = s->add_value(); |
| 151 | // The tag depends on the number of requested images (not the number |
| 152 | // produced.) |
| 153 | // |
| 154 | // Note that later on avisu uses "/" to figure out a consistent naming |
| 155 | // convention for display, so we append "/image" to guarantee that the |
| 156 | // image(s) won't be displayed in the global scope with no name. |
| 157 | if (max_images_ > 1) { |
| 158 | v->set_tag(strings::StrCat(tag, "/image/", i)); |
| 159 | } else { |
| 160 | v->set_tag(strings::StrCat(tag, "/image")); |
| 161 | } |
| 162 | |
| 163 | auto image = ith_image(i); |
| 164 | Summary::Image* si = v->mutable_image(); |
| 165 | si->set_height(h); |
| 166 | si->set_width(w); |
| 167 | si->set_colorspace(depth); |
| 168 | const int channel_bits = 8; |
| 169 | const int compression = -1; // Use zlib default |
| 170 | if (!png::WriteImageToBuffer( |
| 171 | image.data(), w, h, w * depth, depth, channel_bits, compression, |
| 172 | si->mutable_encoded_image_string(), nullptr)) { |
| 173 | return errors::Internal("PNG encoding failed"); |
| 174 | } |
| 175 | } |
| 176 | return Status::OK(); |
| 177 | } |
| 178 | |
| 179 | template <class T> |
| 180 | static void NormalizeFloatImage(int hw, int depth, |
nothing calls this directly
no test coverage detected