Changeset View
Changeset View
Standalone View
Standalone View
plugins/impex/exr/exr_converter.cc
Context not available. | |||||
133 | struct EXRConverter::Private { | 133 | struct EXRConverter::Private { | ||
---|---|---|---|---|---|
134 | Private() | 134 | Private() | ||
135 | : doc(0) | 135 | : doc(0) | ||
136 | , alphaWasModified(false) | | |||
137 | , showNotifications(false) | 136 | , showNotifications(false) | ||
138 | {} | 137 | {} | ||
139 | 138 | | |||
140 | KisImageSP image; | 139 | KisImageSP image; | ||
141 | KisDocument *doc; | 140 | KisDocument *doc; | ||
142 | 141 | | |||
143 | bool alphaWasModified; | | |||
144 | bool showNotifications; | 142 | bool showNotifications; | ||
145 | 143 | | |||
146 | QString errorMessage; | 144 | QString errorMessage; | ||
Context not available. | |||||
295 | template <class WrapperType> | 293 | template <class WrapperType> | ||
296 | void EXRConverter::Private::unmultiplyAlpha(typename WrapperType::pixel_type *pixel) | 294 | void EXRConverter::Private::unmultiplyAlpha(typename WrapperType::pixel_type *pixel) | ||
297 | { | 295 | { | ||
298 | typedef typename WrapperType::pixel_type pixel_type; | | |||
299 | typedef typename WrapperType::channel_type channel_type; | 296 | typedef typename WrapperType::channel_type channel_type; | ||
300 | 297 | | |||
301 | WrapperType srcPixel(*pixel); | 298 | WrapperType srcPixel(*pixel); | ||
302 | 299 | | |||
303 | if (!srcPixel.checkMultipliedColorsConsistent()) { | 300 | channel_type newAlpha = alphaEpsilon<channel_type>(); | ||
304 | 301 | if (srcPixel.alpha() > newAlpha){ | |||
305 | channel_type newAlpha = srcPixel.alpha(); | 302 | newAlpha = srcPixel.alpha(); | ||
306 | | ||||
307 | pixel_type __dstPixelData; | | |||
308 | WrapperType dstPixel(__dstPixelData); | | |||
309 | | ||||
310 | /** | | |||
311 | * Division by a tiny alpha may result in an overflow of half | | |||
312 | * value. That is why we use safe iterational approach. | | |||
313 | */ | | |||
314 | while (1) { | | |||
315 | dstPixel.setUnmultiplied(srcPixel.pixel, newAlpha); | | |||
316 | | ||||
317 | if (dstPixel.checkUnmultipliedColorsConsistent(srcPixel.pixel)) { | | |||
318 | break; | | |||
319 | } | | |||
320 | | ||||
321 | newAlpha += alphaEpsilon<channel_type>(); | | |||
322 | alphaWasModified = true; | | |||
323 | } | | |||
324 | | ||||
325 | *pixel = dstPixel.pixel; | | |||
326 | | ||||
327 | | ||||
328 | } else if (srcPixel.alpha() > 0.0) { | | |||
329 | srcPixel.setUnmultiplied(srcPixel.pixel, srcPixel.alpha()); | | |||
330 | } | 303 | } | ||
304 | srcPixel.setUnmultiplied(srcPixel.pixel, newAlpha); | ||||
331 | } | 305 | } | ||
332 | 306 | | |||
333 | template <typename T, typename Pixel, int size, int alphaPos> | 307 | template <typename T, typename Pixel, int size, int alphaPos> | ||
Context not available. | |||||
863 | // Set projectionColor to opaque | 837 | // Set projectionColor to opaque | ||
864 | d->image->setDefaultProjectionColor(KoColor(Qt::transparent, colorSpace)); | 838 | d->image->setDefaultProjectionColor(KoColor(Qt::transparent, colorSpace)); | ||
865 | 839 | | |||
866 | // After reading the image, notify the user about changed alpha. | | |||
867 | if (d->alphaWasModified) { | | |||
868 | QString msg = | | |||
869 | i18nc("@info", | | |||
870 | "The image contains pixels with zero alpha channel and non-zero " | | |||
871 | "color channels. Krita has modified those pixels to have " | | |||
872 | "at least some alpha. The initial values will <i>not</i> " | | |||
873 | "be reverted on saving the image back." | | |||
874 | "<br/><br/>" | | |||
875 | "This will hardly make any visual difference just keep it in mind."); | | |||
876 | if (d->showNotifications) { | | |||
877 | QMessageBox::information(0, i18nc("@title:window", "EXR image has been modified"), msg); | | |||
878 | } else { | | |||
879 | warnKrita << "WARNING:" << msg; | | |||
880 | } | | |||
881 | } | | |||
882 | | ||||
883 | if (!extraLayersInfo.isNull()) { | 840 | if (!extraLayersInfo.isNull()) { | ||
884 | KisExrLayersSorter sorter(extraLayersInfo, d->image); | 841 | KisExrLayersSorter sorter(extraLayersInfo, d->image); | ||
885 | } | 842 | } | ||
Context not available. |