File indexing completed on 2022-09-27 13:43:49

0001 /********************************************************************
0002  KolorServer - color server based on the X Color Management Specification
0003  This file is part of the KDE project.
0004 
0005 Copyright (C) 2012 Casian Andrei <skeletk13@gmail.com>
0006 
0007 Redistribution and use in source and binary forms, with or without
0008 modification, are permitted provided that the following conditions
0009 are met:
0010 
0011 1. Redistributions of source code must retain the above copyright
0012    notice, this list of conditions and the following disclaimer.
0013 2. Redistributions in binary form must reproduce the above copyright
0014    notice, this list of conditions and the following disclaimer in the
0015    documentation and/or other materials provided with the distribution.
0016 
0017 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0018 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0019 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0020 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0021 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0022 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0023 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0024 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0025 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0026 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0027 *********************************************************************/
0028 
0029 #ifndef COLOR_LOOKUP_TABLE_H_
0030 #define COLOR_LOOKUP_TABLE_H_
0031 
0032 #include <QDBusMetaType>
0033 #include <QList>
0034 #include <QMultiMap>
0035 #include <QPair>
0036 #include <QRect>
0037 #include <QVector>
0038 
0039 
0040 /*
0041  * Clut
0042  */
0043 typedef QVector<quint16> Clut;
0044 typedef QList<Clut> ClutList;
0045 typedef struct { QRect r; Clut c; } RegionalClut;
0046 typedef QMultiMap<uint, RegionalClut> RegionalClutMap;
0047 
0048 Q_DECLARE_METATYPE(Clut)
0049 Q_DECLARE_METATYPE(ClutList)
0050 Q_DECLARE_METATYPE(RegionalClut)
0051 Q_DECLARE_METATYPE(RegionalClutMap)
0052 
0053 // Marshall the RegionalClut data into a D-Bus argument
0054 inline QDBusArgument &operator<<(QDBusArgument &argument, const RegionalClut &rc)
0055 {
0056     argument.beginStructure();
0057     argument << rc.r << rc.c;
0058     argument.endStructure();
0059     return argument;
0060 }
0061 
0062 // Retrieve the RegionalClut data from the D-Bus argument
0063 inline const QDBusArgument &operator>>(const QDBusArgument &argument, RegionalClut &rc)
0064 {
0065     argument.beginStructure();
0066     argument >> rc.r >> rc.c;
0067     argument.endStructure();
0068     return argument;
0069 }
0070 
0071 
0072 /*
0073  * Color lookup table
0074  *
0075  * The 3D lookup texture has 64 points in each dimension, using 16 bit integers.
0076  * That means each active region will use 1.5MiB of texture memory.
0077  */
0078 static const int LUT_GRID_POINTS = 64;
0079 static const size_t CLUT_ELEMENT_SIZE = sizeof(quint16);
0080 static const uint CLUT_ELEMENT_COUNT = LUT_GRID_POINTS * LUT_GRID_POINTS * LUT_GRID_POINTS * 3;
0081 static const size_t CLUT_DATA_SIZE = CLUT_ELEMENT_COUNT * CLUT_ELEMENT_SIZE;
0082 
0083 inline static void buildDummyClut(Clut &c)
0084 {
0085     c.resize(CLUT_ELEMENT_COUNT);
0086     quint16 *p = c.data();
0087 
0088     for (int ib = 0; ib < LUT_GRID_POINTS; ++ ib) {
0089         quint16 b = (quint16) ((float) ib / (LUT_GRID_POINTS - 1) * 65535.0 + 0.5);
0090         for (int ig = 0; ig < LUT_GRID_POINTS; ++ ig) {
0091             quint16 g = (quint16) ((float) ig / (LUT_GRID_POINTS - 1) * 65535.0 + 0.5);
0092             for (int ir = 0; ir < LUT_GRID_POINTS; ++ ir) {
0093                 quint16 r = (quint16) ((float) ir / (LUT_GRID_POINTS - 1) * 65535.0 + 0.5);
0094 
0095                 *(p ++) = r;
0096                 *(p ++) = g;
0097                 *(p ++) = b;
0098             }
0099         }
0100     }
0101 }
0102 
0103 #endif // COLOR_LOOKUP_TABLE_H_