<commit_before>import 'dart:ui' as ui;

import 'package:rive/src/core/core.dart';
import 'package:rive/src/generated/shapes/image_base.dart';
import 'package:rive/src/rive_core/assets/file_asset.dart';
import 'package:rive/src/rive_core/assets/image_asset.dart';
import 'package:rive/src/rive_core/bones/skinnable.dart';
import 'package:rive/src/rive_core/component.dart';
import 'package:rive/src/rive_core/math/aabb.dart';
import 'package:rive/src/rive_core/math/mat2d.dart';
import 'package:rive/src/rive_core/shapes/mesh.dart';
import 'package:rive/src/rive_core/shapes/mesh_vertex.dart';

export 'package:rive/src/generated/shapes/image_base.dart';

class Image extends ImageBase
    with FileAssetReferencer<ImageAsset>, SkinnableProvider<MeshVertex> {
  ui.Image? get image => asset?.image;
  Mesh? _mesh;
  Mesh? get mesh => _mesh;
  bool get hasMesh => _mesh != null;

  AABB get localBounds {
    if (hasMesh && _mesh!.draws) {
      return _mesh!.bounds;
    }
    if (asset == null) {
      return AABB.empty();
    }
    final halfWidth = asset!.width / 2;
    final halfHeight = asset!.height / 2;
    return AABB.fromValues(-halfWidth, -halfHeight, halfWidth, halfHeight);
  }

  @override
  void assetIdChanged(int from, int to) {}

  @override
  void draw(ui.Canvas canvas) {
    final uiImage = asset?.image;
    if (uiImage == null) {
      print('No image yet?! ${asset?.name} $uiImage');
      return;
    }
    bool clipped = clip(canvas);

    final paint = ui.Paint()..color = ui.Color.fromRGBO(0, 0, 0, renderOpacity);

    final width = asset!.width;
    final height = asset!.height;

    canvas.save();
    canvas.transform(renderTransform.mat4);
    if (_mesh == null || !_mesh!.draws) {
      canvas.drawImage(uiImage, ui.Offset(-width / 2, -height / 2), paint);
    } else {
      paint.shader = ui.ImageShader(
          uiImage,
          ui.TileMode.clamp,
          ui.TileMode.clamp,
          Float64List.fromList(<double>[
            1 / width,
            0.0,
            0.0,
            0.0,
            0.0,
            1 / height,
            0.0,<commit_msg>Remove print<commit_after>import 'dart:ui' as ui;

import 'package:rive/src/core/core.dart';
import 'package:rive/src/generated/shapes/image_base.dart';
import 'package:rive/src/rive_core/assets/file_asset.dart';
import 'package:rive/src/rive_core/assets/image_asset.dart';
import 'package:rive/src/rive_core/bones/skinnable.dart';
import 'package:rive/src/rive_core/component.dart';
import 'package:rive/src/rive_core/math/aabb.dart';
import 'package:rive/src/rive_core/math/mat2d.dart';
import 'package:rive/src/rive_core/shapes/mesh.dart';
import 'package:rive/src/rive_core/shapes/mesh_vertex.dart';

export 'package:rive/src/generated/shapes/image_base.dart';

class Image extends ImageBase
    with FileAssetReferencer<ImageAsset>, SkinnableProvider<MeshVertex> {
  ui.Image? get image => asset?.image;
  Mesh? _mesh;
  Mesh? get mesh => _mesh;
  bool get hasMesh => _mesh != null;

  AABB get localBounds {
    if (hasMesh && _mesh!.draws) {
      return _mesh!.bounds;
    }
    if (asset == null) {
      return AABB.empty();
    }
    final halfWidth = asset!.width / 2;
    final halfHeight = asset!.height / 2;
    return AABB.fromValues(-halfWidth, -halfHeight, halfWidth, halfHeight);
  }

  @override
  void assetIdChanged(int from, int to) {}

  @override
  void draw(ui.Canvas canvas) {
    final uiImage = asset?.image;
    if (uiImage == null) {
      return;
    }
    bool clipped = clip(canvas);

    final paint = ui.Paint()..color = ui.Color.fromRGBO(0, 0, 0, renderOpacity);

    final width = asset!.width;
    final height = asset!.height;

    canvas.save();
    canvas.transform(renderTransform.mat4);
    if (_mesh == null || !_mesh!.draws) {
      canvas.drawImage(uiImage, ui.Offset(-width / 2, -height / 2), paint);
    } else {
      paint.shader = ui.ImageShader(
          uiImage,
          ui.TileMode.clamp,
          ui.TileMode.clamp,
          Float64List.fromList(<double>[
            1 / width,
            0.0,
            0.0,
            0.0,
            0.0,
            1 / height,
            0.0,
{'fraction_non_alphanumeric': 0.1399325626204239, 'fraction_numerical': 0.011078998073217727, 'mean_word_length': 2.8740671641791047, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '652260', 'n_tokens_mistral': 1459, 'n_tokens_neox': 1410, 'n_words': 275}