From 9bb610b3d0ad563ce502fd87e1ac76c9d8921d8b Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 21 Feb 2014 09:43:08 +0100 Subject: ICC profile support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/__main__.py | 1 + src/icc.py | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/__main__.py b/src/__main__.py index 9d7b002..689842e 100755 --- a/src/__main__.py +++ b/src/__main__.py @@ -35,6 +35,7 @@ global monitor_controller, running, continuous_run, panic, _globals_, conf_stora global signal_SIGTERM, signal_SIGUSR1 +from icc import * from solar import * from curve import * from colour import * diff --git a/src/icc.py b/src/icc.py index 705d135..fbd7bdc 100644 --- a/src/icc.py +++ b/src/icc.py @@ -15,6 +15,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +from curve import * + def load_icc(pathname): ''' @@ -26,8 +28,12 @@ def load_icc(pathname): MLUT_TAG = 0x6d4c5554 VCGT_TAG = 0x76636774 - def make_f(R_curve, G_curve, B_curve): - pass ## TODO + def fcurve(R_curve, G_curve, B_curve): + for curve, icc in curves(R_curve, G_curve, B_curve): + for i in range(i_size): + y = int(curve[i] * (len(icc) - 1) + 0.5) + y = min(max(0, y), len(icc) - 1) + curve[i] = icc[y] int_ = lambda bs : sum([bs[len(bs) - 1 - i] << (8 * i) for i in range(len(bs))]) def read(n): @@ -42,6 +48,7 @@ def load_icc(pathname): content = list(content) read(128) + R_curve, G_curve, B_curve = [], [], [] n_tags, ptr = int_(read(4)), 128 + 4 for i_tag in range(n_tags): tag_name = int_(read(4)) @@ -50,11 +57,10 @@ def load_icc(pathname): ptr += 3 * 4 if tag_name == MLUT_TAG: read(tag_offset - ptr) - R_curve, G_curve, B_curve = [], [], [] - for i in range(256): R_curve.append(int_(read(2))) - for i in range(256): G_curve.append(int_(read(2))) - for i in range(256): B_curve.append(int_(read(2))) - return make_f(R_curve, G_curve, B_curve) + for i in range(256): R_curve.append(int_(read(2)) / 65535) + for i in range(256): G_curve.append(int_(read(2)) / 65535) + for i in range(256): B_curve.append(int_(read(2)) / 65535) + return lambda : fcurve(R_curve, G_curve, B_curve) elif tag_name == VCGT_TAG: read(tag_offset - ptr) tag_name = int_(read(4)) @@ -70,11 +76,11 @@ def load_icc(pathname): n_channels, n_entries, entry_size = 3, 256, 2 if not n_channels == 3: # assuming sRGB break - int__ = lambda m : float(int(int_(read(m)) * 8 ** (2 - m))) + int__ = lambda m : int_(read(m)) / ((256 ** m) - 1) for i in range(n_entries): R_curve.append(int__(entry_size)) for i in range(n_entries): G_curve.append(int__(entry_size)) for i in range(n_entries): B_curve.append(int__(entry_size)) - return make_f(R_curve, G_curve, B_curve) + return lambda : fcurve(R_curve, G_curve, B_curve) elif gamma_type == 1: r_gamma = int_(read(4)) / 65535 r_min = int_(read(4)) / 65535 -- cgit v1.2.3-70-g09d2