Created
March 4, 2013 12:00
-
-
Save dahlia/5081821 to your computer and use it in GitHub Desktop.
Wand experiments with PixelGet{Red,Green,Blue,Alpha}Quantum() functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ctypes | |
from wand.api import library | |
from wand.color import Color | |
library.PixelGetRedQuantum.argtypes = [ctypes.c_void_p] | |
library.PixelGetRedQuantum.restype = ctypes.c_size_t | |
library.PixelGetGreenQuantum.argtypes = [ctypes.c_void_p] | |
library.PixelGetGreenQuantum.restype = ctypes.c_size_t | |
library.PixelGetBlueQuantum.argtypes = [ctypes.c_void_p] | |
library.PixelGetBlueQuantum.restype = ctypes.c_size_t | |
library.PixelGetAlphaQuantum.argtypes = [ctypes.c_void_p] | |
library.PixelGetAlphaQuantum.restype = ctypes.c_size_t | |
with Color('#ff0088') as c: | |
print (c.red, c.green, c.blue, c.alpha) | |
# Prints: (1.0, 0.0, 0.5333333333333333, 1.0) | |
print ( | |
library.PixelGetRedQuantum(c.resource), | |
library.PixelGetGreenQuantum(c.resource), | |
library.PixelGetBlueQuantum(c.resource), | |
library.PixelGetAlphaQuantum(c.resource), | |
) | |
# Prints: (65535L, 0L, 34952L, 65535L) |
Apparently you can override output color depth on the convert command line using the -depth
switch:
convert -size 256x256 -depth 8 img.rgba img.png
Not sure how to do this in Wand but ImageMagick seems capable.
More:
Trouble setting RGB color depth
Controling the Quality of Images
There's a way to specify image 'depth' for the output image (image.depth(8)) but it doesn't alter the internal representation, just the output format, it seems.
So yeah, I'll need to use ScaleQuantumToChar()
or its equivalent.
@inactivist Thanks for your surveys.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
These give some clues:
Architecture
Controling the Quality of Images
Working with color
using readable pixeldata from an Image
So it looks like we're both using ImageMagick built for two bytes per pixel (Q16).