template <class DST, class SRC>
inline void qt_memconvert(DST *dest, const SRC *src, int count)
{
- if (sizeof(DST) == 1) {
- while (count) {
- int n = 1;
- const SRC color = *src++;
- const DST dstColor = qt_colorConvert<DST, SRC>(color, 0);
- while (--count && (*src == color || dstColor == qt_colorConvert<DST, SRC>(*src, 0))) {
- ++n;
- ++src;
- }
- qt_memfill(dest, dstColor, n);
- dest += n;
- }
- } else {
- /* Duff's device */
- int n = (count + 7) / 8;
- switch (count & 0x07)
- {
- case 0: do { *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
- case 7: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
- case 6: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
- case 5: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
- case 4: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
- case 3: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
- case 2: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
- case 1: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
- } while (--n > 0);
- }
+ // quint32 to quint16 and vise-versa
+ Q_ASSERT(sizeof(DST) != sizeof(SRC))
+ Q_ASSERT(sizeof(DST) == sizeof(quint16) || sizeof(DST) == sizeof(quint32))
+ Q_ASSERT(sizeof(SRC) == sizeof(quint16) || sizeof(SRC) == sizeof(quint32))
+ /* Duff's device */
+ int n = (count + 7) / 8;
+ switch (count & 0x07)
+ {
+ case 0: do { *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
+ case 7: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
+ case 6: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
+ case 5: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
+ case 4: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
+ case 3: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
+ case 2: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
+ case 1: *dest++ = qt_colorConvert<DST, SRC>(*src++, 0);
+ } while (--n > 0);
}
}
-#define QT_TRIVIAL_MEMCONVERT_IMPL(T) \
- template <> \
- inline void qt_memconvert(T *dest, const T *src, int count) \
- { \
- ::memcpy(dest, src, count * sizeof(T)); \
- }
-QT_TRIVIAL_MEMCONVERT_IMPL(quint32)
-QT_TRIVIAL_MEMCONVERT_IMPL(quint16)
-#undef QT_TRIVIAL_MEMCONVERT_IMPL
-
template <class DST, class SRC>
inline void qt_rectconvert(DST *dest, const SRC *src,
int width, int height,
int dstStride, int srcStride)
{
+ // quint32 to quint16 and vise-versa
+ Q_ASSERT(sizeof(DST) != sizeof(SRC))
+ Q_ASSERT(sizeof(DST) == sizeof(quint16) || sizeof(DST) == sizeof(quint32))
+ Q_ASSERT(sizeof(SRC) == sizeof(quint16) || sizeof(SRC) == sizeof(quint32))
char *d = (char*)dest;
const char *s = (const char*)(src);
for (int i = 0; i < height; ++i) {
}
}
-#define QT_RECTCONVERT_TRIVIAL_IMPL(T) \
- template <> \
- inline void qt_rectconvert(T *dest, const T *src, \
- int width, int height, \
- int dstStride, int srcStride) \
- { \
- char *d = (char*)dest; \
- const char *s = (const char*)(src); \
- for (int i = 0; i < height; ++i) { \
- ::memcpy(d, s, width * sizeof(T)); \
- d += dstStride; \
- s += srcStride; \
- } \
- }
-
-QT_RECTCONVERT_TRIVIAL_IMPL(quint32)
-QT_RECTCONVERT_TRIVIAL_IMPL(quint16)
-#undef QT_RECTCONVERT_TRIVIAL_IMPL
-
static inline int qt_div_255(int x) { return (x + (x>>8) + 0x80) >> 8; }
static const uint qt_bayer_matrix[16][16] = {