Browse Source

Replaced the Image::getTag() method with a more versatile getProperties() method. Used this to set a flag called "originalImageHadAlpha" when loading images, which is set to indicate whether the original file had an alpha channel.

tags/2021-05-28
Julian Storer 15 years ago
parent
commit
e299011789
9 changed files with 52 additions and 53 deletions
  1. +24
    -12
      juce_amalgamated.cpp
  2. +6
    -15
      juce_amalgamated.h
  3. +1
    -1
      src/core/juce_StandardHeader.h
  4. +2
    -0
      src/gui/graphics/imaging/image_file_formats/juce_GIFLoader.cpp
  5. +1
    -0
      src/gui/graphics/imaging/image_file_formats/juce_JPEGLoader.cpp
  6. +1
    -0
      src/gui/graphics/imaging/image_file_formats/juce_PNGLoader.cpp
  7. +2
    -8
      src/gui/graphics/imaging/juce_Image.cpp
  8. +6
    -15
      src/gui/graphics/imaging/juce_Image.h
  9. +9
    -2
      src/native/mac/juce_mac_CoreGraphicsContext.mm

+ 24
- 12
juce_amalgamated.cpp View File

@@ -95575,15 +95575,9 @@ const Image Image::convertedToFormat (PixelFormat newFormat) const
return newImage;
}

const var Image::getTag() const
NamedValueSet* Image::getProperties() const
{
return image == 0 ? var::null : image->userTag;
}

void Image::setTag (const var& newTag)
{
if (image != 0)
image->userTag = newTag;
return image == 0 ? 0 : &(image->userData);
}

Image::BitmapData::BitmapData (Image& image, const int x, const int y, const int w, const int h, const bool /*makeWritable*/)
@@ -96480,6 +96474,8 @@ public:
image = Image ((transparent >= 0) ? Image::ARGB : Image::RGB,
imageWidth, imageHeight, (transparent >= 0));

image.getProperties()->set ("originalImageHadAlpha", image.hasAlphaChannel());

readImage ((buf[8] & 0x40) != 0, transparent);

