Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit a8d3869

Browse files
committed
Implement support for "linear" file format detection on client side.
1 parent f7c2138 commit a8d3869

File tree

8 files changed

+92
-62
lines changed

8 files changed

+92
-62
lines changed

app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,8 @@ def index():
355355
primary_colourspace=PRIMARY_COLOURSPACE,
356356
secondary_colourspace=SECONDARY_COLOURSPACE,
357357
image_colourspace=IMAGE_COLOURSPACE,
358-
image_decoding_cctf=IMAGE_DECODING_CCTF)
358+
image_decoding_cctf=IMAGE_DECODING_CCTF,
359+
colourspace_model=COLOURSPACE_MODEL)
359360

360361

361362
@APP.after_request

colour_analysis.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
from collections import OrderedDict
1717
from werkzeug.contrib.cache import SimpleCache
1818

19-
from colour import (LOG_DECODING_CURVES, OETFS_REVERSE,
20-
RGB_COLOURSPACES, RGB_to_RGB, RGB_to_XYZ, XYZ_to_RGB,
21-
read_image)
19+
from colour import (LOG_DECODING_CURVES, OETFS_REVERSE, RGB_COLOURSPACES,
20+
RGB_to_RGB, RGB_to_XYZ, XYZ_to_RGB, read_image)
2221
from colour.models import XYZ_to_colourspace_model, function_gamma
2322
from colour.plotting import filter_cmfs, filter_RGB_colourspaces
2423
from colour.utilities import first_item, normalise_maximum, tsplit, tstack
@@ -178,13 +177,15 @@ def load_image(path, decoding_cctf='sRGB'):
178177
Image as a ndarray.
179178
"""
180179

181-
key = '{0}-{1}'.format(path, decoding_cctf)
180+
is_linear_image = os.path.splitext(path)[-1].lower() in LINEAR_FILE_FORMATS
181+
182+
key = path if is_linear_image else '{0}-{1}'.format(path, decoding_cctf)
182183

183184
RGB = IMAGE_CACHE.get(key)
184185
if RGB is None:
185186
RGB = read_image(path)
186187

187-
if os.path.splitext(path)[-1].lower() not in LINEAR_FILE_FORMATS:
188+
if not is_linear_image:
188189
RGB = DECODING_CCTFS[decoding_cctf](RGB)
189190

190191
IMAGE_CACHE.set(key, RGB)

dist/colour-analysis.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/common.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,15 @@ function loadingCallback(xhr) {
113113
info(`${this.name}: ${loaded}% loaded...`);
114114
}
115115

116+
function isLinearFileFormat(path) {
117+
var tokens = path.split('.');
118+
if (['exr', 'hdr'].indexOf(tokens[tokens.length - 1].toLowerCase()) >= 0) {
119+
return true;
120+
} else {
121+
return false;
122+
}
123+
}
124+
116125
export {
117126
serverRoute,
118127
removeObjectByName,
@@ -121,5 +130,6 @@ export {
121130
message,
122131
info,
123132
warning,
124-
loadingCallback
133+
loadingCallback,
134+
isLinearFileFormat
125135
};

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { GamutView } from './views/gamut-view.js';
22
import { ImageView } from './views/image-view.js';
33
import { updateDropdown, dropdownOptions } from './gui.js';
4-
import { info, serverRoute, warning } from './common.js';
4+
import { isLinearFileFormat, info, serverRoute, warning } from './common.js';
55

66
export {
77
GamutView,
88
ImageView,
99
updateDropdown,
1010
dropdownOptions,
11+
isLinearFileFormat,
1112
info,
1213
serverRoute,
1314
warning

src/views/gamut-view.js

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ class GamutView extends PerspectiveView {
2929
},
3030
axes: { enable: true },
3131
image: 'Rose.ProPhoto.jpg',
32-
colourspaceModel: 'CIE xyY',
3332
primaryColourspace: 'sRGB',
3433
secondaryColourspace: 'DCI-P3',
3534
imageColourspace: 'Primary',
36-
imageDecodingCctf: 'sRGB'
35+
imageDecodingCctf: 'sRGB',
36+
colourspaceModel: 'CIE xyY'
3737
},
3838
...settings
3939
};
@@ -75,11 +75,11 @@ class GamutView extends PerspectiveView {
7575
}
7676

7777
this._image = settings.image;
78-
this._colourspaceModel = settings.colourspaceModel;
7978
this._primaryColourspace = settings.primaryColourspace;
8079
this._secondaryColourspace = settings.secondaryColourspace;
8180
this._imageColourspace = settings.imageColourspace;
8281
this._imageDecodingCctf = settings.imageDecodingCctf;
82+
this._colourspaceModel = settings.colourspaceModel;
8383

8484
this._viewAxesVisual = undefined;
8585

@@ -129,38 +129,6 @@ class GamutView extends PerspectiveView {
129129
}
130130
}
131131

132-
get colourspaceModel() {
133-
return this._colourspaceModel;
134-
}
135-
136-
set colourspaceModel(value) {
137-
this._colourspaceModel = value;
138-
139-
if (this._viewAxesVisual != undefined) {
140-
this._viewAxesVisual.colourspaceModel = value;
141-
}
142-
143-
if (this._spectralLocusVisual != undefined) {
144-
this._spectralLocusVisual.colourspaceModel = value;
145-
}
146-
147-
if (this._secondaryColourspaceVisual != undefined) {
148-
this._secondaryColourspaceVisual.colourspaceModel = value;
149-
}
150-
151-
if (this._primaryColourspaceVisual != undefined) {
152-
this._primaryColourspaceVisual.colourspaceModel = value;
153-
}
154-
155-
if (this._imageScatterVisual != undefined) {
156-
this._imageScatterVisual.colourspaceModel = value;
157-
}
158-
159-
if (this._imageScatterOverlayVisual != undefined) {
160-
this._imageScatterOverlayVisual.colourspaceModel = value;
161-
}
162-
}
163-
164132
get primaryColourspace() {
165133
return this._primaryColourspace;
166134
}
@@ -240,6 +208,38 @@ class GamutView extends PerspectiveView {
240208
}
241209
}
242210

211+
get colourspaceModel() {
212+
return this._colourspaceModel;
213+
}
214+
215+
set colourspaceModel(value) {
216+
this._colourspaceModel = value;
217+
218+
if (this._viewAxesVisual != undefined) {
219+
this._viewAxesVisual.colourspaceModel = value;
220+
}
221+
222+
if (this._spectralLocusVisual != undefined) {
223+
this._spectralLocusVisual.colourspaceModel = value;
224+
}
225+
226+
if (this._secondaryColourspaceVisual != undefined) {
227+
this._secondaryColourspaceVisual.colourspaceModel = value;
228+
}
229+
230+
if (this._primaryColourspaceVisual != undefined) {
231+
this._primaryColourspaceVisual.colourspaceModel = value;
232+
}
233+
234+
if (this._imageScatterVisual != undefined) {
235+
this._imageScatterVisual.colourspaceModel = value;
236+
}
237+
238+
if (this._imageScatterOverlayVisual != undefined) {
239+
this._imageScatterOverlayVisual.colourspaceModel = value;
240+
}
241+
}
242+
243243
get viewAxesVisual() {
244244
return this._viewAxesVisual;
245245
}

src/views/image-view.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ class ImageView extends OrthographicView {
1616
camera: { position: new THREE.Vector3(0, 1, 0) },
1717
controls: { target: new THREE.Vector3(0, 0, 0) },
1818
image: 'Rose.ProPhoto.jpg',
19-
colourspaceModel: 'CIE xyY',
2019
primaryColourspace: 'sRGB',
2120
secondaryColourspace: 'DCI-P3',
2221
imageColourspace: 'Primary',
23-
imageDecodingCctf: 'sRGB'
22+
imageDecodingCctf: 'sRGB',
23+
colourspaceModel: 'CIE xyY'
2424
},
2525
...settings
2626
};
@@ -33,11 +33,11 @@ class ImageView extends OrthographicView {
3333
this.controls.target = settings.controls.target;
3434

3535
this._image = settings.image;
36-
this._colourspaceModel = settings.colourspaceModel;
3736
this._primaryColourspace = settings.primaryColourspace;
3837
this._secondaryColourspace = settings.secondaryColourspace;
3938
this._imageColourspace = settings.imageColourspace;
4039
this._imageDecodingCctf = settings.imageDecodingCctf;
40+
this._colourspaceModel = settings.colourspaceModel;
4141

4242
// The following groups are defining the rendering order.
4343
this._imageVisualGroup = new THREE.Group();
@@ -67,14 +67,6 @@ class ImageView extends OrthographicView {
6767
}
6868
}
6969

70-
get colourspaceModel() {
71-
return this._colourspaceModel;
72-
}
73-
74-
set colourspaceModel(value) {
75-
this._colourspaceModel = value;
76-
}
77-
7870
get primaryColourspace() {
7971
return this._primaryColourspace;
8072
}
@@ -134,6 +126,14 @@ class ImageView extends OrthographicView {
134126
}
135127
}
136128

129+
get colourspaceModel() {
130+
return this._colourspaceModel;
131+
}
132+
133+
set colourspaceModel(value) {
134+
this._colourspaceModel = value;
135+
}
136+
137137
get imageVisual() {
138138
return this._imageVisual;
139139
}
@@ -159,7 +159,6 @@ class ImageView extends OrthographicView {
159159
secondaryColourspace: this._secondaryColourspace,
160160
imageColourspace: this._imageColourspace,
161161
imageDecodingCctf: this._imageDecodingCctf
162-
163162
},
164163
...settings
165164
});

templates/index.html

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
var secondaryColourspace = '{{ secondary_colourspace }}';
145145
var imageColourspace = '{{ image_colourspace }}';
146146
var imageDecodingCctf = '{{ image_decoding_cctf }}';
147+
var colourspaceModel = '{{ colourspace_model }}';
147148

148149
var gamutView1 = new ColourAnalysis.GamutView(
149150
document.getElementById('gamutView1'),
@@ -152,7 +153,8 @@
152153
primaryColourspace: primaryColourspace,
153154
secondaryColourspace: secondaryColourspace,
154155
imageColourspace: imageColourspace,
155-
imageDecodingCctf: imageDecodingCctf
156+
imageDecodingCctf: imageDecodingCctf,
157+
colourspaceModel: colourspaceModel,
156158
}
157159
);
158160
gamutView1.addViewAxesVisual();
@@ -170,7 +172,8 @@
170172
primaryColourspace: primaryColourspace,
171173
secondaryColourspace: secondaryColourspace,
172174
imageColourspace: imageColourspace,
173-
imageDecodingCctf: imageDecodingCctf
175+
imageDecodingCctf: imageDecodingCctf,
176+
colourspaceModel: colourspaceModel,
174177
}
175178
);
176179
imageView1.addImageVisual();
@@ -179,19 +182,21 @@
179182

180183
class Controls {
181184
constructor() {
182-
this.colourspaceModel = [];
183-
this.image = [];
185+
186+
this.colourspaceModel = colourspaceModel;
187+
188+
this.image = image;
184189
this.imageColourspace = imageColourspace;
185190
this.imageDecodingCctf = imageDecodingCctf;
186191
this.outOfPrimaryColourspaceGamut = false;
187192
this.outOfSecondaryColourspaceGamut = false;
188193

189-
this.primaryColourspace = gamutView1.primaryColourspace;
194+
this.primaryColourspace = primaryColourspace;
190195
this.primaryColourspaceVisualWireframe = false;
191196
this.primaryColourspaceVisualVisible = true;
192197
this.primaryColourspaceVisualOpacity = 0.75;
193198

194-
this.secondaryColourspace = gamutView1.secondaryColourspace;
199+
this.secondaryColourspace = secondaryColourspace;
195200
this.secondaryColourspaceVisualWireframe = true;
196201
this.secondaryColourspaceVisualVisible = true;
197202
this.secondaryColourspaceVisualOpacity = 0.25;
@@ -316,6 +321,19 @@
316321
updateImageDecodingCctfDropdown
317322
);
318323
imageDecodingCctfController.onChange(function (value) {
324+
if (ColourAnalysis.isLinearFileFormat(controls.image)) {
325+
ColourAnalysis.warning(
326+
`"${controls.image}" is already linear and ` +
327+
`does not need to be decoded!`);
328+
controls.imageDecodingCctf = gamutView1.imageDecodingCctf;
329+
330+
var keys = ColourAnalysis.dropdownOptions(imageDecodingCctfController);
331+
imageDecodingCctfController.domElement.children[0].selectedIndex = keys.indexOf(
332+
controls.imageDecodingCctf
333+
);
334+
return;
335+
}
336+
319337
if (gamutView1.isLoading() || imageView1.isLoading()) {
320338
ColourAnalysis.warning('A visual is already loading!');
321339
controls.imageDecodingCctf = gamutView1.imageDecodingCctf;

0 commit comments

Comments
 (0)