Returns an QImage 8-bit sRGB
(wnode)
| 23 | |
| 24 | |
| 25 | def nodeToImage(wnode): |
| 26 | """ |
| 27 | Returns an QImage 8-bit sRGB |
| 28 | """ |
| 29 | icc_profile = wnode.meta.get("icc") |
| 30 | if not icc_profile and wnode.inherit: |
| 31 | icc_profile = wnode.inheritedMetadata().get("icc") |
| 32 | if not icc_profile: |
| 33 | icc_profile = wnode.cfg["meta"]["icc"] |
| 34 | |
| 35 | icc_profile = icc_profile[0] |
| 36 | [x, y, w, h] = wnode.bounds |
| 37 | |
| 38 | conversion_not_needed = ( |
| 39 | wnode.node.colorModel() == "RGBA" |
| 40 | and wnode.node.colorDepth() == "U8" |
| 41 | and wnode.node.colorProfile().lower() == icc_profile.lower() |
| 42 | ) |
| 43 | |
| 44 | if conversion_not_needed: |
| 45 | pixel_data = wnode.node.projectionPixelData(x, y, w, h).data() |
| 46 | else: |
| 47 | temp_node = wnode.node.duplicate() |
| 48 | temp_node.setColorSpace("RGBA", "U8", icc_profile) |
| 49 | pixel_data = temp_node.projectionPixelData(x, y, w, h).data() |
| 50 | |
| 51 | return QImage(pixel_data, w, h, QImage.Format.Format_ARGB32) |
| 52 | |
| 53 | |
| 54 | def expandAndFormat(img, margin=0, is_jpg=False): |
no test coverage detected