Subclassing Image to use given data


#1

I’m synching my source base with the past few month’s worth of JUCE changes, including the refactored Image class. Overall I appreciate the changes to a reference-counted object. It’s making for less and better code in my app.

Unfortunately a use I am relying on has gone away and as far as I can tell is no longer possible to do with the new Image class, whether cleanly or not. I have (or had) a subclass of Image that created an Image as a wrapper around an existing bitmap. Like this:

MLSignalImage::MLSignalImage(MLSignal* sig) : Image(Image::SingleChannel, sig->getWidth(), sig->getHeight()) { pixelStride = 1; lineStride = 1 << sig->getWidthBits(); imageData = (unsigned char*)sig->getBuffer(); }

Possibly this use is what you had planned for “const bool /makeWritable/” in Image::BitmapData::BitmapData()? That could work if it creates references to SharedImage::pixelStride etc. But I would prefer to acknowledge that some people might want to do what I’m doing, and provide a constructor or createWithBitmapData() method.

BTW, the rest of my update is going smoothly.


#2

The new design is actually designed to make it easier to create custom image classes that behave identically to the normal ones. The only difference is that instead of subclassing Image itself, you subclass the internal object that it uses, which is the Image::SharedImage class. That class is fairly undocumented but very minimal, and if you search for SoftwareSharedImage, you’ll see an example.


#3

OK, thanks, I get it now. I got fooled into thinking this wasn’t possible because I don’t tend to write public member classes. It does seem like an appropriate design here.