mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1213613 (part 2) - Move some BMP-related structs. r=seth.
This patch moves them into less exposed places. It also moves the RLE_* constants into the RLE enum, and renames ColorTable and its fields.
This commit is contained in:
parent
d89f3d4776
commit
7b48f0bb0c
@ -77,46 +77,6 @@ struct V5InfoHeader {
|
||||
static const uint32_t COLOR_SPACE_LCS_SRGB = 0x73524742;
|
||||
};
|
||||
|
||||
struct ColorTable {
|
||||
uint8_t red;
|
||||
uint8_t green;
|
||||
uint8_t blue;
|
||||
};
|
||||
|
||||
struct BitFields {
|
||||
uint32_t red;
|
||||
uint32_t green;
|
||||
uint32_t blue;
|
||||
uint8_t redLeftShift;
|
||||
uint8_t redRightShift;
|
||||
uint8_t greenLeftShift;
|
||||
uint8_t greenRightShift;
|
||||
uint8_t blueLeftShift;
|
||||
uint8_t blueRightShift;
|
||||
|
||||
// Length of the bitfields structure in the BMP file.
|
||||
static const size_t LENGTH = 12;
|
||||
};
|
||||
|
||||
struct Compression {
|
||||
enum {
|
||||
RGB = 0,
|
||||
RLE8 = 1,
|
||||
RLE4 = 2,
|
||||
BITFIELDS = 3
|
||||
};
|
||||
};
|
||||
|
||||
// RLE escape codes.
|
||||
struct RLE {
|
||||
enum {
|
||||
ESCAPE = 0,
|
||||
ESCAPE_EOL = 0,
|
||||
ESCAPE_EOF = 1,
|
||||
ESCAPE_DELTA = 2
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace bmp
|
||||
} // namespace image
|
||||
} // namespace mozilla
|
||||
|
@ -91,6 +91,31 @@ using namespace mozilla::gfx;
|
||||
|
||||
namespace mozilla {
|
||||
namespace image {
|
||||
namespace bmp {
|
||||
|
||||
struct Compression {
|
||||
enum {
|
||||
RGB = 0,
|
||||
RLE8 = 1,
|
||||
RLE4 = 2,
|
||||
BITFIELDS = 3
|
||||
};
|
||||
};
|
||||
|
||||
// RLE escape codes and constants.
|
||||
struct RLE {
|
||||
enum {
|
||||
ESCAPE = 0,
|
||||
ESCAPE_EOL = 0,
|
||||
ESCAPE_EOF = 1,
|
||||
ESCAPE_DELTA = 2,
|
||||
|
||||
SEGMENT_LENGTH = 2,
|
||||
DELTA_LENGTH = 2
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace bmp
|
||||
|
||||
using namespace bmp;
|
||||
|
||||
@ -104,10 +129,6 @@ GetBMPLog()
|
||||
return sBMPLog;
|
||||
}
|
||||
|
||||
// Constants relating to RLE compression.
|
||||
static const size_t RLE_SEGMENT_LENGTH = 2;
|
||||
static const size_t RLE_DELTA_LENGTH = 2;
|
||||
|
||||
nsBMPDecoder::nsBMPDecoder(RasterImage* aImage)
|
||||
: Decoder(aImage)
|
||||
, mLexer(Transition::To(State::FILE_HEADER, FileHeader::LENGTH))
|
||||
@ -471,8 +492,8 @@ nsBMPDecoder::ReadInfoHeaderRest(const char* aData, size_t aLength)
|
||||
|
||||
// Always allocate and zero 256 entries, even though mNumColors might be
|
||||
// smaller, because the file might erroneously index past mNumColors.
|
||||
mColors = new ColorTable[256];
|
||||
memset(mColors, 0, 256 * sizeof(ColorTable));
|
||||
mColors = new ColorTableEntry[256];
|
||||
memset(mColors, 0, 256 * sizeof(ColorTableEntry));
|
||||
|
||||
// OS/2 Bitmaps have no padding byte.
|
||||
mBytesPerColor = (mBIH.bihsize == InfoHeaderLength::WIN_V2) ? 3 : 4;
|
||||
@ -554,9 +575,9 @@ nsBMPDecoder::ReadColorTable(const char* aData, size_t aLength)
|
||||
|
||||
for (uint32_t i = 0; i < mNumColors; i++) {
|
||||
// The format is BGR or BGR0.
|
||||
mColors[i].blue = uint8_t(aData[0]);
|
||||
mColors[i].green = uint8_t(aData[1]);
|
||||
mColors[i].red = uint8_t(aData[2]);
|
||||
mColors[i].mBlue = uint8_t(aData[0]);
|
||||
mColors[i].mGreen = uint8_t(aData[1]);
|
||||
mColors[i].mRed = uint8_t(aData[2]);
|
||||
aData += mBytesPerColor;
|
||||
}
|
||||
|
||||
@ -581,7 +602,7 @@ nsBMPDecoder::SkipGap()
|
||||
bool hasRLE = mBIH.compression == Compression::RLE8 ||
|
||||
mBIH.compression == Compression::RLE4;
|
||||
return hasRLE
|
||||
? Transition::To(State::RLE_SEGMENT, RLE_SEGMENT_LENGTH)
|
||||
? Transition::To(State::RLE_SEGMENT, RLE::SEGMENT_LENGTH)
|
||||
: Transition::To(State::PIXEL_ROW, mPixelRowSize);
|
||||
}
|
||||
|
||||
@ -706,7 +727,7 @@ nsBMPDecoder::ReadRLESegment(const char* aData)
|
||||
} while (pixelsNeeded);
|
||||
}
|
||||
}
|
||||
return Transition::To(State::RLE_SEGMENT, RLE_SEGMENT_LENGTH);
|
||||
return Transition::To(State::RLE_SEGMENT, RLE::SEGMENT_LENGTH);
|
||||
}
|
||||
|
||||
if (byte2 == RLE::ESCAPE_EOL) {
|
||||
@ -714,7 +735,7 @@ nsBMPDecoder::ReadRLESegment(const char* aData)
|
||||
FinishRow();
|
||||
return mCurrentRow == 0
|
||||
? Transition::Terminate(State::SUCCESS)
|
||||
: Transition::To(State::RLE_SEGMENT, RLE_SEGMENT_LENGTH);
|
||||
: Transition::To(State::RLE_SEGMENT, RLE::SEGMENT_LENGTH);
|
||||
}
|
||||
|
||||
if (byte2 == RLE::ESCAPE_EOF) {
|
||||
@ -722,7 +743,7 @@ nsBMPDecoder::ReadRLESegment(const char* aData)
|
||||
}
|
||||
|
||||
if (byte2 == RLE::ESCAPE_DELTA) {
|
||||
return Transition::To(State::RLE_DELTA, RLE_DELTA_LENGTH);
|
||||
return Transition::To(State::RLE_DELTA, RLE::DELTA_LENGTH);
|
||||
}
|
||||
|
||||
// Absolute mode. |byte2| gives the number of pixels. The length depends on
|
||||
@ -780,7 +801,7 @@ nsBMPDecoder::ReadRLEDelta(const char* aData)
|
||||
|
||||
return mCurrentRow == 0
|
||||
? Transition::Terminate(State::SUCCESS)
|
||||
: Transition::To(State::RLE_SEGMENT, RLE_SEGMENT_LENGTH);
|
||||
: Transition::To(State::RLE_SEGMENT, RLE::SEGMENT_LENGTH);
|
||||
}
|
||||
|
||||
LexerTransition<nsBMPDecoder::State>
|
||||
@ -817,7 +838,7 @@ nsBMPDecoder::ReadRLEAbsolute(const char* aData, size_t aLength)
|
||||
// We should read all the data (unless the last byte is zero padding).
|
||||
MOZ_ASSERT(iSrc == aLength - 1 || iSrc == aLength);
|
||||
|
||||
return Transition::To(State::RLE_SEGMENT, RLE_SEGMENT_LENGTH);
|
||||
return Transition::To(State::RLE_SEGMENT, RLE::SEGMENT_LENGTH);
|
||||
}
|
||||
|
||||
} // namespace image
|
||||
|
@ -16,6 +16,32 @@
|
||||
namespace mozilla {
|
||||
namespace image {
|
||||
|
||||
namespace bmp {
|
||||
|
||||
/// An entry in the color table.
|
||||
struct ColorTableEntry {
|
||||
uint8_t mRed;
|
||||
uint8_t mGreen;
|
||||
uint8_t mBlue;
|
||||
};
|
||||
|
||||
struct BitFields {
|
||||
uint32_t red;
|
||||
uint32_t green;
|
||||
uint32_t blue;
|
||||
uint8_t redLeftShift;
|
||||
uint8_t redRightShift;
|
||||
uint8_t greenLeftShift;
|
||||
uint8_t greenRightShift;
|
||||
uint8_t blueLeftShift;
|
||||
uint8_t blueRightShift;
|
||||
|
||||
// Length of the bitfields structure in the BMP file.
|
||||
static const size_t LENGTH = 12;
|
||||
};
|
||||
|
||||
} // namespace bmp
|
||||
|
||||
class RasterImage;
|
||||
|
||||
/// Decoder for BMP-Files, as used by Windows and OS/2.
|
||||
@ -110,7 +136,7 @@ private:
|
||||
|
||||
uint32_t mNumColors; // The number of used colors, i.e. the number of
|
||||
// entries in mColors, if it's present.
|
||||
bmp::ColorTable* mColors; // The color table, if it's present.
|
||||
bmp::ColorTableEntry* mColors; // The color table, if it's present.
|
||||
uint32_t mBytesPerColor; // 3 or 4, depending on the format
|
||||
|
||||
// The number of bytes prior to the optional gap that have been read. This
|
||||
@ -151,9 +177,10 @@ SetPixel(uint32_t*& aDecoded, uint8_t aRed, uint8_t aGreen,
|
||||
}
|
||||
|
||||
static inline void
|
||||
SetPixel(uint32_t*& aDecoded, uint8_t idx, bmp::ColorTable* aColors)
|
||||
SetPixel(uint32_t*& aDecoded, uint8_t idx, bmp::ColorTableEntry* aColors)
|
||||
{
|
||||
SetPixel(aDecoded, aColors[idx].red, aColors[idx].green, aColors[idx].blue);
|
||||
SetPixel(aDecoded,
|
||||
aColors[idx].mRed, aColors[idx].mGreen, aColors[idx].mBlue);
|
||||
}
|
||||
|
||||
/// Sets two (or one if aCount = 1) pixels
|
||||
@ -163,7 +190,7 @@ SetPixel(uint32_t*& aDecoded, uint8_t idx, bmp::ColorTable* aColors)
|
||||
/// @param aCount Current count. Is decremented by one or two.
|
||||
inline void
|
||||
Set4BitPixel(uint32_t*& aDecoded, uint8_t aData, uint32_t& aCount,
|
||||
bmp::ColorTable* aColors)
|
||||
bmp::ColorTableEntry* aColors)
|
||||
{
|
||||
uint8_t idx = aData >> 4;
|
||||
SetPixel(aDecoded, idx, aColors);
|
||||
|
Loading…
Reference in New Issue
Block a user