1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- import 'dart:typed_data';
- import 'base.dart';
- /// Vid对比度处理器
- class VidContrastProcessor extends VidFrameProcessor {
- VidContrastProcessor(this.contrast) {
- _setActualContrast();
- }
- /// 对比度 [-99~99]
- final int contrast;
- late final double _actualContrast;
- void _setActualContrast() {
- double value = contrast.toDouble();
- if (value < -100) value = -100;
- if (value > 100) value = 100;
- value = (100.0 + value) / 100.0;
- value *= value;
- _actualContrast = value;
- }
- @override
- Uint8List process(Uint8List bytes, int position) {
- final i = position;
- final _contrast = _actualContrast;
- double b = bytes[i].toDouble();
- double g = bytes[i + 1].toDouble();
- double r = bytes[i + 2].toDouble();
- //process b
- b = b / 255.0;
- b -= 0.5;
- b *= _contrast;
- b += 0.5;
- b *= 255;
- if (b < 0) b = 0;
- if (b > 255) b = 255;
- //process g
- g = g / 255.0;
- g -= 0.5;
- g *= _contrast;
- g += 0.5;
- g *= 255;
- if (g < 0) g = 0;
- if (g > 255) g = 255;
- //process r
- r = r / 255.0;
- r -= 0.5;
- r *= _contrast;
- r += 0.5;
- r *= 255;
- if (r < 0) r = 0;
- if (r > 255) r = 255;
- bytes[i] = b.toInt();
- bytes[i + 1] = g.toInt();
- bytes[i + 2] = r.toInt();
- return bytes;
- }
- @override
- String toString() => 'VidContrastProcessor: $contrast';
- }
|