chromium/chromeos/services/machine_learning/public/mojom/document_scanner.mojom

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Next MinVersion: 2

// Datatypes and interfaces of document scanner API.

// NOTE: This mojom exists in two places and must be kept in sync:
//       Chromium:  //chromeos/services/machine_learning/public/mojom/
//       Chrome OS: src/platform2/ml/mojom/
//       Note: Other repos downstream of Chromium might also use this mojom.
// Example: A backwards-compatible mojom change (and corresponding
// implementation change) can be made in Chrome OS first, then replicated to the
// clients (Chromium, other downstream repos) later.
// Use //chromeos/services/machine_learning/public/mojom/roll_mojoms.sh to help
// replicate Chrome OS-side changes over to Chromium.

module chromeos.machine_learning.mojom;

import "chromeos/services/machine_learning/public/mojom/document_scanner_param_types.mojom";
import "mojo/public/mojom/base/file_path.mojom";
import "ui/gfx/geometry/mojom/geometry.mojom";
import "mojo/public/mojom/base/shared_memory.mojom";

// Status of the document scanner response.
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
// Keep this enum in sync with MachineLearningServiceDocumentScannerResultEvent
// in tools/metrics/histograms/metadata/cros_ml/enums.xml.
[Stable, Extensible]
enum DocumentScannerResultStatus {
  OK = 0,
  ERROR = 1,
};

// The configuration for document scanner.
// Next min field ID: 2
[Stable]
struct DocumentScannerConfig {
  string deprecated_library_dlc_path@0;

  // Path to already-installed DocumentScanner library.
  [MinVersion=1] mojo_base.mojom.FilePath? library_dlc_path@1;
};

// The corner detection response.
// Next min field ID: 2
[Stable]
struct DetectCornersResult {
  // Status of the result. Even when there is no corners detected, the detection
  // can still be considered successful if there is no error occurs.
  DocumentScannerResultStatus status@0;

  // Detected document corners.
  array<gfx.mojom.PointF> corners@1;
};

// The post processing response.
// Next min field ID: 2
[Stable]
struct DoPostProcessingResult {
  // Status of the result.
  DocumentScannerResultStatus status@0;

  // Image data after processing. Will be in JPG format.
  array<uint8> processed_jpeg_image@1;
};

// The mojom interface for performing document scanning.
// Next ordinal: 3
[Stable]
interface DocumentScanner {
  // Detect document corners for given `nv12_image` which is in 256x256 size.
  DetectCornersFromNV12Image@0(
      mojo_base.mojom.ReadOnlySharedMemoryRegion nv12_image)
      => (DetectCornersResult result);

  // Detect document corners for given `jpeg_image`.
  DetectCornersFromJPEGImage@1(
      mojo_base.mojom.ReadOnlySharedMemoryRegion jpeg_image)
      => (DetectCornersResult result);

  // Do post processing such as rectification for the document region, contrast
  // enhancement on the given `jpeg_image` according to document `corners`,
  // clockwise rotation in `rotation` degrees.
  DoPostProcessing@2(mojo_base.mojom.ReadOnlySharedMemoryRegion jpeg_image,
                     array<gfx.mojom.PointF> corners,
                     [MinVersion=1] Rotation rotation)
      => (DoPostProcessingResult result);
};