@@ -20,65 +20,18 @@ export class ParsedColor {
20
20
}
21
21
}
22
22
23
- /**
24
- * Represents a color rendered on top of the background at all possible alpha values.
25
- */
26
- export class MinimapColor {
27
-
28
- /**
29
- * For each 0 <= i <= 255:
30
- * data[3*i + 0] = r
31
- * data[3*i + 1] = g;
32
- * data[3*i + 2] = b;
33
- */
34
- public readonly data : Uint8ClampedArray ;
35
-
36
- constructor ( data : Uint8ClampedArray ) {
37
- this . data = data ;
38
- }
39
- }
40
-
41
23
export class MinimapColors {
42
24
43
- private readonly _backgroundColor : ParsedColor ;
44
- private readonly _colors : MinimapColor [ ] ;
25
+ private readonly _colors : ParsedColor [ ] ;
45
26
46
27
constructor ( colorMap : string [ ] ) {
47
- this . _backgroundColor = MinimapColors . _parseColor ( colorMap [ ColorId . DefaultBackground ] ) ;
48
- let backgroundR = this . _backgroundColor . r ;
49
- let backgroundG = this . _backgroundColor . g ;
50
- let backgroundB = this . _backgroundColor . b ;
51
-
52
28
this . _colors = [ null ] ;
53
29
for ( let colorId = 1 ; colorId < colorMap . length ; colorId ++ ) {
54
- let color = MinimapColors . _parseColor ( colorMap [ colorId ] ) ;
55
- let colorR = color . r ;
56
- let colorG = color . g ;
57
- let colorB = color . b ;
58
-
59
- let result = new Uint8ClampedArray ( 256 * 3 ) , resultOffset = 0 ;
60
- for ( let alpha = 0 ; alpha <= 255 ; alpha ++ ) {
61
- let fAlpha = alpha / 255 ;
62
- let fAlphaInverse = ( 255 - alpha ) / 255 ;
63
-
64
- let r = ( colorR * fAlpha ) + ( backgroundR * fAlphaInverse ) ;
65
- let g = ( colorG * fAlpha ) + ( backgroundG * fAlphaInverse ) ;
66
- let b = ( colorB * fAlpha ) + ( backgroundB * fAlphaInverse ) ;
67
-
68
- result [ resultOffset ++ ] = r ;
69
- result [ resultOffset ++ ] = g ;
70
- result [ resultOffset ++ ] = b ;
71
- }
72
-
73
- this . _colors [ colorId ] = new MinimapColor ( result ) ;
30
+ this . _colors [ colorId ] = MinimapColors . _parseColor ( colorMap [ colorId ] ) ;
74
31
}
75
32
}
76
33
77
- public getBackgroundColor ( ) : ParsedColor {
78
- return this . _backgroundColor ;
79
- }
80
-
81
- public getMinimapColor ( colorId : ColorId ) : MinimapColor {
34
+ public getColor ( colorId : ColorId ) : ParsedColor {
82
35
if ( colorId < 1 || colorId >= this . _colors . length ) {
83
36
// background color (basically invisible)
84
37
colorId = 2 ;
@@ -243,59 +196,77 @@ export class MinimapCharRenderer2 {
243
196
return chCode - Constants . START_CH_CODE ;
244
197
}
245
198
246
- public x2RenderChar ( target : ImageData , dx : number , dy : number , chCode : number , _color : MinimapColor ) : void {
199
+ public x2RenderChar ( target : ImageData , dx : number , dy : number , chCode : number , color : ParsedColor , backgroundColor : ParsedColor ) : void {
247
200
const x2CharData = this . x2charData ;
248
201
const chIndex = MinimapCharRenderer2 . _getChIndex ( chCode ) ;
249
- const sourceOffset = chIndex * Constants . x2_CHAR_HEIGHT * Constants . x2_CHAR_WIDTH ;
250
- const c1 = x2CharData [ sourceOffset ] ;
251
- const c2 = x2CharData [ sourceOffset + 1 ] ;
252
- const c3 = x2CharData [ sourceOffset + 2 ] ;
253
- const c4 = x2CharData [ sourceOffset + 3 ] ;
254
- const c5 = x2CharData [ sourceOffset + 4 ] ;
255
- const c6 = x2CharData [ sourceOffset + 5 ] ;
256
- const c7 = x2CharData [ sourceOffset + 6 ] ;
257
- const c8 = x2CharData [ sourceOffset + 7 ] ;
258
202
259
203
const outWidth = target . width * Constants . RGBA_CHANNELS_CNT ;
260
- let resultOffset = dy * outWidth + dx * Constants . RGBA_CHANNELS_CNT ;
204
+
205
+ const backgroundR = backgroundColor . r ;
206
+ const backgroundG = backgroundColor . g ;
207
+ const backgroundB = backgroundColor . b ;
208
+
209
+ const deltaR = color . r - backgroundR ;
210
+ const deltaG = color . g - backgroundG ;
211
+ const deltaB = color . b - backgroundB ;
261
212
262
213
const dest = target . data ;
263
- const color = _color . data ;
264
- dest [ resultOffset + 0 ] = color [ 3 * c1 + 0 ] ;
265
- dest [ resultOffset + 1 ] = color [ 3 * c1 + 1 ] ;
266
- dest [ resultOffset + 2 ] = color [ 3 * c1 + 2 ] ;
267
- dest [ resultOffset + 3 ] = 255 ;
268
- dest [ resultOffset + 4 ] = color [ 3 * c2 + 0 ] ;
269
- dest [ resultOffset + 5 ] = color [ 3 * c2 + 1 ] ;
270
- dest [ resultOffset + 6 ] = color [ 3 * c2 + 2 ] ;
271
- dest [ resultOffset + 7 ] = 255 ;
272
- resultOffset += outWidth ;
273
- dest [ resultOffset + 0 ] = color [ 3 * c3 + 0 ] ;
274
- dest [ resultOffset + 1 ] = color [ 3 * c3 + 1 ] ;
275
- dest [ resultOffset + 2 ] = color [ 3 * c3 + 2 ] ;
276
- dest [ resultOffset + 3 ] = 255 ;
277
- dest [ resultOffset + 4 ] = color [ 3 * c4 + 0 ] ;
278
- dest [ resultOffset + 5 ] = color [ 3 * c4 + 1 ] ;
279
- dest [ resultOffset + 6 ] = color [ 3 * c4 + 2 ] ;
280
- dest [ resultOffset + 7 ] = 255 ;
281
- resultOffset += outWidth ;
282
- dest [ resultOffset + 0 ] = color [ 3 * c5 + 0 ] ;
283
- dest [ resultOffset + 1 ] = color [ 3 * c5 + 1 ] ;
284
- dest [ resultOffset + 2 ] = color [ 3 * c5 + 2 ] ;
285
- dest [ resultOffset + 3 ] = 255 ;
286
- dest [ resultOffset + 4 ] = color [ 3 * c6 + 0 ] ;
287
- dest [ resultOffset + 5 ] = color [ 3 * c6 + 1 ] ;
288
- dest [ resultOffset + 6 ] = color [ 3 * c6 + 2 ] ;
289
- dest [ resultOffset + 7 ] = 255 ;
290
- resultOffset += outWidth ;
291
- dest [ resultOffset + 0 ] = color [ 3 * c7 + 0 ] ;
292
- dest [ resultOffset + 1 ] = color [ 3 * c7 + 1 ] ;
293
- dest [ resultOffset + 2 ] = color [ 3 * c7 + 2 ] ;
294
- dest [ resultOffset + 3 ] = 255 ;
295
- dest [ resultOffset + 4 ] = color [ 3 * c8 + 0 ] ;
296
- dest [ resultOffset + 5 ] = color [ 3 * c8 + 1 ] ;
297
- dest [ resultOffset + 6 ] = color [ 3 * c8 + 2 ] ;
298
- dest [ resultOffset + 7 ] = 255 ;
214
+ const sourceOffset = chIndex * Constants . x2_CHAR_HEIGHT * Constants . x2_CHAR_WIDTH ;
215
+ let destOffset = dy * outWidth + dx * Constants . RGBA_CHANNELS_CNT ;
216
+ {
217
+ const c = x2CharData [ sourceOffset ] / 255 ;
218
+ dest [ destOffset + 0 ] = backgroundR + deltaR * c ;
219
+ dest [ destOffset + 1 ] = backgroundG + deltaG * c ;
220
+ dest [ destOffset + 2 ] = backgroundB + deltaB * c ;
221
+ }
222
+ {
223
+ const c = x2CharData [ sourceOffset + 1 ] / 255 ;
224
+ dest [ destOffset + 4 ] = backgroundR + deltaR * c ;
225
+ dest [ destOffset + 5 ] = backgroundG + deltaG * c ;
226
+ dest [ destOffset + 6 ] = backgroundB + deltaB * c ;
227
+ }
228
+
229
+ destOffset += outWidth ;
230
+ {
231
+ const c = x2CharData [ sourceOffset + 2 ] / 255 ;
232
+ dest [ destOffset + 0 ] = backgroundR + deltaR * c ;
233
+ dest [ destOffset + 1 ] = backgroundG + deltaG * c ;
234
+ dest [ destOffset + 2 ] = backgroundB + deltaB * c ;
235
+ }
236
+ {
237
+ const c = x2CharData [ sourceOffset + 3 ] / 255 ;
238
+ dest [ destOffset + 4 ] = backgroundR + deltaR * c ;
239
+ dest [ destOffset + 5 ] = backgroundG + deltaG * c ;
240
+ dest [ destOffset + 6 ] = backgroundB + deltaB * c ;
241
+ }
242
+
243
+ destOffset += outWidth ;
244
+ {
245
+ const c = x2CharData [ sourceOffset + 4 ] / 255 ;
246
+ dest [ destOffset + 0 ] = backgroundR + deltaR * c ;
247
+ dest [ destOffset + 1 ] = backgroundG + deltaG * c ;
248
+ dest [ destOffset + 2 ] = backgroundB + deltaB * c ;
249
+ }
250
+ {
251
+ const c = x2CharData [ sourceOffset + 5 ] / 255 ;
252
+ dest [ destOffset + 4 ] = backgroundR + deltaR * c ;
253
+ dest [ destOffset + 5 ] = backgroundG + deltaG * c ;
254
+ dest [ destOffset + 6 ] = backgroundB + deltaB * c ;
255
+ }
256
+
257
+ destOffset += outWidth ;
258
+ {
259
+ const c = x2CharData [ sourceOffset + 6 ] / 255 ;
260
+ dest [ destOffset + 0 ] = backgroundR + deltaR * c ;
261
+ dest [ destOffset + 1 ] = backgroundG + deltaG * c ;
262
+ dest [ destOffset + 2 ] = backgroundB + deltaB * c ;
263
+ }
264
+ {
265
+ const c = x2CharData [ sourceOffset + 7 ] / 255 ;
266
+ dest [ destOffset + 4 ] = backgroundR + deltaR * c ;
267
+ dest [ destOffset + 5 ] = backgroundG + deltaG * c ;
268
+ dest [ destOffset + 6 ] = backgroundB + deltaB * c ;
269
+ }
299
270
}
300
271
301
272
public x1RenderChar ( target : ImageData , dx : number , dy : number , chCode : number ) : void {
0 commit comments