I made a simple bitmapper, using the coreimage support. Keep in mind it's VERY slow. Damn python :P you pass it a 1d array of Colors, a width and height, and it gives you a layer back.
import Numeric from AppKit import * coreimage = ximport("coreimage") canvas = coreimage.canvas(WIDTH, HEIGHT) width = 50#0 # I wouldn't uncomment this height = 50#0 # or this # it took about thirty seconds to render # python is damn slow :P d = [color(0.0, 0.0, 0.0)] * width * height colormode(HSB) for x in range(width): c = color(float(x + 1) / width, 1.0, 1.0) print width, x, c for y in range(height): d[(y * width) + x] = c colormode(RGB) def better_layer_bytes(color_data, w, h, x=None, y=None, name=''): data = Numeric.array([0] * len(color_data) * 4, typecode='c') for i in range(len(color_data)): data[(i*4)] = color_data[i].r * 255 data[(i*4)+1] = color_data[i].g * 255 data[(i*4)+2] = color_data[i].b * 255 data[(i*4)+3] = color_data[i].a * 255 data = (data, None, None, None, None) img = NSBitmapImageRep.alloc().initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bytesPerRow_bitsPerPixel_(data, w, h, 8, 4, True, False, NSDeviceRGBColorSpace, w * 4, 32) img = img.TIFFRepresentation() return canvas.layer_bytes(img, w=w, h=h, x=x, y=y, name=name) l = better_layer_bytes(d, width, height, x=width, y=height) canvas.draw(0, 0)
Hi Duane, Great work! I'll integrate the code into the Core Image library.
Simple Bitmapper
Posted by Duane Bailey on Dec 28, 2007I made a simple bitmapper, using the coreimage support. Keep in mind it's VERY slow. Damn python :P
you pass it a 1d array of Colors, a width and height, and it gives you a layer back.