29#if (JUCE_MAC || JUCE_IOS) && USE_COREGRAPHICS_RENDERING && JUCE_USE_COREIMAGE_LOADER
33JUCE_BEGIN_IGNORE_WARNINGS_MSVC (6385)
41 dataBlockIsZero (
false), fresh (
false), finished (
false),
42 currentBit (0), lastBit (0), lastByteIndex (0),
43 codeSize (0), setCodeSize (0), maxCode (0), maxCodeSize (0),
44 firstcode (0), oldcode (0), clearCode (0), endCode (0)
54 int numColours = 2 << (
buf[0] & 7);
57 if ((
buf[0] & 0x80) != 0)
58 readPalette (numColours);
62 if (input.read (
buf, 1) != 1 ||
buf[0] ==
';')
76 if (input.read (
buf, 9) == 9)
81 numColours = 2 << (
buf[8] & 7);
83 if ((
buf[8] & 0x80) != 0)
84 if (! readPalette (numColours))
90 image.getProperties()->set (
"originalImageHadAlpha",
transparent >= 0);
105 bool dataBlockIsZero, fresh, finished;
106 int currentBit, lastBit, lastByteIndex;
107 int codeSize, setCodeSize;
108 int maxCode, maxCodeSize;
109 int firstcode, oldcode;
110 int clearCode, endCode;
111 enum { maxGifCode = 1 << 12 };
112 int table [2] [maxGifCode];
113 int stack [2 * maxGifCode];
116 bool getSizeFromHeader (
int& w,
int& h)
121 if (input.
read (b, 6) == 6
122 && (
strncmp (
"GIF87a", b, 6) == 0
123 ||
strncmp (
"GIF89a", b, 6) == 0))
125 if (input.
read (b, 4) == 4)
129 return w > 0 && h > 0;
136 bool readPalette (
const int numCols)
138 for (
int i = 0; i <
numCols; ++i)
150 int readDataBlock (
uint8*
const dest)
153 if (input.
read (&n, 1) == 1)
155 dataBlockIsZero = (n == 0);
157 if (dataBlockIsZero || (input.
read (dest, n) == n))
167 if (input.
read (&type, 1) != 1)
175 n = readDataBlock (b);
185 n = readDataBlock (b);
195 for (i = 0; i < clearCode; ++i)
201 for (; i < maxGifCode; ++i)
211 codeSize = setCodeSize + 1;
212 clearCode = 1 << setCodeSize;
213 endCode = clearCode + 1;
214 maxCodeSize = 2 * clearCode;
215 maxCode = clearCode + 2;
232 firstcode = oldcode = getCode (codeSize,
false);
234 if (firstcode != clearCode)
244 while ((code = getCode (codeSize,
false)) >= 0)
246 if (code == clearCode)
249 codeSize = setCodeSize + 1;
250 maxCodeSize = 2 * clearCode;
251 maxCode = clearCode + 2;
253 firstcode = oldcode = getCode (codeSize,
false);
256 else if (code == endCode)
264 while ((n = readDataBlock (
buf)) > 0)
279 while (code >= clearCode)
281 *sp++ = table[1][code];
282 if (code == table[0][code])
285 code = table[0][code];
288 *sp++ = firstcode = table[1][code];
290 if ((code = maxCode) < maxGifCode)
292 table[0][code] = oldcode;
293 table[1][code] = firstcode;
296 if (maxCode >= maxCodeSize && maxCodeSize < maxGifCode)
327 buffer[0] = buffer [
jmax (0, lastByteIndex - 2)];
328 buffer[1] = buffer [
jmax (0, lastByteIndex - 1)];
330 const int n = readDataBlock (buffer + 2);
335 lastByteIndex = 2 + n;
336 currentBit = (currentBit - lastBit) + 16;
337 lastBit = (2 + n) * 8 ;
345 result |= ((buffer[i >> 3] & (1 << (i & 7))) != 0) <<
j;
356 if (input.
read (&c, 1) != 1)
368 const bool hasAlpha = image.hasAlphaChannel();
372 const int index = readLZWByte();
379 ((
PixelRGB*) p)->set (palette [index]);
383 if (++
xpos == destData.width)
391 while (
ypos >= destData.height)
398 default:
return true;
404 if (++
ypos >= destData.height)
418JUCE_END_IGNORE_WARNINGS_MSVC
423GIFImageFormat::GIFImageFormat() {}
424GIFImageFormat::~GIFImageFormat() {}
433 return (in.
read (header,
sizeof (header)) == (
int)
sizeof (header))
441 #if (JUCE_MAC || JUCE_IOS) && USE_COREGRAPHICS_RENDERING && JUCE_USE_COREIMAGE_LOADER
static constexpr uint16 littleEndianShort(const void *bytes) noexcept
Turns 2 bytes into a little-endian integer.
Represents a local file or directory.
bool hasFileExtension(StringRef extensionToTest) const
Checks whether the file has a given extension.
Retrieves a section of an image as raw pixel data, so it can be read or written to.
int pixelStride
The number of bytes between each pixel.
uint8 * getPixelPointer(int x, int y) const noexcept
Returns a pointer to a pixel in the image.
Holds a fixed-size bitmap.
@ ARGB
< each pixel is a 4-byte ARGB premultiplied colour value.
@ RGB
< each pixel is a 3-byte packed RGB colour value.
The base class for streams that write data to some kind of destination.
Represents a 32-bit INTERNAL pixel with premultiplied alpha, and can perform compositing operations w...
void setARGB(uint8 a, uint8 r, uint8 g, uint8 b) noexcept
Sets the pixel's colour from individual components.
forcedinline void premultiply() noexcept
Premultiplies the pixel's RGB values by its alpha.
Represents a 24-bit RGB pixel, and can perform compositing operations on it.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
unsigned char uint8
A platform-independent 8-bit unsigned integer type.