chromium/ui/gfx/image/image.cc

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

#include "ui/gfx/image/image.h"

#include <algorithm>
#include <map>
#include <ostream>
#include <utility>
#include <vector>

#include "base/check_op.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted_memory.h"
#include "base/notreached.h"
#include "build/build_config.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/image/image_internal.h"
#include "ui/gfx/image/image_platform.h"
#include "ui/gfx/image/image_png_rep.h"
#include "ui/gfx/image/image_skia.h"

#if BUILDFLAG(IS_IOS)
#include "base/apple/foundation_util.h"
#include "ui/gfx/image/image_skia_util_ios.h"
#elif BUILDFLAG(IS_MAC)
#include "base/apple/foundation_util.h"
#include "base/mac/mac_util.h"
#include "ui/gfx/image/image_skia_util_mac.h"
#endif

namespace gfx {

namespace internal {

ImageRep::ImageRep(Image::RepresentationType rep) :{}

ImageRep::~ImageRep() = default;

const ImageRepPNG* ImageRep::AsImageRepPNG() const {}
ImageRepPNG* ImageRep::AsImageRepPNG() {}

const ImageRepSkia* ImageRep::AsImageRepSkia() const {}
ImageRepSkia* ImageRep::AsImageRepSkia() {}

class ImageRepPNG final : public ImageRep {};

class ImageRepSkia final : public ImageRep {};

ImageStorage::ImageStorage(Image::RepresentationType default_type)
    :{}

ImageStorage::~ImageStorage() = default;

Image::RepresentationType ImageStorage::default_representation_type() const {}

bool ImageStorage::HasRepresentation(Image::RepresentationType type) const {}

size_t ImageStorage::RepresentationCount() const {}

const ImageRep* ImageStorage::GetRepresentation(
    Image::RepresentationType rep_type,
    bool must_exist) const {}

const ImageRep* ImageStorage::AddRepresentation(
    std::unique_ptr<ImageRep> rep) const {}

}  // namespace internal

  // |storage_| is null for empty Images.
Image::Image() = default;

Image::Image(const std::vector<ImagePNGRep>& image_reps) {}

Image::Image(const ImageSkia& image) {}

Image::Image(const Image& other) = default;

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

Image& Image::operator=(const Image& other) = default;

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

Image::~Image() = default;

bool Image::operator==(const Image& other) const {}

// static
Image Image::CreateFrom1xBitmap(const SkBitmap& bitmap) {}

// static
Image Image::CreateFrom1xPNGBytes(base::span<const uint8_t> input) {}

Image Image::CreateFrom1xPNGBytes(
    const scoped_refptr<base::RefCountedMemory>& input) {}

const SkBitmap* Image::ToSkBitmap() const {}

const ImageSkia* Image::ToImageSkia() const {}

#if BUILDFLAG(IS_IOS)
UIImage* Image::ToUIImage() const {
  const internal::ImageRep* rep = GetRepresentation(kImageRepCocoaTouch, false);
  if (!rep) {
    std::unique_ptr<internal::ImageRep> scoped_rep;
    switch (DefaultRepresentationType()) {
      case kImageRepPNG: {
        const internal::ImageRepPNG* png_rep =
            GetRepresentation(kImageRepPNG, true)->AsImageRepPNG();
        scoped_rep = internal::MakeImageRepCocoaTouch(
            internal::UIImageFromPNG(png_rep->image_reps()));
        break;
      }
      case kImageRepSkia: {
        const internal::ImageRepSkia* skia_rep =
            GetRepresentation(kImageRepSkia, true)->AsImageRepSkia();
        UIImage* image = UIImageFromImageSkia(*skia_rep->image());
        scoped_rep = internal::MakeImageRepCocoaTouch(image);
        break;
      }
      default:
        NOTREACHED_IN_MIGRATION();
    }
    CHECK(scoped_rep);
    rep = AddRepresentation(std::move(scoped_rep));
  }
  return UIImageOfImageRepCocoaTouch(rep->AsImageRepCocoaTouch());
}
#elif BUILDFLAG(IS_MAC)
NSImage* Image::ToNSImage() const {
  const internal::ImageRep* rep = GetRepresentation(kImageRepCocoa, false);
  if (!rep) {
    std::unique_ptr<internal::ImageRep> scoped_rep;

    switch (DefaultRepresentationType()) {
      case kImageRepPNG: {
        const internal::ImageRepPNG* png_rep =
            GetRepresentation(kImageRepPNG, true)->AsImageRepPNG();
        scoped_rep = internal::MakeImageRepCocoa(
            internal::NSImageFromPNG(png_rep->image_reps()));
        break;
      }
      case kImageRepSkia: {
        const internal::ImageRepSkia* skia_rep =
            GetRepresentation(kImageRepSkia, true)->AsImageRepSkia();
        NSImage* image = NSImageFromImageSkia(*skia_rep->image());
        scoped_rep = internal::MakeImageRepCocoa(image);
        break;
      }
      default:
        NOTREACHED_IN_MIGRATION();
    }
    CHECK(scoped_rep);
    rep = AddRepresentation(std::move(scoped_rep));
  }
  return NSImageOfImageRepCocoa(rep->AsImageRepCocoa());
}
#endif

scoped_refptr<base::RefCountedMemory> Image::As1xPNGBytes() const {}

SkBitmap Image::AsBitmap() const {}

ImageSkia Image::AsImageSkia() const {}

#if BUILDFLAG(IS_MAC)
NSImage* Image::AsNSImage() const {
  return IsEmpty() ? nil : ToNSImage();
}
#endif

bool Image::HasRepresentation(RepresentationType type) const {}

size_t Image::RepresentationCount() const {}

bool Image::IsEmpty() const {}

int Image::Width() const {}

int Image::Height() const {}

gfx::Size Image::Size() const {}

Image::RepresentationType Image::DefaultRepresentationType() const {}

const internal::ImageRep* Image::GetRepresentation(RepresentationType rep_type,
                                                   bool must_exist) const {}

const internal::ImageRep* Image::AddRepresentation(
    std::unique_ptr<internal::ImageRep> rep) const {}

}  // namespace gfx