diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp index ab19aefa41..ce1567953c 100644 --- a/src/gui/painting/qdrawhelper.cpp +++ b/src/gui/painting/qdrawhelper.cpp @@ -250,6 +250,117 @@ static const uint *QT_FASTCALL convertFromARGB32PM(uint *buffer, const uint *src return buffer; } +template static +uint QT_FASTCALL fetchPixel(const uchar *src, int index); + +template <> +inline uint QT_FASTCALL fetchPixel(const uchar *src, int index) +{ + return (src[index >> 3] >> (index & 7)) & 1; +} + +template <> +inline uint QT_FASTCALL fetchPixel(const uchar *src, int index) +{ + return (src[index >> 3] >> (~index & 7)) & 1; +} + +template <> +inline uint QT_FASTCALL fetchPixel(const uchar *src, int index) +{ + return src[index]; +} + +template <> +inline uint QT_FASTCALL fetchPixel(const uchar *src, int index) +{ + return reinterpret_cast(src)[index]; +} + +template <> +inline uint QT_FASTCALL fetchPixel(const uchar *src, int index) +{ + return reinterpret_cast(src)[index]; +} + +template <> +inline uint QT_FASTCALL fetchPixel(const uchar *src, int index) +{ + return reinterpret_cast(src)[index]; +} + +template +inline const uint *QT_FASTCALL fetchPixels(uint *buffer, const uchar *src, int index, int count) +{ + for (int i = 0; i < count; ++i) + buffer[i] = fetchPixel(src, index + i); + return buffer; +} + +template <> +inline const uint *QT_FASTCALL fetchPixels(uint *, const uchar *src, int index, int) +{ + return reinterpret_cast(src) + index; +} + +template static +void QT_FASTCALL storePixel(uchar *dest, int index, uint pixel); + +template <> +inline void QT_FASTCALL storePixel(uchar *dest, int index, uint pixel) +{ + if (pixel) + dest[index >> 3] |= 1 << (index & 7); + else + dest[index >> 3] &= ~(1 << (index & 7)); +} + +template <> +inline void QT_FASTCALL storePixel(uchar *dest, int index, uint pixel) +{ + if (pixel) + dest[index >> 3] |= 1 << (~index & 7); + else + dest[index >> 3] &= ~(1 << (~index & 7)); +} + +template <> +inline void QT_FASTCALL storePixel(uchar *dest, int index, uint pixel) +{ + dest[index] = uchar(pixel); +} + +template <> +inline void QT_FASTCALL storePixel(uchar *dest, int index, uint pixel) +{ + reinterpret_cast(dest)[index] = quint16(pixel); +} + +template <> +inline void QT_FASTCALL storePixel(uchar *dest, int index, uint pixel) +{ + reinterpret_cast(dest)[index] = quint24(pixel); +} + +template <> +inline void QT_FASTCALL storePixel(uchar *dest, int index, uint pixel) +{ + reinterpret_cast(dest)[index] = pixel; +} + +template +inline void QT_FASTCALL storePixels(uchar *dest, const uint *src, int index, int count) +{ + for (int i = 0; i < count; ++i) + storePixel(dest, index + i, src[i]); +} + +template <> +inline void QT_FASTCALL storePixels(uchar *dest, const uint *src, int index, int count) +{ + memcpy(reinterpret_cast(dest) + index, src, count * sizeof(uint)); +} + // Note: // convertToArgb32() assumes that no color channel is less than 4 bits. // convertFromArgb32() assumes that no color channel is more than 8 bits. diff --git a/src/gui/painting/qdrawhelper_p.h b/src/gui/painting/qdrawhelper_p.h index 4266609c7b..3ff75a32cc 100644 --- a/src/gui/painting/qdrawhelper_p.h +++ b/src/gui/painting/qdrawhelper_p.h @@ -996,120 +996,7 @@ struct QPixelLayout ConvertFunc convertFromARGB32PM; }; -template -uint QT_FASTCALL fetchPixel(const uchar *src, int index); - -template <> -inline uint QT_FASTCALL fetchPixel(const uchar *src, int index) -{ - return (src[index >> 3] >> (index & 7)) & 1; -} - -template <> -inline uint QT_FASTCALL fetchPixel(const uchar *src, int index) -{ - return (src[index >> 3] >> (~index & 7)) & 1; -} - -template <> -inline uint QT_FASTCALL fetchPixel(const uchar *src, int index) -{ - return src[index]; -} - -template <> -inline uint QT_FASTCALL fetchPixel(const uchar *src, int index) -{ - return reinterpret_cast(src)[index]; -} - -template <> -inline uint QT_FASTCALL fetchPixel(const uchar *src, int index) -{ - return reinterpret_cast(src)[index]; -} - -template <> -inline uint QT_FASTCALL fetchPixel(const uchar *src, int index) -{ - return reinterpret_cast(src)[index]; -} - -template -inline const uint *QT_FASTCALL fetchPixels(uint *buffer, const uchar *src, int index, int count) -{ - for (int i = 0; i < count; ++i) - buffer[i] = fetchPixel(src, index + i); - return buffer; -} - -template <> -inline const uint *QT_FASTCALL fetchPixels(uint *, const uchar *src, int index, int) -{ - return reinterpret_cast(src) + index; -} - typedef const uint *(QT_FASTCALL *FetchPixelsFunc)(uint *buffer, const uchar *src, int index, int count); - - -template -void QT_FASTCALL storePixel(uchar *dest, int index, uint pixel); - -template <> -inline void QT_FASTCALL storePixel(uchar *dest, int index, uint pixel) -{ - if (pixel) - dest[index >> 3] |= 1 << (index & 7); - else - dest[index >> 3] &= ~(1 << (index & 7)); -} - -template <> -inline void QT_FASTCALL storePixel(uchar *dest, int index, uint pixel) -{ - if (pixel) - dest[index >> 3] |= 1 << (~index & 7); - else - dest[index >> 3] &= ~(1 << (~index & 7)); -} - -template <> -inline void QT_FASTCALL storePixel(uchar *dest, int index, uint pixel) -{ - dest[index] = uchar(pixel); -} - -template <> -inline void QT_FASTCALL storePixel(uchar *dest, int index, uint pixel) -{ - reinterpret_cast(dest)[index] = quint16(pixel); -} - -template <> -inline void QT_FASTCALL storePixel(uchar *dest, int index, uint pixel) -{ - reinterpret_cast(dest)[index] = quint24(pixel); -} - -template <> -inline void QT_FASTCALL storePixel(uchar *dest, int index, uint pixel) -{ - reinterpret_cast(dest)[index] = pixel; -} - -template -inline void QT_FASTCALL storePixels(uchar *dest, const uint *src, int index, int count) -{ - for (int i = 0; i < count; ++i) - storePixel(dest, index + i, src[i]); -} - -template <> -inline void QT_FASTCALL storePixels(uchar *dest, const uint *src, int index, int count) -{ - memcpy(reinterpret_cast(dest) + index, src, count * sizeof(uint)); -} - typedef void (QT_FASTCALL *StorePixelsFunc)(uchar *dest, const uint *src, int index, int count); extern QPixelLayout qPixelLayouts[QImage::NImageFormats];