bitbank2/JPEGDEC

callbacks require global variables.

Closed this issue · 5 comments

I have my display code encapsulated and the drawing callback lacks the ability to pass context to the callback. It would be nice if a context pointer could be passed in.

I just added it; please give it a try. Set your context pointer by calling setContext(void *). In the draw callback, it is part of the JPEGDRAW structure (pDraw->pContext). If all works as you expect, I'll do an official release.

It works like a charm! I am wondering though if it should be called fHandle since that is more or less what the context is in the case of jpeg_file_tag. Granted the open callback could suffer the same issue as draw just because you might have an instance that provides the "bootstrap" information for the jpeg_file_tag that is returned by open. The other alternative is to have the context from setContext passed in as a final argument for each callback function. This might not be a viable option though as it would break the published API. Thoughts?

It's hard for me to say one way or another; I'm the worst "customer" for my libraries. Maybe I can change the name to "setDrawContext" to make it more evident that it relates to the DRAW callback. I can ask on Twitter; there will certainly be plenty of opinions shared there...

Actually, in pngdecode you call it pUser. That seems like a good name.

ok, I'll change it