chromium/components/qr_code_generator/bitmap_generator.cc

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "components/qr_code_generator/bitmap_generator.h"

#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
#include "base/types/expected.h"
#include "build/build_config.h"
#include "components/qr_code_generator/dino_image.h"
#include "components/qr_code_generator/qr_code_generator.h"
#include "components/vector_icons/vector_icons.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/skia_conversions.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/image/image_skia_rep_default.h"
#include "ui/gfx/paint_vector_icon.h"

namespace qr_code_generator {

namespace {

// Allow each element to render as this many pixels.
static const int kModuleSizePixels =;

// Allow each dino tile to render as this many pixels.
static const int kDinoTileSizePixels =;

// Size of a QR locator, in modules.
static const int kLocatorSizeModules =;

SkBitmap CreateDinoBitmap() {}

void PaintCenterImage(SkCanvas* canvas,
                      const SkRect& canvas_bounds,
                      const int width_px,
                      const int height_px,
                      const int border_px,
                      const SkPaint& paint_background,
                      const SkBitmap& image);

// `gfx::CreateVectorIcon` is not available on iOS.
#if !BUILDFLAG(IS_IOS)
void DrawPasskeyIcon(SkCanvas* canvas,
                     const SkRect& canvas_bounds,
                     const SkPaint& paint_foreground,
                     const SkPaint& paint_background) {}

void DrawProductIcon(SkCanvas* canvas,
                     const SkRect& canvas_bounds,
                     const SkPaint& paint_foreground,
                     const SkPaint& paint_background) {}
#endif

void DrawDino(SkCanvas* canvas,
              const SkRect& canvas_bounds,
              const int pixels_per_dino_tile,
              const int dino_border_px,
              const SkPaint& paint_foreground,
              const SkPaint& paint_background) {}

void PaintCenterImage(SkCanvas* canvas,
                      const SkRect& canvas_bounds,
                      const int width_px,
                      const int height_px,
                      const int border_px,
                      const SkPaint& paint_background,
                      const SkBitmap& image) {}

// Draws QR locators at three corners of |canvas|.
void DrawLocators(SkCanvas* canvas,
                  const gfx::Size data_size,
                  const SkPaint& paint_foreground,
                  const SkPaint& paint_background,
                  LocatorStyle style,
                  int margin) {}

int CalculateMargin(QuietZone quiet_zone) {}

SkBitmap RenderBitmap(base::span<const uint8_t> data,
                      const gfx::Size data_size,
                      ModuleStyle module_style,
                      LocatorStyle locator_style,
                      CenterImage center_image,
                      QuietZone quiet_zone) {}

}  // namespace

const int kQuietZoneSizePixels =;

base::expected<gfx::ImageSkia, Error> GenerateImage(
    base::span<const uint8_t> data,
    ModuleStyle module_style,
    LocatorStyle locator_style,
    CenterImage center_image,
    QuietZone quiet_zone) {}

base::expected<SkBitmap, Error> GenerateBitmap(base::span<const uint8_t> data,
                                               ModuleStyle module_style,
                                               LocatorStyle locator_style,
                                               CenterImage center_image,
                                               QuietZone quiet_zone) {}

}  // namespace qr_code_generator