Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Tests/test_imagetk.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ def test_photoimage(self):
self.assertEqual(im_tk.width(), im.width)
self.assertEqual(im_tk.height(), im.height)

# _tkinter.TclError: this function is not yet supported
# reloaded = ImageTk.getimage(im_tk)
# self.assert_image_equal(reloaded, im)
reloaded = ImageTk.getimage(im_tk)
self.assert_image_equal(reloaded, im.convert("RGBA"))

def test_photoimage_blank(self):
# test a image using mode/size:
Expand Down
9 changes: 6 additions & 3 deletions src/PIL/ImageTk.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,13 @@ def __str__(self):


def getimage(photo):
""" This function is unimplemented """

"""Copies the contents of a PhotoImage to a PIL image memory."""
photo.tk.call("PyImagingPhotoGet", photo)
im = Image.new("RGBA", (photo.width(), photo.height()))
block = im.im

photo.tk.call("PyImagingPhotoGet", photo, block.id)

return im


def _show(image, title):
Expand Down
36 changes: 21 additions & 15 deletions src/Tk/tkImaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,18 @@ PyImagingPhotoPut(ClientData clientdata, Tcl_Interp* interp,
return TCL_OK;
}

/* Warning -- this does not work at all */
static int
PyImagingPhotoGet(ClientData clientdata, Tcl_Interp* interp,
int argc, const char **argv)
{
Imaging im;
Tk_PhotoHandle photo;
Tk_PhotoImageBlock block;
int x, y, z;

if (argc != 2) {
if (argc != 3) {
TCL_APPEND_RESULT(interp, "usage: ", argv[0],
" srcPhoto", (char *) NULL);
" srcPhoto destImage", (char *) NULL);
return TCL_ERROR;
}

Expand All @@ -172,21 +173,26 @@ PyImagingPhotoGet(ClientData clientdata, Tcl_Interp* interp,
return TCL_ERROR;
}

TK_PHOTO_GET_IMAGE(photo, &block);
/* get PIL Image handle */
im = ImagingFind(argv[2]);
if (!im) {
TCL_APPEND_RESULT(interp, "bad name", (char*) NULL);
return TCL_ERROR;
}

printf("pixelPtr = %p\n", block.pixelPtr);
printf("width = %d\n", block.width);
printf("height = %d\n", block.height);
printf("pitch = %d\n", block.pitch);
printf("pixelSize = %d\n", block.pixelSize);
printf("offset = %d %d %d %d\n", block.offset[0], block.offset[1],
block.offset[2], block.offset[3]);
TK_PHOTO_GET_IMAGE(photo, &block);

TCL_APPEND_RESULT(
interp, "this function is not yet supported", (char *) NULL
);
for (y = 0; y < block.height; y++) {
UINT8* out = (UINT8*)im->image32[y];
for (x = 0; x < block.pitch; x += block.pixelSize) {
for (z=0; z < block.pixelSize; z++) {
int offset = block.offset[z];
out[x + offset] = block.pixelPtr[y * block.pitch + x + offset];
}
}
}

return TCL_ERROR;
return TCL_OK;
}


Expand Down