<commit_before>// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
import 'dart:ui' show Image, ImageDecoder, ImageDecoderCallback;
import 'dart:typed_data';

import 'package:mojo/core.dart' show MojoDataPipeConsumer;

final Set<ImageDecoder> _activeDecoders = new Set<ImageDecoder>();

typedef ImageDecoder _DecoderFactory(ImageDecoderCallback callback);

Future<Image> _decode(_DecoderFactory createDecoder) {
  Completer<Image> completer = new Completer<Image>();
  ImageDecoder decoder;
  decoder = createDecoder((Image image) {
    _activeDecoders.remove(decoder);
    completer.complete(image);
  });
  _activeDecoders.add(decoder);
  return completer.future;
}

Future<Image> decodeImageFromDataPipe(MojoDataPipeConsumer consumerHandle) {
  return _decode((ImageDecoderCallback callback) => new ImageDecoder.consume(consumerHandle.handle.h, callback));
}

Future<Image> decodeImageFromList(Uint8List list) {
  return _decode((ImageDecoderCallback callback) => new ImageDecoder.fromList(list, callback));
}<commit_msg>simplify the ImageDecoder native code binding<commit_after>// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
import 'dart:typed_data';
import 'dart:ui' as ui;

import 'package:mojo/core.dart' show MojoDataPipeConsumer;

Future<ui.Image> decodeImageFromDataPipe(MojoDataPipeConsumer consumerHandle) {
  Completer<ui.Image> completer = new Completer<ui.Image>();
  ui.decodeImageFromDataPipe(consumerHandle.handle.h, (ui.Image image) {
    completer.complete(image);
  });
  return completer.future;
}

Future<ui.Image> decodeImageFromList(Uint8List list) {
  Completer<ui.Image> completer = new Completer<ui.Image>();
  ui.decodeImageFromList(list, (ui.Image image) {
    completer.complete(image);
  });
  return completer.future;
}
{'fraction_non_alphanumeric': 0.10650887573964497, 'fraction_numerical': 0.004930966469428008, 'mean_word_length': 5.996551724137931, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 18, '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': '4148413', 'n_tokens_mistral': 641, 'n_tokens_neox': 617, 'n_words': 157}