Summary: | strange/wrong behavoiur when using cairo.ImageSurface.create_for_data with alpha values != 255 | ||
---|---|---|---|
Product: | pycairo | Reporter: | Tobias Bonnke <tobias.bonnke> |
Component: | general | Assignee: | Steve Chaplin <d74n5pohf9> |
Status: | RESOLVED NOTABUG | QA Contact: | |
Severity: | normal | ||
Priority: | medium | CC: | tobias.bonnke |
Version: | unspecified | ||
Hardware: | x86 (IA32) | ||
OS: | Windows (All) | ||
Whiteboard: | |||
i915 platform: | i915 features: | ||
Attachments: |
The "correctly" created gradient image which looks like expected
The "incorrectly" looking gradient image, the "unexpected/wrong" result so to say |
Description
Tobias Bonnke
2006-12-07 03:03:36 UTC
Created attachment 7998 [details]
The "correctly" created gradient image which looks like expected
Created attachment 7999 [details]
The "incorrectly" looking gradient image, the "unexpected/wrong" result so to say
This image should look like "channel_test_alpha_const.png", the only difference
should be that each scanline's alpha should increment from y=0, alpha=0 to
y=255, alpha=255. But instead the image is not a linear gradient at all.
This is a due to the format CAIRO_FORMAT_ARGB32 using pre-multiplied alpha. That is, 50% transparent red is 0x80800000, not 0x80ff0000. Something like this shound produce better results: pelData = array.array('B', [0] * imgW * imgH * 4) for y in range(imgH): for x in range(imgW): offset = (x + (y * imgW)) * 4 alpha = y pelData[offset+0] = 0 pelData[offset+1] = 0 pelData[offset+2] = int((x * alpha)/255) pelData[offset+3] = alpha img = cairo.ImageSurface.create_for_data(pelData, cairo.FORMAT_ARGB32, imgW, imgH, imgW * 4) img.write_to_png("channel_test_alpha_var.png") (But if its just gradients you want, cairo has its own functions to create gradients) |
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.