LowLevelGraphicsSoftwareRenderer::drawHorizontal


#1

I need to draw a horizontal line all the way across an Image. So I’m doing this:

w = (float) img->getWidth();
g.drawLine(0.0,y,w-1,y);

The line ends one pixel before the right edge of the Image.

Looking at LowLevelGraphicsSoftwareRenderer::drawHorizontal,
I suspect that the loop that does the drawing:

while (wholeEnd > wholeStart) { ((PixelARGB*)dest)->set (colour); dest += dstPixelStride; ++wholeStart }

should be changed so that the loop condition is:

I though that perhaps I was meant to do g.drawLine(0.0,y,w,y). However, if I do this, then the call to image.lockPixelDataReadWrite in drawHorizontal uses a width that is one pixel too large.

Matt


#2

you do want to use w, not w - 1. Best not to worry about how the graphics code goes about doing its stuff!


#3

I’d be happy to use w instead of w-1 - that’s how I had it originally. It worked fine prior to JUCE 1.24.

The problem is that if I do use w, then I hit an jassert in the call to image.lockPixelDataReadWrite at the beginning of LowLevelGraphicsSoftwareRenderer::drawHorizontal.

lockPixelDataReadWrite is being passed a width of wholeEnd + 1 - wholeStart. So, for instance, if your image is 100 pixels wide and you passed in an x of 0 and a w of 100, the width passed to lockPixelDataReadWrite comes out as 101. This trips the jassert at the top of lockPixelDataReadWrite, which asserts that w <= imageWidth.

So I don’t think you can get there from here. Either the parameter to the lock call needs to change or the loop condition that draws the line needs to change. As the code stands, I really don’t see how you can draw a horizontal line that goes all the way across an image.


#4

Oh, I see. Ok, I’ll look at the assert, but in the meantime it won’t do you any harm to leave it in.


#5

It’s not a big deal; I’ve already worked around it. Just thought you’d like to know.

The new LnF is a big improvement, by the way.


#6