@breakside/jskit 2021.46.0 → 2022.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/Frameworks/DOM.jsframework/Info.json +2 -2
  2. package/Frameworks/DOM.jsframework/io.breakside.JSKit.DOM-bundle.js +2 -2
  3. package/Frameworks/FontKit.jsframework/Info.json +2 -2
  4. package/Frameworks/FontKit.jsframework/io.breakside.JSKit.FontKit-bundle.js +2 -2
  5. package/Frameworks/Foundation.jsframework/Info.json +2 -2
  6. package/Frameworks/Foundation.jsframework/JS/JSColor.js +9 -0
  7. package/Frameworks/Foundation.jsframework/JS/JSColorSpace.js +106 -20
  8. package/Frameworks/Foundation.jsframework/JS/JSMediaType.js +1 -1
  9. package/Frameworks/Foundation.jsframework/JS/JSTimer.js +6 -0
  10. package/Frameworks/Foundation.jsframework/io.breakside.JSKit.Foundation-bundle.js +2 -2
  11. package/Frameworks/SecurityKit.jsframework/Info.json +2 -2
  12. package/Frameworks/SecurityKit.jsframework/io.breakside.JSKit.SecurityKit-bundle.js +2 -2
  13. package/Info.json +2 -2
  14. package/Node/io.breakside.jskit-bundle.js +2 -2
  15. package/Root/Frameworks/APIKit/APIRequest.js +99 -0
  16. package/Root/Frameworks/APIKit/Info.yaml +1 -1
  17. package/Root/Frameworks/APIKitTesting/Info.yaml +1 -1
  18. package/Root/Frameworks/AuthKit/Info.yaml +1 -1
  19. package/Root/Frameworks/CSSOM/Info.yaml +1 -1
  20. package/Root/Frameworks/ChartKit/Info.yaml +1 -1
  21. package/Root/Frameworks/ConferenceKit/Info.yaml +1 -1
  22. package/Root/Frameworks/DBKit/Info.yaml +1 -1
  23. package/Root/Frameworks/DOM/Info.yaml +1 -1
  24. package/Root/Frameworks/Dispatch/Info.yaml +1 -1
  25. package/Root/Frameworks/FontKit/Info.yaml +1 -1
  26. package/Root/Frameworks/Foundation/Info.yaml +1 -1
  27. package/Root/Frameworks/Foundation/JSColor.js +9 -0
  28. package/Root/Frameworks/Foundation/JSColorSpace.js +106 -20
  29. package/Root/Frameworks/Foundation/JSMediaType.js +1 -1
  30. package/Root/Frameworks/Foundation/JSTimer.js +6 -0
  31. package/Root/Frameworks/ImageKit/IKColorProfile.js +1091 -0
  32. package/Root/Frameworks/ImageKit/IKColorSpace.js +49 -198
  33. package/Root/Frameworks/ImageKit/IKMatrix.js +124 -0
  34. package/Root/Frameworks/ImageKit/ImageKit.js +2 -0
  35. package/Root/Frameworks/ImageKit/Info.yaml +1 -1
  36. package/Root/Frameworks/MediaKit/Info.yaml +1 -1
  37. package/Root/Frameworks/MediaKitUI/Info.yaml +1 -1
  38. package/Root/Frameworks/NotificationKit/Info.yaml +1 -1
  39. package/Root/Frameworks/PDFKit/Info.yaml +1 -1
  40. package/Root/Frameworks/QRKit/Info.yaml +1 -1
  41. package/Root/Frameworks/SearchKit/Info.yaml +1 -1
  42. package/Root/Frameworks/SecurityKit/Info.yaml +1 -1
  43. package/Root/Frameworks/ServerKit/Info.yaml +1 -1
  44. package/Root/Frameworks/ServerKit/SKHTTPRequest.js +44 -0
  45. package/Root/Frameworks/ServerKitTesting/Info.yaml +1 -1
  46. package/Root/Frameworks/TestKit/Info.yaml +1 -1
  47. package/Root/Frameworks/UIKit/Info.yaml +1 -1
  48. package/Root/Frameworks/UIKit/UICollectionReusableView.js +91 -0
  49. package/Root/Frameworks/UIKit/UICollectionView.js +1254 -0
  50. package/Root/Frameworks/UIKit/UICollectionViewCell.js +121 -0
  51. package/Root/Frameworks/UIKit/UICollectionViewGridLayout.js +425 -0
  52. package/Root/Frameworks/UIKit/UICollectionViewLayout.js +82 -0
  53. package/Root/Frameworks/UIKit/UIColorWell.js +12 -1
  54. package/Root/Frameworks/UIKit/UIDisplayServer.js +5 -1
  55. package/Root/Frameworks/UIKit/UIKit.js +7 -0
  56. package/Root/Frameworks/UIKit/UILayer.js +3 -0
  57. package/Root/Frameworks/UIKit/UIListView.js +26 -11
  58. package/Root/Frameworks/UIKit/UIMenu.js +1 -1
  59. package/Root/Frameworks/UIKit/UIMenuView.js +5 -1
  60. package/Root/Frameworks/UIKit/UINavigationBar.js +2 -2
  61. package/Root/Frameworks/UIKit/UIPopupButton.js +31 -3
  62. package/Root/Frameworks/UIKit/UIScrollView.js +2 -0
  63. package/Root/Frameworks/UIKit/UISplitViewController.js +43 -9
  64. package/Root/Frameworks/UIKit/UITextField.js +3 -0
  65. package/Root/Frameworks/UIKit/UIView.js +3 -0
  66. package/Root/Frameworks/UIKit/UIViewController.js +11 -0
  67. package/Root/Frameworks/UIKitTesting/Info.yaml +1 -1
  68. package/package.json +1 -1
