@@ -431,6 +431,24 @@ export class Image {
431
431
this . data [ ( row * this . width + column ) * this . channels + channel ] = value ;
432
432
}
433
433
434
+ /**
435
+ * Set the value of a specific pixel channel. Select pixel using coordinates.
436
+ * If the value is out of range it is set to the closest extremety.
437
+ * @param column - Column index.
438
+ * @param row - Row index.
439
+ * @param channel - Channel index.
440
+ * @param value - Value to set.
441
+ */
442
+ public setClampedValue (
443
+ column : number ,
444
+ row : number ,
445
+ channel : number ,
446
+ value : number ,
447
+ ) : void {
448
+ if ( value < 0 ) value = 0 ;
449
+ else if ( value > this . maxValue ) value = this . maxValue ;
450
+ this . data [ ( row * this . width + column ) * this . channels + channel ] = value ;
451
+ }
434
452
/**
435
453
* Get the value of a specific pixel channel. Select pixel using index.
436
454
* @param index - Index of the pixel.
@@ -450,6 +468,23 @@ export class Image {
450
468
this . data [ index * this . channels + channel ] = value ;
451
469
}
452
470
471
+ /**
472
+ * Set the value of a specific pixel channel. Select pixel using index.
473
+ * If the value is out of range it is set to the closest extremety.
474
+ * @param index - Index of the pixel.
475
+ * @param channel - Channel index.
476
+ * @param value - Value to set.
477
+ */
478
+ public setClampedValueByIndex (
479
+ index : number ,
480
+ channel : number ,
481
+ value : number ,
482
+ ) : void {
483
+ if ( value < 0 ) value = 0 ;
484
+ else if ( value > this . maxValue ) value = this . maxValue ;
485
+ this . data [ index * this . channels + channel ] = value ;
486
+ }
487
+
453
488
/**
454
489
* Get the value of a specific pixel channel. Select pixel using a point.
455
490
* @param point - Coordinates of the desired pixel.
0 commit comments