Browse Source

Improved drop-shadow code.

tags/2021-05-28
jules 13 years ago
parent
commit
225040e62b
2 changed files with 40 additions and 58 deletions
  1. +16
    -5
      extras/Introjucer/Source/Application/jucer_FilePreviewComponent.h
  2. +24
    -53
      modules/juce_graphics/effects/juce_DropShadowEffect.cpp

+ 16
- 5
extras/Introjucer/Source/Application/jucer_FilePreviewComponent.h View File

@@ -36,19 +36,30 @@ public:
ItemPreviewComponent (const File& file_)
: file (file_)
{
setOpaque (true);
tryToLoadImage();
}
void paint (Graphics& g)
{
g.drawImageWithin (image, 2, 22, getWidth() - 4, getHeight() - 24,
RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
false);
drawTexturedBackground (g);
Rectangle<int> area = RectanglePlacement (RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize)
.appliedTo (image.getBounds(), Rectangle<int> (4, 22, getWidth() - 8, getHeight() - 26));
Path p;
p.addRectangle (area);
DropShadow (Colours::black.withAlpha (0.5f), 6, Point<int> (0, 1)).drawForPath (g, p);
g.fillCheckerBoard (area, 24, 24, Colour (0xffffffff), Colour (0xffeeeeee));
g.setOpacity (1.0f);
g.drawImageWithin (image, area.getX(), area.getY(), area.getWidth(), area.getHeight(),
RectanglePlacement::stretchToFit, false);
g.setFont (Font (14.0f, Font::bold));
g.setColour (findColour (mainBackgroundColourId).contrasting());
g.drawMultiLineText (facts.joinIntoString ("\n"),
10, 15, getWidth() - 16);
g.drawMultiLineText (facts.joinIntoString ("\n"), 10, 15, getWidth() - 16);
}
private:


+ 24
- 53
modules/juce_graphics/effects/juce_DropShadowEffect.cpp View File

@@ -23,63 +23,38 @@
==============================================================================
*/
#if JUCE_MSVC && JUCE_DEBUG
#pragma optimize ("t", on)
#endif
static void blurSingleChannelImage (uint8* const data, const int width, const int height,
const int lineStride, const int repetitions) noexcept
static inline void blurDataTriplets (uint8* d, int num, const int delta) noexcept
{
uint8* line = data;
for (int y = height; --y >= 0;)
{
for (int i = repetitions; --i >= 0;)
{
uint8* p = line;
*p++ = (((int) p[0]) + p[1]) / 2;
uint32 last = d[0];
d[0] = (uint8) ((d[0] + d[delta] + 1) / 3);
d += delta;
for (int x = width - 2; --x >= 0;)
*p++ = (((int) p[-1]) + p[0] + p[1] + 1) / 3;
num -= 2;
*p = (((int) p[0]) + p[-1]) / 2;
}
line += lineStride;
}
for (int i = repetitions; --i >= 0;)
do
{
line = data;
{
uint8* p1 = line;
uint8* p2 = line + lineStride;
for (int x = width; --x >= 0;)
*p1++ = (((int) *p1) + *p2++) / 2;
}
line += lineStride;
for (int y = height - 2; --y >= 0;)
{
uint8* p1 = line;
uint8* p2 = line - lineStride;
uint8* p3 = line + lineStride;
const uint32 newLast = d[0];
d[0] = (uint8) ((last + d[0] + d[delta] + 1) / 3);
d += delta;
last = newLast;
}
while (--num > 0);
for (int x = width; --x >= 0;)
*p1++ = (((int) *p1) + *p2++ + *p3++ + 1) / 3;
d[0] = (uint8) ((last + d[0] + 1) / 3);
}
line += lineStride;
}
static void blurSingleChannelImage (uint8* const data, const int width, const int height,
const int lineStride, const int repetitions) noexcept
{
jassert (width > 2 && height > 2);
uint8* p1 = line;
uint8* p2 = line - lineStride;
for (int y = 0; y < height; ++y)
for (int i = repetitions; --i >= 0;)
blurDataTriplets (data + lineStride * y, width, 1);
for (int x = width; --x >= 0;)
*p1++ = (((int) *p1) + *p2++) / 2;
}
for (int x = 0; x < width; ++x)
for (int i = repetitions; --i >= 0;)
blurDataTriplets (data + x, height, lineStride);
}
static void blurSingleChannelImage (Image& image, int radius)
@@ -88,10 +63,6 @@ static void blurSingleChannelImage (Image& image, int radius)
blurSingleChannelImage (bm.data, bm.width, bm.height, bm.lineStride, 2 * radius);
}
#if JUCE_MSVC && JUCE_DEBUG
#pragma optimize ("", on) // resets optimisations to the project defaults
#endif
//==============================================================================
DropShadow::DropShadow() noexcept
: colour (0x90000000), radius (4)


Loading…
Cancel
Save