Hi,
Sorry if this is a silly question, but in all my Googling and looking through the docs, I couldn't find anything related to this besides a vague mention in the GIMP-Python documentation.
I'm writing a plugin that scales an image to 2x size using Hyllian's Super-xBR algorithm.
I have an array of RGBA values that I want to draw into a pixel region that spans the image. Formatted like this:
# Indices: 0 1 2 3 | 4 5 6 7 | 8
# Values: 235 127 0 94 | 221 67 95 255| ...
where indices 0-3 are the R, G, B, A values of the pixel at [0, 0], indices 4-7 are the values of [1, 0], etc.
The documentation says that the input data for setting a pixel region "is a string containing the binary data of the requested region", but I'm not sure how it should be formatted. The plugin I used as a basic reference, Akkana's arclayer.py (can find on their website at shallowsky), just uses array.tostring() to change the input into a string and then sets the pixel region equal to it:
# Copy the whole array back to the pixel region:
dstRgn[0:newWidth, 0:newHeight] = dest_pixels.tostring()
however, doing this simply gives me an empty(transperant, all RGBA values 0) layer when I insert the layer into the image.
Is there another, or better, way of doing something like this? Or do I just have the wrong idea completely?
This is my first time using Python or dealing with GIMP at all(I used paint NET pretty heavily before I switched off Windows), so apologies if I'm missing something obvious.
Here's some relevant code, if it helps:
original_pixel_region = tdrawable.get_pixel_rgn(0, 0, original_width, original_height, False, False)
original_pixel_data = array("B", original_pixel_region[0:original_width, 0:original_height])
# True if the pixel data is RGBA, false if it's RGB and needs alpha to be fudged.
rgba_flag = (tdrawable.type == RGBA_IMAGE)
original_pixel_data = rgba_to_int(original_width, original_height, original_pixel_data, rgba_flag)
dest_drawable = gimp.Layer(timg, "scaled", out_width, out_height, RGBA_IMAGE, 100, NORMAL_MODE)
dest_region = dest_drawable.get_pixel_rgn(0, 0, out_width, out_height, True, True)
pdb.gimp_image_resize(timg, out_width, out_height, 0, 0)
output_data = array("L", [0L] * (out_width * out_height))
# ----- (algorithm) -----
output_data = int_to_rgba(out_width, out_height, output_data)
pdb.gimp_image_insert_layer(timg, dest_drawable, None, 0)
dest_region[0:out_width, 0:out_height] = output_data.tostring()
dest_drawable.flush()
dest_drawable.update(0, 0, out_width, out_height)
timg.undo_group_end()
gimp.context_pop()
Thanks.