chromium/pdf/ui/thumbnail.cc

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

#include "pdf/ui/thumbnail.h"

#include <stddef.h>

#include <algorithm>
#include <cmath>
#include <utility>

#include "base/check.h"
#include "base/check_op.h"
#include "base/numerics/checked_math.h"
#include "base/values.h"
#include "ui/gfx/geometry/size.h"

namespace chrome_pdf {

namespace {

constexpr float kMinDevicePixelRatio =;
constexpr float kMaxDevicePixelRatio =;

constexpr int kImageColorChannels =;

// TODO(crbug.com/40511452): Reevaluate the thumbnail size cap when the PDF
// component migrates off of PPAPI.
// The maximum thumbnail area is essentially arbitrary, but the value was chosen
// considering the fact that when sending array buffers through PPAPI, if the
// size of the data is over 256KiB, it gets sent using shared memory instead of
// IPC. Thumbnail sizes are capped at 255KiB to avoid the 256KiB threshold for
// images and their metadata, such as size.
constexpr int kMaxThumbnailPixels =;

// Maximum CSS dimensions are set to match UX specifications.
// These constants should be kept in sync with `PORTRAIT_WIDTH` and
// `LANDSCAPE_WIDTH` in
// chrome/browser/resources/pdf/elements/viewer-thumbnail.ts.
constexpr int kMaxWidthPortraitPx =;
constexpr int kMaxWidthLandscapePx =;

// PDF page size limits in default user space units, as defined by PDF 1.7 Annex
// C.2, "Architectural limits".
constexpr int kPdfPageMinDimension =;
constexpr int kPdfPageMaxDimension =;
constexpr int kPdfMaxAspectRatio =;

// Limit the proportions within PDF limits to handle pathological PDF pages.
gfx::Size LimitAspectRatio(gfx::Size page_size) {}

// Calculate the size of a thumbnail image in device pixels using `page_size` in
// any units and `device_pixel_ratio`.
gfx::Size CalculateBestFitSize(const gfx::Size& page_size,
                               float device_pixel_ratio) {}

int CalculateStride(int width) {}

size_t CalculateImageDataSize(int stride, int height) {}

}  // namespace

Thumbnail::Thumbnail(const gfx::Size& page_size, float device_pixel_ratio)
    :{}

Thumbnail::Thumbnail(Thumbnail&& other) noexcept = default;

Thumbnail& Thumbnail::operator=(Thumbnail&& other) noexcept = default;

Thumbnail::~Thumbnail() = default;

base::Value::BlobStorage& Thumbnail::GetImageData() {}

base::Value::BlobStorage Thumbnail::TakeData() {}

}  // namespace chrome_pdf