@@ -0,0 +1,1091 @@
1
+ // Copyright 2022 Breakside Inc.
2
+ //
3
+ // Licensed under the Breakside Public License, Version 1.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // If a copy of the License was not distributed with this file, you may
6
+ // obtain a copy at
7
+ //
8
+ // http://breakside.io/licenses/LICENSE-1.0.txt
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+
16
+ // #import Foundation
17
+ // #import "IKMatrix.js"
18
+ 'use strict';
19
+
20
+ (function(){
21
+
22
+ var logger = JSLog("imagekit", "colorprofile");
23
+
24
+ JSClass("IKColorProfile", JSColorSpace, {
25
+
26
+ initWithData: function(data){
27
+ if (data === null || data === undefined){
28
+ return null;
29
+ }
30
+ this._data = data;
31
+ this._dataView = data.dataView();
32
+ try{
33
+ this._readHeader();
34
+ this._readTags();
35
+ }catch (e){
36
+ logger.warn(e);
37
+ return null;
38
+ }
39
+ },
40
+
41
+ data: JSReadOnlyProperty('_data', null),
42
+ _dataView: null,
43
+ numberOfComponents: 0,
44
+
45
+ preferredCMM: 0,
46
+ version: 0,
47
+ profileClass: null,
48
+ colorSpace: null,
49
+ connectionSpace: null,
50
+ createdDate: null,
51
+ signature: null,
52
+ platform: null,
53
+ manufacturer: null,
54
+ embedded: false,
55
+ independent: false,
56
+ model: null,
57
+ renderingIntent: 0,
58
+ creator: 0,
59
+ id: null,
60
+
61
+ _readHeader: function(){
62
+ if (this._data.length < 128){
63
+ throw new Error("Invalid profile, not enough data for header");
64
+ }
65
+ var data = this._data;
66
+ var dataView = this._dataView;
67
+ if (dataView.getUint32(0) != data.length){
68
+ throw new Error("Invalid profile, size does not match data length");
69
+ }
70
+ this.preferredCMM = dataView.getUint32(4);
71
+ this.version = dataView.getUint32(8);
72
+ this.profileClass = String.initWithData(data.subdataInRange(JSRange(12, 4)), String.Encoding.latin1);
73
+ this.colorSpace = String.initWithData(data.subdataInRange(JSRange(16, 4)), String.Encoding.latin1);
74
+ this.connectionSpace = String.initWithData(data.subdataInRange(JSRange(20, 4)), String.Encoding.latin1);
75
+ this.createdDate = JSCalendar.gregorian.dateFromComponents({
76
+ year: dataView.getUint16(24),
77
+ month: dataView.getUint16(26),
78
+ day: dataView.getUint16(28),
79
+ hour: dataView.getUint16(30),
80
+ minute: dataView.getUint16(32),
81
+ second: dataView.getUint16(34),
82
+ timezone: JSTimeZone.utc
83
+ });
84
+ this.signature = String.initWithData(data.subdataInRange(JSRange(36, 4)), String.Encoding.latin1);
85
+ if (this.signature !== "acsp"){
86
+ throw new Error("Invalid profile signature: %s".sprintf(this.signature));
87
+ }
88
+ this.platform = String.initWithData(data.subdataInRange(JSRange(40, 4)), String.Encoding.latin1);
89
+ var flags = dataView.getUint32(44);
90
+ this.embedded = (flags & 0x01) === 0x01;
91
+ this.independent = (flags & 0x02) === 0x02;
92
+ this.manufacturer = dataView.getUint32(48);
93
+ this.model = dataView.getUint32(52);
94
+ // attributes1: dataView.getUint32(56),
95
+ // attributes2: dataView.getUint32(60),
96
+ this.renderingIntent = dataView.getUint32(64);
97
+ this.connectionWhitepoint = XYZ32(dataView.getUint32(68), dataView.getUint32(72), dataView.getUint32(76));
98
+ this.creator = dataView.getUint32(80);
99
+ this.id = data.subdataInRange(JSRange(84, 16)).hexStringRepresentation();
100
+ switch (this.colorSpace){
101
+ case IKColorProfile.ColorSpace.xyz:
102
+ this.numberOfComponents = 3;
103
+ break;
104
+ case IKColorProfile.ColorSpace.lab:
105
+ this.numberOfComponents = 3;
106
+ break;
107
+ case IKColorProfile.ColorSpace.luv:
108
+ this.numberOfComponents = 3;
109
+ break;
110
+ case IKColorProfile.ColorSpace.ycbcr:
111
+ this.numberOfComponents = 3;
112
+ break;
113
+ case IKColorProfile.ColorSpace.yxy:
114
+ this.numberOfComponents = 3;
115
+ break;
116
+ case IKColorProfile.ColorSpace.rgb:
117
+ this.numberOfComponents = 3;
118
+ break;
119
+ case IKColorProfile.ColorSpace.gray:
120
+ this.numberOfComponents = 1;
121
+ break;
122
+ case IKColorProfile.ColorSpace.hsv:
123
+ this.numberOfComponents = 3;
124
+ break;
125
+ case IKColorProfile.ColorSpace.hls:
126
+ this.numberOfComponents = 3;
127
+ break;
128
+ case IKColorProfile.ColorSpace.cmyk:
129
+ this.numberOfComponents = 4;
130
+ break;
131
+ case IKColorProfile.ColorSpace.cmy:
132
+ this.numberOfComponents = 3;
133
+ break;
134
+ case IKColorProfile.ColorSpace.twoColor:
135
+ this.numberOfComponents = 2;
136
+ break;
137
+ case IKColorProfile.ColorSpace.threeColor:
138
+ this.numberOfComponents = 3;
139
+ break;
140
+ case IKColorProfile.ColorSpace.fourColor:
141
+ this.numberOfComponents = 4;
142
+ break;
143
+ case IKColorProfile.ColorSpace.fiveColor:
144
+ this.numberOfComponents = 5;
145
+ break;
146
+ case IKColorProfile.ColorSpace.sixColor:
147
+ this.numberOfComponents = 6;
148
+ break;
149
+ case IKColorProfile.ColorSpace.sevenColor:
150
+ this.numberOfComponents = 7;
151
+ break;
152
+ case IKColorProfile.ColorSpace.eightColor:
153
+ this.numberOfComponents = 8;
154
+ break;
155
+ case IKColorProfile.ColorSpace.nineColor:
156
+ this.numberOfComponents = 9;
157
+ break;
158
+ case IKColorProfile.ColorSpace.tenColor:
159
+ this.numberOfComponents = 10;
160
+ break;
161
+ case IKColorProfile.ColorSpace.elevenColor:
162
+ this.numberOfComponents = 11;
163
+ break;
164
+ case IKColorProfile.ColorSpace.twelveColor:
165
+ this.numberOfComponents = 12;
166
+ break;
167
+ case IKColorProfile.ColorSpace.thirteenColor:
168
+ this.numberOfComponents = 13;
169
+ break;
170
+ case IKColorProfile.ColorSpace.fourteenColor:
171
+ this.numberOfComponents = 14;
172
+ break;
173
+ case IKColorProfile.ColorSpace.fifteenColor:
174
+ this.numberOfComponents = 15;
175
+ break;
176
+ default:
177
+ throw new Error("Invalid color space: %s".sprintf(this.colorSpace));
178
+ }
179
+ },
180
+
181
+ _tags: null,
182
+
183
+ _readTags: function(){
184
+ if (this._data.length < 128){
185
+ throw new Error("Invalid profile, not enough data for tag count");
186
+ }
187
+ var tagCount = this._dataView.getUint32(128);
188
+ if (this._data.length < 132 + tagCount * 12){
189
+ throw new Error("Invalid profile, not enough data for tag table");
190
+ }
191
+ var offset = 132;
192
+ this._tags = {};
193
+ var tag;
194
+ var name;
195
+ for (var i = 0; i < tagCount; ++i){
196
+ name = String.initWithData(this._data.subdataInRange(JSRange(offset, 4)), String.Encoding.latin1);
197
+ tag = {
198
+ name: name,
199
+ range: JSRange(this._dataView.getUint32(offset + 4), this._dataView.getUint32(offset + 8))
200
+ };
201
+ if (tag.range.end > this._data.length){
202
+ throw new Error("Invalid profile, not enough data for tag %s at %d (%d)".sprintf(tag.name, tag.range.location, tag.range.length));
203
+ }
204
+ this._tags[tag.name] = tag;
205
+ offset += 12;
206
+ }
207
+ for (var propertyName in IKColorProfile.Tag){
208
+ name = IKColorProfile.Tag[propertyName];
209
+ this.definePropertyForTag(name, propertyName);
210
+ }
211
+ },
212
+
213
+ definePropertyForTag: function(name, propertyName){
214
+ Object.defineProperty(this, propertyName, {
215
+ configurable: true,
216
+ get: function(){
217
+ var value = this.getTag(name);
218
+ Object.defineProperty(this, propertyName, {value: value});
219
+ return value;
220
+ }
221
+ });
222
+ },
223
+
224
+ getTag: function(name){
225
+ var tag = this._tags[name];
226
+ if (!tag){
227
+ return null;
228
+ }
229
+ var data = this.data.subdataInRange(tag.range);
230
+ var allowedTypes = IKColorProfile.allowedTypesForTag[name];
231
+ return IKColorProfileType.initWithData(data, allowedTypes);
232
+ },
233
+
234
+ });
235
+
236
+ IKColorProfile.ProfileClass = {
237
+ input: "scnr",
238
+ display: "mntr",
239
+ output: "prtr",
240
+ deviceLink: "link",
241
+ colorSpace: "spac",
242
+ abstract: "abst",
243
+ namedColor: "nmcl"
244
+ };
245
+
246
+ IKColorProfile.ColorSpace = {
247
+ xyz: "XYZ ",
248
+ lab: "Lab ",
249
+ luv: "Luv ",
250
+ ycbcr: "YCbr",
251
+ yxy: "Yxy ",
252
+ rgb: "RGB ",
253
+ gray: "GRAY",
254
+ hsv: "HSV ",
255
+ hls: "HLS ",
256
+ cmyk: "CMYK",
257
+ cmy: "CMY ",
258
+ twoColor: "2CLR",
259
+ threeColor: "3CLR",
260
+ fourColor: "4CLR",
261
+ fiveColor: "5CLR",
262
+ sixColor: "6CLR",
263
+ sevenColor: "7CLR",
264
+ eightColor: "8CLR",
265
+ nineColor: "9CLR",
266
+ tenColor: "ACLR",
267
+ elevenColor: "BCLR",
268
+ twelveColor: "CCLR",
269
+ thirteenColor: "DCLR",
270
+ fourteenColor: "ECLR",
271
+ fifteenColor: "FCLR"
272
+ };
273
+
274
+ IKColorProfile.Platform = {
275
+ apple: "APPL",
276
+ microsoft: "MSFT",
277
+ siliconGraphics: "SGI ",
278
+ sunMicrosystems: "SUNW"
279
+ };
280
+
281
+ IKColorProfile.RenderingIntent = {
282
+ perceptual: 0,
283
+ mediaRelative: 1,
284
+ saturation: 2,
285
+ absolute: 3
286
+ };
287
+
288
+ IKColorProfile.Tag = {
289
+ aToB0: "A2B0",
290
+ aToB1: "A2B1",
291
+ aToB2: "A2B2",
292
+ blueMatrixColumn: "bXYZ",
293
+ blueToneReproductionCurve: "bTRC",
294
+ bToA0: "B2A0",
295
+ bToA1: "B2A1",
296
+ bToA2: "B2A2",
297
+ bToD0: "B2D0",
298
+ bToD1: "B2D1",
299
+ bToD2: "B2D2",
300
+ bToD3: "B2D3",
301
+ calibrationDate: "calt",
302
+ charTarget: "targ",
303
+ chromaticAdaptation: "chad",
304
+ chromaticity: "chrm",
305
+ colorantOrder: "clro",
306
+ colorantTable: "clrt",
307
+ colorantTableOut: "clot",
308
+ colorimetricIntentImageState: "ciis",
309
+ copyright: "cprt",
310
+ deviceManufacturer: "dmnd",
311
+ deviceModelDescription: "dmdd",
312
+ dToB0: "D2B0",
313
+ dToB1: "D2B1",
314
+ dToB2: "D2B2",
315
+ dToB3: "D2B3",
316
+ gamut: "gamt",
317
+ grayToneReproductionCurve: "kTRC",
318
+ greenMatrixColumn: "gXYZ",
319
+ greenToneReproductionCurve: "gTRC",
320
+ luminance: "lumi",
321
+ measurement: "meas",
322
+ mediaWhitepoint: "wtpt",
323
+ namedColor: "ncl2",
324
+ outputResponse: "resp",
325
+ perceptualRenderingIntentGamut: "rig0",
326
+ preview0: "pre0",
327
+ preview1: "pre1",
328
+ preview2: "pre2",
329
+ profileDescription: "desc",
330
+ profileSequenceDescription: "pseq",
331
+ profileSequenceIdentifier: "psid",
332
+ redMatrixColumn: "rXYZ",
333
+ redToneReproductionCurve: "rTRC",
334
+ saturationRenderingIntentGamut: "rig2",
335
+ technology: "tech",
336
+ viewingConditionsDescription: "vued",
337
+ viewingConditions: "view"
338
+ };
339
+
340
+ IKColorProfile.DataType = {
341
+ chromaticity: "chrm",
342
+ colorantOrder: "clro",
343
+ colorantTable: "clrt",
344
+ curve: "curv",
345
+ data: "data",
346
+ dateTime: "dtim",
347
+ lookupTable8: "mft1",
348
+ lookupTable16: "mft2",
349
+ lookupTableAToB: "mAB ",
350
+ lookupTableBToA: "mBA ",
351
+ measurement: "meas",
352
+ multiLocalizedUnicode: "mluc",
353
+ multiProcessElements: "mpet",
354
+ namedColor: "ncl2",
355
+ parametricCurve: "para",
356
+ profileSequenceDescription: "pseq",
357
+ profileSequenceIdentifier: "psid",
358
+ responseCurveSet16: "rcs2",
359
+ s15Fixed16Array: "sf32",
360
+ signature: "sig ",
361
+ text: "text",
362
+ u16Fixed16Array: "uf32",
363
+ uin8Array: "ui08",
364
+ uint16Array: "ui16",
365
+ uint32Array: "ui32",
366
+ uint64Array: "ui64",
367
+ viewingConditions: "view",
368
+ xyz: "XYZ "
369
+ };
370
+
371
+ IKColorProfile.allowedTypesForTag = {};
372
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.aToB0] = [IKColorProfile.DataType.lookupTable8, IKColorProfile.DataType.lookupTable16, IKColorProfile.DataType.lookupTableAToB];
373
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.aToB1] = [IKColorProfile.DataType.lookupTable8, IKColorProfile.DataType.lookupTable16, IKColorProfile.DataType.lookupTableAToB];
374
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.aToB2] = [IKColorProfile.DataType.lookupTable8, IKColorProfile.DataType.lookupTable16, IKColorProfile.DataType.lookupTableAToB];
375
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.blueMatrixColumn] = [IKColorProfile.DataType.xyz];
376
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.blueToneReproductionCurve] = [IKColorProfile.DataType.curve, IKColorProfile.DataType.parametricCurve];
377
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.bToA0] = [IKColorProfile.DataType.lookupTable8, IKColorProfile.DataType.lookupTable16, IKColorProfile.DataType.lookupTableBToA];
378
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.bToA1] = [IKColorProfile.DataType.lookupTable8, IKColorProfile.DataType.lookupTable16, IKColorProfile.DataType.lookupTableBToA];
379
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.bToA2] = [IKColorProfile.DataType.lookupTable8, IKColorProfile.DataType.lookupTable16, IKColorProfile.DataType.lookupTableBToA];
380
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.bToD0] = [IKColorProfile.DataType.multiProcessElements];
381
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.bToD1] = [IKColorProfile.DataType.multiProcessElements];
382
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.bToD2] = [IKColorProfile.DataType.multiProcessElements];
383
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.bToD3] = [IKColorProfile.DataType.multiProcessElements];
384
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.calibrationDate] = [IKColorProfile.DataType.dateTime];
385
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.charTarget] = [IKColorProfile.DataType.text];
386
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.chromaticAdaptation] = [IKColorProfile.DataType.s15Fixed16Array];
387
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.chromaticity] = [IKColorProfile.DataType.chromaticity];
388
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.colorantOrder] = [IKColorProfile.DataType.colorantOrder];
389
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.colorantTable] = [IKColorProfile.DataType.colorantTable];
390
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.colorantTableOut] = [IKColorProfile.DataType.colorantTable];
391
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.colorimetricIntentImageState] = [IKColorProfile.DataType.signature];
392
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.copyright] = [IKColorProfile.DataType.multiLocalizedUnicode];
393
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.deviceManufacturer] = [IKColorProfile.DataType.multiLocalizedUnicode];
394
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.deviceModelDescription] = [IKColorProfile.DataType.multiLocalizedUnicode];
395
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.dToB0] = [IKColorProfile.DataType.multiProcessElements];
396
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.dToB1] = [IKColorProfile.DataType.multiProcessElements];
397
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.dToB2] = [IKColorProfile.DataType.multiProcessElements];
398
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.dToB3] = [IKColorProfile.DataType.multiProcessElements];
399
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.gamut] = [IKColorProfile.DataType.lookupTable8, IKColorProfile.DataType.lookupTable16, IKColorProfile.DataType.lookupTableBToA];
400
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.grayToneReproductionCurve] = [IKColorProfile.DataType.curve, IKColorProfile.DataType.parametricCurve];
401
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.greenMatrixColumn] = [IKColorProfile.DataType.xyz];
402
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.greenToneReproductionCurve] = [IKColorProfile.DataType.curve, IKColorProfile.DataType.parametricCurve];
403
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.luminance] = [IKColorProfile.DataType.xyz];
404
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.measurement] = [IKColorProfile.DataType.measurement];
405
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.mediaWhitepoint] = [IKColorProfile.DataType.xyz];
406
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.namedColor] = [IKColorProfile.DataType.namedColor];
407
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.outputResponse] = [IKColorProfile.DataType.responseCurveSet16];
408
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.perceptualRenderingIntentGamut] = [IKColorProfile.DataType.signature];
409
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.preview0] = [IKColorProfile.DataType.lookupTable8, IKColorProfile.DataType.lookupTable16, IKColorProfile.DataType.lookupTableAToB, IKColorProfile.DataType.lookupTableBToA];
410
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.preview1] = [IKColorProfile.DataType.lookupTable8, IKColorProfile.DataType.lookupTable16, IKColorProfile.DataType.lookupTableBToA];
411
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.preview2] = [IKColorProfile.DataType.lookupTable8, IKColorProfile.DataType.lookupTable16, IKColorProfile.DataType.lookupTableBToA];
412
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.profileDescription] = [IKColorProfile.DataType.multiLocalizedUnicode];
413
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.profileSequenceDescription] = [IKColorProfile.DataType.profileSequenceDescription];
414
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.profileSequenceIdentifier] = [IKColorProfile.DataType.profileSequenceIdentifier];
415
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.redMatrixColumn] = [IKColorProfile.DataType.xyz];
416
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.redToneReproductionCurve] = [IKColorProfile.DataType.curve, IKColorProfile.DataType.parametricCurve];
417
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.saturationRenderingIntentGamut] = [IKColorProfile.DataType.signature];
418
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.technology] = [IKColorProfile.DataType.signature];
419
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.viewingConditionsDescription] = [IKColorProfile.DataType.multiLocalizedUnicode];
420
+ IKColorProfile.allowedTypesForTag[IKColorProfile.Tag.viewingConditions] = [IKColorProfile.DataType.viewingConditions];
421
+
422
+ IKColorProfile.Curve = {
423
+ identity: function(x){
424
+ return x;
425
+ },
426
+ gamma: function(g){
427
+ var fn = function(x){
428
+ return Math.pow(x, g);
429
+ };
430
+ fn.inverse = function(y){
431
+ y = Math.min(1, Math.max(0, y));
432
+ return Math.pow(y, 1.0 / g);
433
+ };
434
+ return fn;
435
+ },
436
+ parametric1: function(g, a, b){
437
+ var fn = function(x){
438
+ if (x >= -b / a){
439
+ return Math.pow(a * x + b, g);
440
+ }
441
+ return 0;
442
+ };
443
+ fn.inverse = function(y){
444
+ y = Math.min(1, Math.max(0, y));
445
+ if (y === 0){
446
+ return -b / a;
447
+ }
448
+ return (Math.pow(y, 1.0 / g) - b) / a;
449
+ };
450
+ return fn;
451
+ },
452
+ parametric2: function(g, a, b, c){
453
+ var fn = function(x){
454
+ if (x >= - b / a){
455
+ return Math.pow(a * x + b, g) + c;
456
+ }
457
+ return c;
458
+ };
459
+ fn.inverse = function(y){
460
+ y = Math.min(1, Math.max(0, y));
461
+ if (y === c){
462
+ return -b / a;
463
+ }
464
+ return (Math.pow(y - c, 1.0 / g) - b) / a;
465
+ };
466
+ return fn;
467
+ },
468
+ parametric3: function(g, a, b, c, d){
469
+ var fn = function(x){
470
+ if (x >= d){
471
+ return Math.pow(a * x + b, g);
472
+ }
473
+ return c * x;
474
+ };
475
+ fn.inverse = function(y){
476
+ y = Math.min(1, Math.max(0, y));
477
+ if (y < c * d){
478
+ return y / c;
479
+ }
480
+ return (Math.pow(y, 1.0 / g) - b) / a;
481
+ };
482
+ return fn;
483
+ },
484
+ parametric4: function(g, a, b, c, d, e, f){
485
+ var fn = function(x){
486
+ if (x >= d){
487
+ return Math.pow(a * x + b, g) + c;
488
+ }
489
+ return c * x + f;
490
+ };
491
+ fn.inverse = function(y){
492
+ y = Math.min(1, Math.max(0, y));
493
+ if (y < c * d + f){
494
+ return (y - f) / c;
495
+ }
496
+ return (Math.pow(y - c, 1.0 / g) - b) / a;
497
+ };
498
+ return fn;
499
+ },
500
+ };
501
+
502
+ IKColorProfile.Curve.identity.inverse = IKColorProfile.Curve.identity;
503
+
504
+
505
+
506
+ JSClass("IKColorProfileType", JSObject, {
507
+
508
+ data: null,
509
+
510
+ initWithData: function(data, allowedTypes){
511
+ if (this.$class === IKColorProfileType){
512
+ var type = String.initWithData(data.subdataInRange(JSRange(0, 4)), String.Encoding.latin1);
513
+ if (allowedTypes !== undefined){
514
+ var allowed = false;
515
+ for (var i = 0, l = allowedTypes.length; i < l && !allowed; ++i){
516
+ if (type === allowedTypes[i]){
517
+ allowed = true;
518
+ }
519
+ }
520
+ if (!allowed){
521
+ return null;
522
+ }
523
+ }
524
+ var subclass = IKColorProfileType.registeredSubclasses[type];
525
+ if (subclass){
526
+ return subclass.initWithData(data);
527
+ }
528
+ this.data = data;
529
+ }else{
530
+ this.data = data;
531
+ }
532
+ }
533
+
534
+ });
535
+
536
+ IKColorProfileType.registeredSubclasses = {};
537
+
538
+ IKColorProfileType.$extend = function(extensions, name){
539
+ var subclass = JSObject.$extend.call(this, extensions, name);
540
+ IKColorProfileType.registeredSubclasses[subclass.prototype.type] = subclass;
541
+ return subclass;
542
+ };
543
+
544
+ JSClass("IKColorProfileCurve", IKColorProfileType, {
545
+
546
+ type: IKColorProfile.DataType.curve,
547
+ fn: null,
548
+
549
+ initWithData: function(data){
550
+ IKColorProfileCurve.$super.initWithData.call(this, data);
551
+ var dataView = data.dataView();
552
+ var n = dataView.getUint32(8);
553
+ if (n === 0){
554
+ this.fn = IKColorProfile.Curve.identity;
555
+ }else if (n === 1){
556
+ if (data.length < 14){
557
+ logger.warn("not enough data for curve gamma value");
558
+ return null;
559
+ }
560
+ var g = u8Fixed8(dataView.getUint16(12));
561
+ this.fn = IKColorProfile.Curve.gamma(g);
562
+ }else{
563
+ var offset = 12;
564
+ var end = offset + n + n;
565
+ if (data.length < end){
566
+ logger.warn("not enough data for curve values");
567
+ return null;
568
+ }
569
+ var table = [];
570
+ var sorted = true;
571
+ for (; offset < end; offset += 2){
572
+ table.push(dataView.getUint16(offset) / 0xFFFF);
573
+ }
574
+ var searcher = JSBinarySearcher(table, function(a, b){
575
+ return a - b;
576
+ });
577
+ this.fn = function(x){
578
+ var i = Math.min(1, Math.max(0, x)) * (n - 1);
579
+ var i0 = Math.floor(i);
580
+ var i1 = i0 + 1;
581
+ var w0 = i1 - i;
582
+ var w1 = 1 - w0;
583
+ if (w1 <= 0.00001){
584
+ return table[i0];
585
+ }
586
+ return (table[i0] * w0) + (table[i1] * w1);
587
+ };
588
+ this.fn.inverse = function(y){
589
+ var i0 = searcher.insertionIndexForValue(y);
590
+ if (i0 >= n - 1){
591
+ return 1;
592
+ }
593
+ var i1 = i0 + 1;
594
+ var y0 = table[i0];
595
+ var y1 = table[i1];
596
+ var w1 = (y - y0) / (y1 - y0);
597
+ var w0 = 1 - w1;
598
+ return (i0 * w0 + i1 * w1) / (n - 1);
599
+ };
600
+ }
601
+ },
602
+
603
+ });
604
+
605
+ JSClass("IKColorProfileParametricCurve", IKColorProfileType, {
606
+
607
+ type: IKColorProfile.DataType.parametricCurve,
608
+ fn: null,
609
+
610
+ initWithData: function(data){
611
+ IKColorProfileParametricCurve.$super.initWithData.call(this, data);
612
+ var dataView = data.dataView();
613
+ var type = dataView.getUint16(8);
614
+ var g, a, b, c, d, e, f;
615
+ if (data.length < 16){
616
+ logger.warn("not enough data for parametric curve gamma");
617
+ return null;
618
+ }
619
+ g = dataView.getUint32(12) / 0xFFFFFFFF;
620
+ if (type === 0){
621
+ this.fn = IKColorProfile.Curve.gamma(g);
622
+ return;
623
+ }
624
+ if (data.length < 24){
625
+ logger.warn("not enough data for parametric curve 1");
626
+ return null;
627
+ }
628
+ a = dataView.getUint32(16) / 0xFFFFFFFF;
629
+ b = dataView.getUint32(20) / 0xFFFFFFFF;
630
+ if (type === 1){
631
+ this.fn = IKColorProfile.Curve.parametric1(g, a, b);
632
+ return;
633
+ }
634
+ if (data.length < 28){
635
+ logger.warn("not enough data for parametric curve 2");
636
+ return null;
637
+ }
638
+ c = dataView.getUint32(24) / 0xFFFFFFFF;
639
+ if (type === 2){
640
+ this.fn = IKColorProfile.Curve.parametric2(g, a, b, c);
641
+ return;
642
+ }
643
+ if (data.length < 32){
644
+ logger.warn("not enough data for parametric curve 3");
645
+ return null;
646
+ }
647
+ d = dataView.getUint32(28) / 0xFFFFFFFF;
648
+ if (type === 3){
649
+ this.fn = IKColorProfile.Curve.parametric3(g, a, b, c, d);
650
+ return;
651
+ }
652
+ if (data.length < 40){
653
+ logger.warn("not enough data for parametric curve 4");
654
+ return null;
655
+ }
656
+ e = dataView.getUint32(32) / 0xFFFFFFFF;
657
+ f = dataView.getUint32(36) / 0xFFFFFFFF;
658
+ if (type === 4){
659
+ this.fn = IKColorProfile.Curve.parametric4(g, a, b, c, d, e, f);
660
+ return;
661
+ }
662
+ logger.warn("unsupported parametric curve type: %d".sprintf(type));
663
+ return null;
664
+ },
665
+
666
+ });
667
+
668
+ JSClass("IKColorProfileXYZ", IKColorProfileType, {
669
+
670
+ type: IKColorProfile.DataType.xyz,
671
+ value: null,
672
+
673
+ initWithData: function(data){
674
+ IKColorProfileXYZ.$super.initWithData.call(this, data);
675
+ var dataView = data.dataView();
676
+ if (data.length < 20){
677
+ logger.warn("not enough data for XYZ data");
678
+ return null;
679
+ }
680
+ this.value = XYZ32(
681
+ dataView.getUint32(8),
682
+ dataView.getUint32(12),
683
+ dataView.getUint32(16)
684
+ );
685
+ },
686
+
687
+ });
688
+
689
+ JSClass("IKColorProfileLookupTable8", IKColorProfileType, {
690
+
691
+ type: IKColorProfile.DataType.lookupTable8,
692
+ numberOfInputChannels: 0,
693
+ numberOfOutputChannels: 0,
694
+ numberOfGridPoints: 0,
695
+ matrix: null,
696
+ inputTables: null,
697
+ outputTables: null,
698
+ lookupTableDataView: null,
699
+ stride: 0,
700
+
701
+ initWithData: function(data){
702
+ IKColorProfileLookupTable8.$super.initWithData.call(this, data);
703
+ var dataView = data.dataView();
704
+ if (data.length < 48){
705
+ logger.warn("not enough data for lut8 matrix");
706
+ return null;
707
+ }
708
+ this.numberOfInputChannels = dataView.getUint8(8);
709
+ this.numberOfOutputChannels = dataView.getUint8(9);
710
+ this.numberOfGridPoints = dataView.getUint8(10);
711
+ this.matrix = IKMatrix([
712
+ [s15Fixed16(dataView.getUint32(12)), s15Fixed16(dataView.getUint32(16)), s15Fixed16(dataView.getUint32(20))],
713
+ [s15Fixed16(dataView.getUint32(24)), s15Fixed16(dataView.getUint32(28)), s15Fixed16(dataView.getUint32(32))],
714
+ [s15Fixed16(dataView.getUint32(36)), s15Fixed16(dataView.getUint32(40)), s15Fixed16(dataView.getUint32(44))]
715
+ ]);
716
+ var offset = 48;
717
+ var end;
718
+ var i, j, k;
719
+ var table;
720
+ this.stride = this.numberOfOutputChannels;
721
+ this.inputTables = [];
722
+ this.outputTables = [];
723
+ for (i = 0; i < this.numberOfInputChannels; ++i){
724
+ this.stride *= this.numberOfGridPoints;
725
+ end = offset + 256;
726
+ if (data.length < end){
727
+ logger.warn("not enough data for lut8 input tables");
728
+ return null;
729
+ }
730
+ table = [];
731
+ for (; offset < end; ++offset){
732
+ table.push(dataView.getUint8(offset) / 255.0);
733
+ }
734
+ this.inputTables.push(table);
735
+ }
736
+ end = offset + this.stride;
737
+ if (data.length < end){
738
+ logger.warn("not enough data for lut8 clut");
739
+ return null;
740
+ }
741
+ this.lookupTableDataView = this.data.subdataInRange(JSRange(offset, this.stride)).dataView();
742
+ offset += this.stride;
743
+ for (i = 0; i < this.numberOfOutputChannels; ++i){
744
+ end = offset + 256;
745
+ if (data.length < end){
746
+ logger.warn("not enough data for lut8 output tables");
747
+ return null;
748
+ }
749
+ table = [];
750
+ for (; offset < end; ++offset){
751
+ table.push(dataView.getUint8(offset) / 255.0);
752
+ }
753
+ this.outputTables.push(table);
754
+ }
755
+ },
756
+
757
+ lookup: function(components){
758
+ var input = [];
759
+ var i, j, l;
760
+ var x, x0, x1;
761
+ var offsetCount;
762
+ var offsets = [0];
763
+ var weights = [1];
764
+ var w0, w1;
765
+ var stride = this.stride;
766
+ var d;
767
+ for (i = 0; i < this.numberOfInputChannels; ++i){
768
+ stride /= this.numberOfGridPoints;
769
+ x = this.inputTables[i][Math.round(Math.max(0, Math.min(1, components[i])) * 255)];
770
+ x *= (this.numberOfGridPoints - 1);
771
+ x0 = Math.floor(x);
772
+ d = x0 * stride;
773
+ for (j = 0, l = offsets.length; j < l; ++j){
774
+ offsets[j] += d;
775
+ }
776
+ if (x > x0){
777
+ x1 = x0 + 1;
778
+ w1 = (x - x0);
779
+ w0 = 1 - w1;
780
+ for (j = 0, l = offsets.length; j < l; ++j){
781
+ offsets.push(offsets[j] + stride);
782
+ weights.push(weights[j] * w1);
783
+ weights[j] *= w0;
784
+ }
785
+ }
786
+ }
787
+ var output = [];
788
+ for (i = 0; i < this.numberOfOutputChannels; ++i){
789
+ output.push(0);
790
+ }
791
+ var offset;
792
+ for (i = 0, l = offsets.length; i < l; ++i){
793
+ offset = offsets[i];
794
+ for (j = 0; j < this.numberOfOutputChannels; ++j, ++offset){
795
+ output[j] += this.outputTables[j][this.lookupTableDataView.getUint8(offset)] * weights[i];
796
+ }
797
+ }
798
+ return output;
799
+ }
800
+
801
+ });
802
+
803
+ JSClass("IKColorProfileLookupTable16", IKColorProfileType, {
804
+
805
+ type: IKColorProfile.DataType.lookupTable16,
806
+ numberOfInputTableEntries: 0,
807
+ mumberOfOutputTableEntries: 0,
808
+ numberOfInputChannels: 0,
809
+ numberOfOutputChannels: 0,
810
+ numberOfGridPoints: 0,
811
+ matrix: null,
812
+ inputTables: null,
813
+ outputTables: null,
814
+ lookupTableDataView: null,
815
+ stride: 0,
816
+
817
+ initWithData: function(data){
818
+ IKColorProfileLookupTable16.$super.initWithData.call(this, data);
819
+ var dataView = data.dataView();
820
+ if (data.length < 48){
821
+ logger.warn("not enough data for lut8 matrix");
822
+ return null;
823
+ }
824
+ this.numberOfInputChannels = dataView.getUint8(8);
825
+ this.numberOfOutputChannels = dataView.getUint8(9);
826
+ this.numberOfGridPoints = dataView.getUint8(10);
827
+ this.matrix = IKMatrix([
828
+ [s15Fixed16(dataView.getUint32(12)), s15Fixed16(dataView.getUint32(16)), s15Fixed16(dataView.getUint32(20))],
829
+ [s15Fixed16(dataView.getUint32(24)), s15Fixed16(dataView.getUint32(28)), s15Fixed16(dataView.getUint32(32))],
830
+ [s15Fixed16(dataView.getUint32(36)), s15Fixed16(dataView.getUint32(40)), s15Fixed16(dataView.getUint32(44))]
831
+ ]);
832
+ this.numberOfInputTableEntries = dataView.getUint16(48);
833
+ this.numberOfOutputTableEntries = dataView.getUint16(50);
834
+ var offset = 52;
835
+ var end;
836
+ var i, j, k;
837
+ var table;
838
+ this.stride = this.numberOfOutputChannels + this.numberOfOutputChannels;
839
+ this.inputTables = [];
840
+ this.outputTables = [];
841
+ for (i = 0; i < this.numberOfInputChannels; ++i){
842
+ this.stride *= this.numberOfGridPoints;
843
+ end = offset + this.numberOfInputTableEntries + this.numberOfInputTableEntries;
844
+ if (data.length < end){
845
+ logger.warn("not enough data for lut16 input tables");
846
+ return null;
847
+ }
848
+ table = [];
849
+ for (; offset < end; offset += 2){
850
+ table.push(dataView.getUint16(offset) / 65535.0);
851
+ }
852
+ this.inputTables.push(table);
853
+ }
854
+ end = offset + this.stride;
855
+ if (data.length < end){
856
+ logger.warn("not enough data for lut8 clut");
857
+ return null;
858
+ }
859
+ this.lookupTableDataView = this.data.subdataInRange(JSRange(offset, this.stride)).dataView();
860
+ offset += this.stride;
861
+ for (i = 0; i < this.numberOfOutputChannels; ++i){
862
+ end = offset + this.numberOfOutputTableEntries + this.numberOfOutputTableEntries;
863
+ if (data.length < end){
864
+ logger.warn("not enough data for lut8 output tables");
865
+ return null;
866
+ }
867
+ table = [];
868
+ for (; offset < end; offset += 2){
869
+ table.push(dataView.getUint16(offset) / 65535.0);
870
+ }
871
+ this.outputTables.push(table);
872
+ }
873
+ },
874
+
875
+ lookup: function(components){
876
+ var input = [];
877
+ var i, j, l;
878
+ var x, x0, x1;
879
+ var offsetCount;
880
+ var offsets = [0];
881
+ var weights = [1];
882
+ var w0, w1;
883
+ var stride = this.stride;
884
+ var d;
885
+ for (i = 0; i < this.numberOfInputChannels; ++i){
886
+ stride /= this.numberOfGridPoints;
887
+ x = this.inputTables[i][Math.round(Math.max(0, Math.min(1, components[i])) * (this.numberOfInputTableEntries - 1))];
888
+ x *= (this.numberOfGridPoints - 1);
889
+ x0 = Math.floor(x);
890
+ d = x0 * stride;
891
+ for (j = 0, l = offsets.length; j < l; ++j){
892
+ offsets[j] += d;
893
+ }
894
+ if (x > x0){
895
+ x1 = x0 + 1;
896
+ w1 = (x - x0);
897
+ w0 = 1 - w1;
898
+ for (j = 0, l = offsets.length; j < l; ++j){
899
+ offsets.push(offsets[j] + stride);
900
+ weights.push(weights[j] * w1);
901
+ weights[j] *= w0;
902
+ }
903
+ }
904
+ }
905
+ var output = [];
906
+ for (i = 0; i < this.numberOfOutputChannels; ++i){
907
+ output.push(0);
908
+ }
909
+ var offset;
910
+ for (i = 0, l = offsets.length; i < l; ++i){
911
+ offset = offsets[i];
912
+ for (j = 0; j < this.numberOfOutputChannels; ++j, offset += 2){
913
+ x = (this.lookupTableDataView.getUint16(offset) / 65535.0) * (this.numberOfOutputTableEntries - 1);
914
+ x0 = Math.floor(x);
915
+ if (x0 < x){
916
+ x1 = x0 + 1;
917
+ w1 = (x - x0);
918
+ w0 = 1 - w1;
919
+ output[j] += (this.outputTables[j][x0] * w0 + this.outputTables[j][x1] * w1) * weights[i];
920
+ }else{
921
+ output[j] += this.outputTables[j][x0] * weights[i];
922
+ }
923
+ }
924
+ }
925
+ return output;
926
+ }
927
+
928
+ });
929
+
930
+ // JSClass("IKColorProfileLookupTableAToB", IKColorProfileType, {
931
+
932
+ // type: IKColorProfile.DataType.lookupTableAToB,
933
+
934
+ // initWithData: function(data){
935
+ // IKColorProfileLookupTableAToB.$super.initWithData.call(this, data);
936
+ // var dataView = data.dataView();
937
+ // // TODO:
938
+ // },
939
+
940
+ // lookup: function(components){
941
+ // }
942
+
943
+ // });
944
+
945
+ // JSClass("IKColorProfileLookupTableBToA", IKColorProfileType, {
946
+
947
+ // type: IKColorProfile.DataType.lookupTableBToA,
948
+
949
+ // initWithData: function(data){
950
+ // IKColorProfileLookupTableBToA.$super.initWithData.call(this, data);
951
+ // var dataView = data.dataView();
952
+ // // TODO:
953
+ // },
954
+
955
+ // lookup: function(components){
956
+ // }
957
+
958
+ // });
959
+
960
+ JSClass("IKColorProfileComponentConverter", JSObject, {
961
+
962
+ connectionComponentsFromComponents: function(components){
963
+ throw new Error("unsupported component conversion");
964
+ },
965
+
966
+ componentsFromConnectionComponents: function(connectionComponents){
967
+ throw new Error("unsupported component conversion");
968
+ },
969
+
970
+ });
971
+
972
+ JSClass("IKColorProfileCurveComponentConverter", IKColorProfileComponentConverter, {
973
+
974
+ curve: null,
975
+
976
+ initWithCurve: function(curve){
977
+ this.curve = curve;
978
+ },
979
+
980
+ connectionComponentsFromComponents: function(components){
981
+ var white = this.curve(components[0]);
982
+ return [
983
+ white * JSColorSpace.Whitepoint.profileConnection[0],
984
+ white * JSColorSpace.Whitepoint.profileConnection[1],
985
+ white * JSColorSpace.Whitepoint.profileConnection[2]
986
+ ];
987
+ },
988
+
989
+ componentsFromConnectionComponents: function(xyz){
990
+ var white = Math.min(JSColorSpace.Whitepoint.profileConnection[1], Math.max(0, xyz[1])) / JSColorSpace.Whitepoint.profileConnection[1];
991
+ return [this.curve.inverse(white)];
992
+ },
993
+
994
+ });
995
+
996
+ JSClass("IKColorProfileMatrixComponentConverter", IKColorProfileComponentConverter, {
997
+
998
+ matrix: null,
999
+ inverseMatrix: null,
1000
+ curves: null,
1001
+
1002
+ initWithMatrix: function(matrix, curves){
1003
+ this.matrix = IKMatrix(matrix);
1004
+ this.curves = curves;
1005
+ this.inverseMatrix = matrix.inverse();
1006
+ },
1007
+
1008
+ connectionComponentsFromComponents: function(components){
1009
+ var rgb = [
1010
+ this.curves[0](components[0]),
1011
+ this.curves[1](components[1]),
1012
+ this.curves[2](components[2])
1013
+ ];
1014
+ return [
1015
+ this.matrix[0][0] * rgb[0] + this.matrix[0][1] * rgb[1] + this.matrix[0][2] * rgb[2],
1016
+ this.matrix[1][0] * rgb[0] + this.matrix[1][1] * rgb[1] + this.matrix[1][2] * rgb[2],
1017
+ this.matrix[2][0] * rgb[0] + this.matrix[2][1] * rgb[1] + this.matrix[2][2] * rgb[2]
1018
+ ];
1019
+ },
1020
+
1021
+ componentsFromConnectionComponents: function(xyz){
1022
+ return [
1023
+ this.curves[0].inverse(this.inverseMatrix[0][0] * xyz[0] + this.inverseMatrix[0][1] * xyz[1] + this.inverseMatrix[0][2] * xyz[2]),
1024
+ this.curves[1].inverse(this.inverseMatrix[1][0] * xyz[0] + this.inverseMatrix[1][1] * xyz[1] + this.inverseMatrix[1][2] * xyz[2]),
1025
+ this.curves[2].inverse(this.inverseMatrix[2][0] * xyz[0] + this.inverseMatrix[2][1] * xyz[1] + this.inverseMatrix[2][2] * xyz[2])
1026
+ ];
1027
+ },
1028
+
1029
+ });
1030
+
1031
+ JSClass("IKColorProfileLookupComponentConverter", IKColorProfileComponentConverter, {
1032
+
1033
+ lookupTable: null,
1034
+ inverseLookupTable: null,
1035
+ connectionSpace: null,
1036
+
1037
+ initWithLookupTables: function(lookupTable, inverseLookupTable, connectionSpace){
1038
+ this.lookupTable = lookupTable;
1039
+ this.inverseLookupTable = inverseLookupTable;
1040
+ this.connectionSpace = connectionSpace;
1041
+ },
1042
+
1043
+ connectionComponentsFromComponents: function(components){
1044
+ var connectionComponents = this.lookupTable.lookup(components);
1045
+ if (this.connectionSpace === IKColorProfile.ColorSpace.lab){
1046
+ connectionComponents = [
1047
+ connectionComponents[0] * 100.0,
1048
+ connectionComponents[1] * 256 - 128,
1049
+ connectionComponents[2] * 256 - 128
1050
+ ];
1051
+ }
1052
+ return connectionComponents;
1053
+ },
1054
+
1055
+ componentsFromConnectionComponents: function(connectionComponents){
1056
+ if (this.connectionSpace === IKColorProfile.ColorSpace.lab){
1057
+ connectionComponents = [
1058
+ connectionComponents[0] / 100.0,
1059
+ (connectionComponents[1] + 128) / 256.0,
1060
+ (connectionComponents[2] + 128) / 256.0
1061
+ ];
1062
+ }
1063
+ return this.inverseLookupTable.lookup(connectionComponents);
1064
+ },
1065
+
1066
+ });
1067
+
1068
+ var s15Fixed16 = function(i){
1069
+ var f = ((i & 0x7FFF0000) >> 16) + ((i & 0xFFFF) / 65536.0);
1070
+ if ((i & 0x80000000) != 0){
1071
+ return -f;
1072
+ }
1073
+ return f;
1074
+ };
1075
+
1076
+ var u8Fixed8 = function(i){
1077
+ return (i >> 8) + ((i & 0xFF) / 256.0);
1078
+ };
1079
+
1080
+ var XYZ32 = function(x, y, z){
1081
+ if (x == 0x0000F6D6 && y == 0x00010000 && z == 0x0000D32D){
1082
+ return JSColorSpace.Whitepoint.D50;
1083
+ }
1084
+ return [
1085
+ s15Fixed16(x),
1086
+ s15Fixed16(y),
1087
+ s15Fixed16(z)
1088
+ ];
1089
+ };
1090
+
1091
+ })();