Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tk_PhotoGetImage: whivh block parameter are constant

34 views
Skip to first unread message

Harald Oehlmann

unread,
Nov 27, 2018, 2:05:26 AM11/27/18
to
Dear Team,

I want to put a tk photo onto a windows gdi object.

There are multiple questions:

a) Sample code
There should be somewhere the code for that in Tk, as Tk is displaying
photos withing labels widgets.
And the code must be Windows specific, as Windows GDI is very special.

I only found the wm icon code in win/tkWInWm.c (proc WmIconphotoCmd()).

Here, the tk image is taken by name. The image data is taken by
Tk_PhotoGetImage.

The following structure is returned:

typedef struct {
unsigned char *pixelPtr;
int width;
int height;
int pitch;
int pixelSize;
int offset[4];
} Tk_PhotoImageBlock;

The returned block parameters are not checked at all (except width and
height). It is supposed, that each pixel is 4 bite RGBA one after the other.

E.G. the following contents is supposed:

offset[0]=0,offset[1]=1,offset[2]=2,offset[3]=3
pixelSize=4
pitch = 4*width

Here are my questions:

- is it a general rule, that the photos are returned in this format by
tk_PhotoGetImage ?

- is there other sample code available ?

Thanks for any answer,
Harald

Christian Gollwitzer

unread,
Nov 27, 2018, 2:28:24 AM11/27/18
to
Hi Harald,

Am 27.11.18 um 08:05 schrieb Harald Oehlmann:
> Dear Team,
>
> I want to put a tk photo onto a windows gdi object.
>
> There are multiple questions:
>
> a) Sample code
> There should be somewhere the code for that in Tk, as Tk is displaying
> photos withing labels widgets.
> And the code must be Windows specific, as Windows GDI is very special.
>
> I only found the wm icon code in win/tkWInWm.c (proc WmIconphotoCmd()).

Are you sure it must be Windows specific? The code for displaying a
photo image is in tkImgPhInstance, see here:

https://github.com/tcltk/tk/blob/master/generic/tkImgPhInstance.c#L602

which subsequently calls TkPutImage() to do the real work. Can't you use
that without writing platform specific code?

>
> Here, the tk image is taken by name. The image data is taken by
> Tk_PhotoGetImage.
>
> The following structure is returned:
>
> typedef struct {
> unsigned char *pixelPtr;
> int width;
> int height;
> int pitch;
> int pixelSize;
> int offset[4];
> } Tk_PhotoImageBlock;
>
> The returned block parameters are not checked at all (except width and
> height). It is supposed, that each pixel is 4 bite RGBA one after the other.
>
> E.G. the following contents is supposed:
>
> offset[0]=0,offset[1]=1,offset[2]=2,offset[3]=3
> pixelSize=4
> pitch = 4*width
>
> Here are my questions:
>
> - is it a general rule, that the photos are returned in this format by
> tk_PhotoGetImage ?

I think this is not guaranteed in the specification, though I think that
in the current implementation the data gets always converted into that
format (see PhotoPutBlock:
https://github.com/tcltk/tk/blob/master/generic/tkImgPhoto.c#L2844 )

The whole code is littered with very old shite (Colormaps and Dithering
for displays with low color depth) and could probably be significantly
reduced.

Christian

Harald Oehlmann

unread,
Nov 27, 2018, 12:08:01 PM11/27/18
to
Hi Christian,

thank you for the always helpful analysis.

Thanks,
Harald
0 new messages