Переглянути джерело

fix single_frame vid load visual bug

melon.yin 2 роки тому
батько
коміт
fde175646e
5 змінених файлів з 47 додано та 280 видалено
  1. 0 42
      lib/draw.dart
  2. 0 233
      lib/img_demo.dart
  3. 0 1
      lib/main.dart
  4. 6 2
      lib/process/workspace/application.dart
  5. 41 2
      lib/vid.dart

+ 0 - 42
lib/draw.dart

@@ -1,42 +0,0 @@
-import 'package:flutter/material.dart';
-
-class DrawRecord extends StatelessWidget {
-  const DrawRecord({
-    Key? key,
-    required this.width,
-    required this.height,
-  }) : super(key: key);
-
-  final double width;
-  final double height;
-
-  @override
-  Widget build(BuildContext context) {
-    return RepaintBoundary(
-      child: CustomPaint(
-        painter: _DrawRecordPainter(),
-      ),
-    );
-  }
-}
-
-class _DrawRecordPainter extends CustomPainter {
-  final pen = Paint()
-    ..color = Colors.red
-    ..isAntiAlias = true;
-
-  @override
-  void paint(Canvas canvas, Size size) {
-    print("draw at ${DateTime.now()}");
-    canvas.drawLine(
-      Offset(100, 100),
-      Offset(200, 200),
-      pen,
-    );
-  }
-
-  @override
-  bool shouldRepaint(covariant CustomPainter oldDelegate) {
-    return false;
-  }
-}

+ 0 - 233
lib/img_demo.dart

@@ -1,233 +0,0 @@
-import 'dart:ui' as ui;
-import 'package:flutter/material.dart';
-import 'package:flutter/services.dart';
-import 'package:vid/us/vid_us_image_data.dart';
-
-class ImageDemoPage extends StatefulWidget {
-  const ImageDemoPage({Key? key}) : super(key: key);
-
-  @override
-  State<StatefulWidget> createState() => _ImageDemoPageState();
-}
-
-class _ImageDemoPageState extends State<ImageDemoPage> {
-  /// -255~255,default:0
-  int brightness = 0;
-
-  /// -99~99,default:0
-  int contrast = 0;
-
-  ui.Image? image;
-
-  @override
-  void initState() {
-    super.initState();
-    _loadImg().then((value) {
-      if (mounted) {
-        setState(() {
-          image = value;
-        });
-      }
-    });
-  }
-
-  @override
-  Widget build(BuildContext context) {
-    return Material(
-      color: Colors.green,
-      child: FutureBuilder(
-        future: _loadImg(),
-        builder: (_, snapshot) {
-          if (snapshot.connectionState == ConnectionState.done &&
-              snapshot.hasData) {
-            final image = snapshot.data! as ui.Image;
-            return Column(
-              children: [
-                RepaintBoundary(
-                  child: CustomPaint(
-                    size: ui.Size(
-                      image.width.toDouble(),
-                      image.height.toDouble(),
-                    ),
-                    painter: _MyPainter(
-                      image,
-                      brightness: brightness,
-                      contrast: contrast,
-                    ),
-                  ),
-                ),
-                const SizedBox(height: 8),
-                buildBrightnessController(),
-                const SizedBox(height: 8),
-                buildContrastController(),
-              ],
-            );
-          }
-          return const Center(
-            child: CircularProgressIndicator(),
-          );
-        },
-      ),
-    );
-  }
-
-  Widget buildBrightnessController() {
-    return Container(
-      color: Colors.white,
-      height: 50,
-      width: 280,
-      child: Row(
-        mainAxisAlignment: MainAxisAlignment.start,
-        children: [
-          IconButton(
-            onPressed: () {
-              if (brightness < -250) return;
-              setState(() {
-                brightness -= 10;
-              });
-            },
-            icon: const Icon(Icons.remove),
-          ),
-          IconButton(
-            onPressed: () {
-              if (brightness > 250) return;
-              setState(() {
-                brightness += 10;
-              });
-            },
-            icon: const Icon(Icons.add),
-          ),
-          const SizedBox(width: 10),
-          Text("Brightness: $brightness [-255~255]"),
-        ],
-      ),
-    );
-  }
-
-  Widget buildContrastController() {
-    return Container(
-      color: Colors.white,
-      height: 50,
-      width: 280,
-      child: Row(
-        mainAxisAlignment: MainAxisAlignment.start,
-        children: [
-          IconButton(
-            onPressed: () {
-              if (contrast < -90) return;
-              setState(() {
-                contrast -= 10;
-              });
-            },
-            icon: const Icon(Icons.remove),
-          ),
-          IconButton(
-            onPressed: () {
-              if (contrast > 90) return;
-              setState(() {
-                contrast += 10;
-              });
-            },
-            icon: const Icon(Icons.add),
-          ),
-          const SizedBox(width: 10),
-          Text("Contrast: $contrast (-100~100)"),
-        ],
-      ),
-    );
-  }
-
-  Future<ui.Image> _loadImg() async {
-    return await _loadJpgImg();
-    final byteData = await rootBundle.load('assets/default.VID');
-    final bytes = byteData.buffer.asUint8List();
-    final vidData = VidUsImageData(bytes);
-    final frame = vidData.getImage(0);
-    final img = await decodeImageFromList(frame.imageData);
-    return img;
-  }
-
-  Future<ui.Image> _loadJpgImg() async {
-    final byteData = await rootBundle.load('assets/test.jpg');
-    final bytes = byteData.buffer.asUint8List();
-    final img = await decodeImageFromList(bytes);
-    return img;
-  }
-
-  double _calcConstract(int val, double contrast) {
-    double pval = val / 255.0;
-    pval -= 0.5;
-    pval *= contrast;
-    pval += 0.5;
-    pval *= 255;
-    if (pval < 0) pval = 0;
-    if (pval > 255) pval = 255;
-    return pval;
-  }
-}
-
-class _MyPainter extends CustomPainter {
-  _MyPainter(
-    this.image, {
-    this.brightness = 0,
-    this.contrast = 0,
-  });
-  final ui.Image image;
-
-  final int brightness;
-  final int contrast;
-
-  // ignore: prefer_final_fields
-  ui.Paint _paint = ui.Paint()..isAntiAlias = true;
-
-  @override
-  void paint(ui.Canvas canvas, ui.Size size) {
-    // https://blog.csdn.net/hnulwt/article/details/44755025
-
-    // _paint.colorFilter = const ui.ColorFilter.matrix(<double>[
-    //   1, 0, 0, 0, 220, //
-    //   0, 1, 0, 0, 220, //
-    //   0, 0, 1, 0, 220, //
-    //   0, 0, 0, 1, 0, //
-    // ]);
-    // double lum = brightness.toDouble();
-    double scale = 1.0;
-    // if (contrast < 0) {
-    //   scale = (100 - contrast) / 100.0;
-    // } else if (contrast > 0) {
-    //   scale = contrast / 100.0 * 2.5 + 1;
-    // }
-
-    // if (contrast < 50) {
-    //   scale = contrast / 50.0;
-    // } else if (contrast > 50) {
-    //   scale = (contrast - 50) / 50.0 * 2.5 + 1;
-    // }
-    double lum = brightness.toDouble();
-
-    double contrast = this.contrast.toDouble();
-    if (contrast < -100) contrast = -100;
-    if (contrast > 100) contrast = 100;
-    contrast = (100.0 + contrast) / 100.0;
-    contrast *= contrast;
-    // print(contrast);
-    print(lum);
-    scale = contrast;
-    // scale != 1.0 ? brightness * (1.0 - scale) : brightness.toDouble();
-    // _paint.colorFilter = ui.ColorFilter.matrix(<double>[
-    //   scale, 0, 0, 0, lum, // R
-    //   0, scale, 0, 0, lum, // G
-    //   0, 0, scale, 0, lum, // B
-    //   0, 0, 0, 1, 0, // A
-    // ]);
-    _paint.colorFilter = ui.ColorFilter.mode(Colors.blue, BlendMode.darken);
-    final centerW = size.width / 2;
-    final centerH = size.height / 2;
-    canvas.translate(centerW, centerH);
-    final offset = ui.Offset(-centerW, -centerH);
-    canvas.drawImage(image, offset, _paint);
-  }
-
-  @override
-  bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
-}