break;
@@ -211967,6 +211963,7 @@ const Image JPEGImageFormat::decodeImage (InputStream& in)
if (jpeg_start_decompress (&jpegDecompStruct))
{
image = Image (Image::RGB, width, height, false);
image.getProperties()->set ("originalImageHadAlpha", false);
const bool hasAlphaChan = image.hasAlphaChannel(); // (the native image creator may not give back what we expect)

const Image::BitmapData destData (image, true);
@@ -237674,6 +237671,7 @@ const Image PNGImageFormat::decodeImage (InputStream& in)
image = Image (hasAlphaChan ? Image::ARGB : Image::RGB,
(int) width, (int) height, hasAlphaChan);

image.getProperties()->set ("originalImageHadAlpha", image.hasAlphaChannel());
hasAlphaChan = image.hasAlphaChannel(); // (the native image creator may not give back what we expect)

const Image::BitmapData destData (image, true);
@@ -267560,8 +267558,12 @@ const Image juce_loadWithCoreImage (InputStream& input)

if (loadedImage != 0)
{
const bool hasAlphaChan = CGImageGetAlphaInfo (loadedImage) != kCGImageAlphaNone;
Image image (hasAlphaChan ? Image::ARGB : Image::RGB,
CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo (loadedImage);
const bool hasAlphaChan = (alphaInfo != kCGImageAlphaNone
&& alphaInfo != kCGImageAlphaNoneSkipLast
&& alphaInfo != kCGImageAlphaNoneSkipFirst);

Image image (Image::ARGB, // (CoreImage doesn't work with 24-bit images)
(int) CGImageGetWidth (loadedImage), (int) CGImageGetHeight (loadedImage),
hasAlphaChan, Image::NativeImage);

@@ -267575,6 +267577,9 @@ const Image juce_loadWithCoreImage (InputStream& input)
CFRelease (loadedImage);
#endif

// Because it's impossible to create a truly 24-bit CG image, this flag allows a user
// to find out whether the file they just loaded the image from had an alpha channel or not.
image.getProperties()->set ("originalImageHadAlpha", hasAlphaChan);
return image;
}
}
@@ -272254,8 +272259,12 @@ const Image juce_loadWithCoreImage (InputStream& input)

if (loadedImage != 0)
{
const bool hasAlphaChan = CGImageGetAlphaInfo (loadedImage) != kCGImageAlphaNone;
Image image (hasAlphaChan ? Image::ARGB : Image::RGB,
CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo (loadedImage);
const bool hasAlphaChan = (alphaInfo != kCGImageAlphaNone
&& alphaInfo != kCGImageAlphaNoneSkipLast
&& alphaInfo != kCGImageAlphaNoneSkipFirst);

Image image (Image::ARGB, // (CoreImage doesn't work with 24-bit images)
(int) CGImageGetWidth (loadedImage), (int) CGImageGetHeight (loadedImage),
hasAlphaChan, Image::NativeImage);

@@ -272269,6 +272278,9 @@ const Image juce_loadWithCoreImage (InputStream& input)
CFRelease (loadedImage);
#endif

// Because it's impossible to create a truly 24-bit CG image, this flag allows a user
// to find out whether the file they just loaded the image from had an alpha channel or not.
image.getProperties()->set ("originalImageHadAlpha", hasAlphaChan);
return image;
}
}


+ 6
- 15
juce_amalgamated.h View File

@@ -64,7 +64,7 @@
*/
#define JUCE_MAJOR_VERSION 1
#define JUCE_MINOR_VERSION 52
#define JUCE_BUILDNUMBER 79
#define JUCE_BUILDNUMBER 80

/** Current Juce version number.

@@ -25352,21 +25352,12 @@ public:
void createSolidAreaMask (RectangleList& result,
float alphaThreshold = 0.5f) const;

/** Returns a user-specified data item that was set with setTag().
setTag() and getTag() allow you to attach an arbitrary identifier value to an
image. The value is shared between all Image object that are referring to the
same underlying image data object.
*/
const var getTag() const;

/** Attaches a user-specified data item to this image, which can be retrieved using getTag().
setTag() and getTag() allow you to attach an arbitrary identifier value to an
image. The value is shared between all Image object that are referring to the
same underlying image data object.
/** Returns a NamedValueSet that is attached to the image and which can be used for
associating custom values with it.

Note that if this Image is null, this method will fail to store the data.
If this is a null image, this will return a null pointer.
*/
void setTag (const var& newTag);
NamedValueSet* getProperties() const;

/** Creates a context suitable for drawing onto this image.
Don't call this method directly! It's used internally by the Graphics class.
@@ -25411,7 +25402,7 @@ public:
const int width, height;
int pixelStride, lineStride;
uint8* imageData;
var userTag;
NamedValueSet userData;

SharedImage (const SharedImage&);
SharedImage& operator= (const SharedImage&);


+ 1
- 1
src/core/juce_StandardHeader.h View File

@@ -33,7 +33,7 @@
*/
#define JUCE_MAJOR_VERSION 1
#define JUCE_MINOR_VERSION 52
#define JUCE_BUILDNUMBER 79
#define JUCE_BUILDNUMBER 80
/** Current Juce version number.


+ 2
- 0
src/gui/graphics/imaging/image_file_formats/juce_GIFLoader.cpp View File

@@ -104,6 +104,8 @@ public:
image = Image ((transparent >= 0) ? Image::ARGB : Image::RGB,
imageWidth, imageHeight, (transparent >= 0));
image.getProperties()->set ("originalImageHadAlpha", image.hasAlphaChannel());
readImage ((buf[8] & 0x40) != 0, transparent);
break;


+ 1
- 0
src/gui/graphics/imaging/image_file_formats/juce_JPEGLoader.cpp View File

@@ -304,6 +304,7 @@ const Image JPEGImageFormat::decodeImage (InputStream& in)
if (jpeg_start_decompress (&jpegDecompStruct))
{
image = Image (Image::RGB, width, height, false);
image.getProperties()->set ("originalImageHadAlpha", false);
const bool hasAlphaChan = image.hasAlphaChannel(); // (the native image creator may not give back what we expect)
const Image::BitmapData destData (image, true);


+ 1
- 0
src/gui/graphics/imaging/image_file_formats/juce_PNGLoader.cpp View File

@@ -228,6 +228,7 @@ const Image PNGImageFormat::decodeImage (InputStream& in)
image = Image (hasAlphaChan ? Image::ARGB : Image::RGB,
(int) width, (int) height, hasAlphaChan);
image.getProperties()->set ("originalImageHadAlpha", image.hasAlphaChannel());
hasAlphaChan = image.hasAlphaChannel(); // (the native image creator may not give back what we expect)
const Image::BitmapData destData (image, true);


+ 2
- 8
src/gui/graphics/imaging/juce_Image.cpp View File

@@ -252,15 +252,9 @@ const Image Image::convertedToFormat (PixelFormat newFormat) const
return newImage;
}
const var Image::getTag() const
NamedValueSet* Image::getProperties() const
{
return image == 0 ? var::null : image->userTag;
}
void Image::setTag (const var& newTag)
{
if (image != 0)
image->userTag = newTag;
return image == 0 ? 0 : &(image->userData);
}
//==============================================================================


+ 6
- 15
src/gui/graphics/imaging/juce_Image.h View File

@@ -29,7 +29,7 @@
#include "../colour/juce_Colour.h"
#include "../contexts/juce_Graphics.h"
#include "../../../containers/juce_Variant.h"
#include "../../../containers/juce_NamedValueSet.h"
//==============================================================================
/**
@@ -354,21 +354,12 @@ public:
float alphaThreshold = 0.5f) const;
//==============================================================================
/** Returns a user-specified data item that was set with setTag().
setTag() and getTag() allow you to attach an arbitrary identifier value to an
image. The value is shared between all Image object that are referring to the
same underlying image data object.
*/
const var getTag() const;
/** Attaches a user-specified data item to this image, which can be retrieved using getTag().
setTag() and getTag() allow you to attach an arbitrary identifier value to an
image. The value is shared between all Image object that are referring to the
same underlying image data object.
/** Returns a NamedValueSet that is attached to the image and which can be used for
associating custom values with it.
Note that if this Image is null, this method will fail to store the data.
If this is a null image, this will return a null pointer.
*/
void setTag (const var& newTag);
NamedValueSet* getProperties() const;
//==============================================================================
/** Creates a context suitable for drawing onto this image.
@@ -415,7 +406,7 @@ public:
const int width, height;
int pixelStride, lineStride;
uint8* imageData;
var userTag;
NamedValueSet userData;
SharedImage (const SharedImage&);
SharedImage& operator= (const SharedImage&);


+ 9
- 2
src/native/mac/juce_mac_CoreGraphicsContext.mm View File

@@ -800,8 +800,12 @@ const Image juce_loadWithCoreImage (InputStream& input)
if (loadedImage != 0)
{
const bool hasAlphaChan = CGImageGetAlphaInfo (loadedImage) != kCGImageAlphaNone;
Image image (hasAlphaChan ? Image::ARGB : Image::RGB,
CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo (loadedImage);
const bool hasAlphaChan = (alphaInfo != kCGImageAlphaNone
&& alphaInfo != kCGImageAlphaNoneSkipLast
&& alphaInfo != kCGImageAlphaNoneSkipFirst);
Image image (Image::ARGB, // (CoreImage doesn't work with 24-bit images)
(int) CGImageGetWidth (loadedImage), (int) CGImageGetHeight (loadedImage),
hasAlphaChan, Image::NativeImage);
@@ -815,6 +819,9 @@ const Image juce_loadWithCoreImage (InputStream& input)
CFRelease (loadedImage);
#endif
// Because it's impossible to create a truly 24-bit CG image, this flag allows a user
// to find out whether the file they just loaded the image from had an alpha channel or not.
image.getProperties()->set ("originalImageHadAlpha", hasAlphaChan);
return image;
}
}


Loading…
Cancel
Save