+ 0 - 1
lib/main.dart

@@ -5,7 +5,6 @@ import 'package:flutter/foundation.dart';
 import 'package:flutter/material.dart';
 import 'package:get/get.dart';
 
-import 'img_demo.dart';
 import 'view/gesture/mouse_gesture.dart';
 import 'view/player/player.dart';
 import 'vid.dart';

+ 6 - 2
lib/process/workspace/application.dart

@@ -24,7 +24,7 @@ class Application implements IApplication {
   IMeasureItem? _activeItem;
   bool _canMeasure = false;
   Size _displaySize = Size.zero;
-  Set<IMeasureItem> _items = {};
+  final Set<IMeasureItem> _items = {};
 
   Application(VidUsProbe probe) {
     _probe = probe;
@@ -117,7 +117,11 @@ class Application implements IApplication {
 
   @override
   void loadFrame(VidUsImage frame) {
+    bool frameLoaded = _frame != null;
     _frame = frame;
+    if (!frameLoaded && canMeasure) {
+      _loadVisuals();
+    }
   }
 
   @override
@@ -190,7 +194,7 @@ class Application implements IApplication {
     canMeasureChanged.emit(this, canMeasure);
 
     _clearViewPorts();
-    if (canMeasure) {
+    if (canMeasure && frameData != null) {
       _loadVisuals();
     }
   }

+ 41 - 2
lib/vid.dart

@@ -15,8 +15,6 @@ import 'package:vid/us/vid_us_physical_coordinate.dart';
 import 'package:vid/us/vid_us_visual_area_type.dart';
 import 'package:vid/us/vid_us_visual_type.dart';
 
-import 'draw.dart';
-
 class Tuple<T1, T2> {
   final T1 item1;
   final T2 item2;
@@ -788,3 +786,44 @@ class VidPage extends StatelessWidget {
     return VidMeasurePlayer();
   }
 }
+
+class DrawRecord extends StatelessWidget {
+  const DrawRecord({
+    Key? key,
+    required this.width,
+    required this.height,
+  }) : super(key: key);
+
+  final double width;
+  final double height;
+
+  @override
+  Widget build(BuildContext context) {
+    return RepaintBoundary(
+      child: CustomPaint(
+        painter: _DrawRecordPainter(),
+      ),
+    );
+  }
+}
+
+class _DrawRecordPainter extends CustomPainter {
+  final pen = Paint()
+    ..color = Colors.red
+    ..isAntiAlias = true;
+
+  @override
+  void paint(Canvas canvas, Size size) {
+    print("draw at ${DateTime.now()}");
+    canvas.drawLine(
+      Offset(100, 100),
+      Offset(200, 200),
+      pen,
+    );
+  }
+
+  @override
+  bool shouldRepaint(covariant CustomPainter oldDelegate) {
+    return false;
+  }
+}