gecko-dev/image/ImageRegion.h

174 строки
4.5 KiB
C
Исходник Обычный вид История

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Bug 1038536 - Flatten image/src/ directory. r=seth --HG-- rename : image/src/BMPFileHeaders.h => image/BMPFileHeaders.h rename : image/src/ClippedImage.cpp => image/ClippedImage.cpp rename : image/src/ClippedImage.h => image/ClippedImage.h rename : image/src/DecodePool.cpp => image/DecodePool.cpp rename : image/src/DecodePool.h => image/DecodePool.h rename : image/src/Decoder.cpp => image/Decoder.cpp rename : image/src/Decoder.h => image/Decoder.h rename : image/src/Downscaler.cpp => image/Downscaler.cpp rename : image/src/Downscaler.h => image/Downscaler.h rename : image/src/DynamicImage.cpp => image/DynamicImage.cpp rename : image/src/DynamicImage.h => image/DynamicImage.h rename : image/src/FrameAnimator.cpp => image/FrameAnimator.cpp rename : image/src/FrameAnimator.h => image/FrameAnimator.h rename : image/src/FrozenImage.cpp => image/FrozenImage.cpp rename : image/src/FrozenImage.h => image/FrozenImage.h rename : image/src/ICOFileHeaders.h => image/ICOFileHeaders.h rename : image/src/IProgressObserver.h => image/IProgressObserver.h rename : image/src/Image.cpp => image/Image.cpp rename : image/src/Image.h => image/Image.h rename : image/src/ImageFactory.cpp => image/ImageFactory.cpp rename : image/src/ImageFactory.h => image/ImageFactory.h rename : image/src/ImageMetadata.cpp => image/ImageMetadata.cpp rename : image/src/ImageMetadata.h => image/ImageMetadata.h rename : image/src/ImageOps.cpp => image/ImageOps.cpp rename : image/src/ImageOps.h => image/ImageOps.h rename : image/src/ImageRegion.h => image/ImageRegion.h rename : image/src/ImageURL.h => image/ImageURL.h rename : image/src/ImageWrapper.cpp => image/ImageWrapper.cpp rename : image/src/ImageWrapper.h => image/ImageWrapper.h rename : image/src/MultipartImage.cpp => image/MultipartImage.cpp rename : image/src/MultipartImage.h => image/MultipartImage.h rename : image/src/Orientation.h => image/Orientation.h rename : image/src/OrientedImage.cpp => image/OrientedImage.cpp rename : image/src/OrientedImage.h => image/OrientedImage.h rename : image/src/ProgressTracker.cpp => image/ProgressTracker.cpp rename : image/src/ProgressTracker.h => image/ProgressTracker.h rename : image/src/RasterImage.cpp => image/RasterImage.cpp rename : image/src/RasterImage.h => image/RasterImage.h rename : image/src/SVGDocumentWrapper.cpp => image/SVGDocumentWrapper.cpp rename : image/src/SVGDocumentWrapper.h => image/SVGDocumentWrapper.h rename : image/src/ScriptedNotificationObserver.cpp => image/ScriptedNotificationObserver.cpp rename : image/src/ScriptedNotificationObserver.h => image/ScriptedNotificationObserver.h rename : image/src/ShutdownTracker.cpp => image/ShutdownTracker.cpp rename : image/src/ShutdownTracker.h => image/ShutdownTracker.h rename : image/src/SourceBuffer.cpp => image/SourceBuffer.cpp rename : image/src/SourceBuffer.h => image/SourceBuffer.h rename : image/src/SurfaceCache.cpp => image/SurfaceCache.cpp rename : image/src/SurfaceCache.h => image/SurfaceCache.h rename : image/src/VectorImage.cpp => image/VectorImage.cpp rename : image/src/VectorImage.h => image/VectorImage.h rename : image/src/imgFrame.cpp => image/imgFrame.cpp rename : image/src/imgFrame.h => image/imgFrame.h rename : image/src/imgLoader.cpp => image/imgLoader.cpp rename : image/src/imgLoader.h => image/imgLoader.h rename : image/src/imgRequest.cpp => image/imgRequest.cpp rename : image/src/imgRequest.h => image/imgRequest.h rename : image/src/imgRequestProxy.cpp => image/imgRequestProxy.cpp rename : image/src/imgRequestProxy.h => image/imgRequestProxy.h rename : image/src/imgTools.cpp => image/imgTools.cpp rename : image/src/imgTools.h => image/imgTools.h
2015-05-15 06:52:05 +03:00
#ifndef mozilla_image_ImageRegion_h
#define mozilla_image_ImageRegion_h
#include "gfxRect.h"
#include "mozilla/gfx/Types.h"
namespace mozilla {
namespace image {
/**
* An axis-aligned rectangle in tiled image space, with an optional sampling
* restriction rect. The drawing code ensures that if a sampling restriction
* rect is present, any pixels sampled during the drawing process are found
* within that rect.
*
* The sampling restriction rect exists primarily for callers which perform
* pixel snapping. Other callers should generally use one of the Create()
* overloads.
*/
class ImageRegion
{
typedef mozilla::gfx::ExtendMode ExtendMode;
public:
static ImageRegion Empty()
{
return ImageRegion(gfxRect(), ExtendMode::CLAMP);
}
static ImageRegion Create(const gfxRect& aRect,
ExtendMode aExtendMode = ExtendMode::CLAMP)
{
return ImageRegion(aRect, aExtendMode);
}
static ImageRegion Create(const gfxSize& aSize,
ExtendMode aExtendMode = ExtendMode::CLAMP)
{
return ImageRegion(gfxRect(0, 0, aSize.width, aSize.height), aExtendMode);
}
static ImageRegion Create(const nsIntSize& aSize,
ExtendMode aExtendMode = ExtendMode::CLAMP)
{
return ImageRegion(gfxRect(0, 0, aSize.width, aSize.height), aExtendMode);
}
static ImageRegion CreateWithSamplingRestriction(const gfxRect& aRect,
const gfxRect& aRestriction,
ExtendMode aExtendMode = ExtendMode::CLAMP)
{
return ImageRegion(aRect, aRestriction, aExtendMode);
}
bool IsRestricted() const { return mIsRestricted; }
const gfxRect& Rect() const { return mRect; }
const gfxRect& Restriction() const
{
MOZ_ASSERT(mIsRestricted);
return mRestriction;
}
bool RestrictionContains(const gfxRect& aRect) const
{
if (!mIsRestricted) {
return true;
}
return mRestriction.Contains(aRect);
}
ImageRegion Intersect(const gfxRect& aRect) const
{
if (mIsRestricted) {
return CreateWithSamplingRestriction(aRect.Intersect(mRect),
aRect.Intersect(mRestriction));
}
return Create(aRect.Intersect(mRect));
}
gfxRect IntersectAndRestrict(const gfxRect& aRect) const
{
gfxRect intersection = mRect.Intersect(aRect);
if (mIsRestricted) {
intersection = mRestriction.Intersect(intersection);
}
return intersection;
}
void MoveBy(gfxFloat dx, gfxFloat dy)
{
mRect.MoveBy(dx, dy);
if (mIsRestricted) {
mRestriction.MoveBy(dx, dy);
}
}
void Scale(gfxFloat sx, gfxFloat sy)
{
mRect.Scale(sx, sy);
if (mIsRestricted) {
mRestriction.Scale(sx, sy);
}
}
void TransformBy(const gfxMatrix& aMatrix)
{
mRect = aMatrix.TransformRect(mRect);
if (mIsRestricted) {
mRestriction = aMatrix.TransformRect(mRestriction);
}
}
void TransformBoundsBy(const gfxMatrix& aMatrix)
{
mRect = aMatrix.TransformBounds(mRect);
if (mIsRestricted) {
mRestriction = aMatrix.TransformBounds(mRestriction);
}
}
ImageRegion operator-(const gfxPoint& aPt) const
{
if (mIsRestricted) {
return CreateWithSamplingRestriction(mRect - aPt, mRestriction - aPt);
}
return Create(mRect - aPt);
}
ImageRegion operator+(const gfxPoint& aPt) const
{
if (mIsRestricted) {
return CreateWithSamplingRestriction(mRect + aPt, mRestriction + aPt);
}
return Create(mRect + aPt);
}
gfx::ExtendMode GetExtendMode() const
{
return mExtendMode;
}
/* ImageRegion() : mIsRestricted(false) { } */
private:
explicit ImageRegion(const gfxRect& aRect, ExtendMode aExtendMode)
: mRect(aRect)
, mExtendMode(aExtendMode)
, mIsRestricted(false)
{ }
ImageRegion(const gfxRect& aRect, const gfxRect& aRestriction, ExtendMode aExtendMode)
: mRect(aRect)
, mRestriction(aRestriction)
, mExtendMode(aExtendMode)
, mIsRestricted(true)
{ }
gfxRect mRect;
gfxRect mRestriction;
ExtendMode mExtendMode;
bool mIsRestricted;
};
} // namespace image
} // namespace mozilla
Bug 1038536 - Flatten image/src/ directory. r=seth --HG-- rename : image/src/BMPFileHeaders.h => image/BMPFileHeaders.h rename : image/src/ClippedImage.cpp => image/ClippedImage.cpp rename : image/src/ClippedImage.h => image/ClippedImage.h rename : image/src/DecodePool.cpp => image/DecodePool.cpp rename : image/src/DecodePool.h => image/DecodePool.h rename : image/src/Decoder.cpp => image/Decoder.cpp rename : image/src/Decoder.h => image/Decoder.h rename : image/src/Downscaler.cpp => image/Downscaler.cpp rename : image/src/Downscaler.h => image/Downscaler.h rename : image/src/DynamicImage.cpp => image/DynamicImage.cpp rename : image/src/DynamicImage.h => image/DynamicImage.h rename : image/src/FrameAnimator.cpp => image/FrameAnimator.cpp rename : image/src/FrameAnimator.h => image/FrameAnimator.h rename : image/src/FrozenImage.cpp => image/FrozenImage.cpp rename : image/src/FrozenImage.h => image/FrozenImage.h rename : image/src/ICOFileHeaders.h => image/ICOFileHeaders.h rename : image/src/IProgressObserver.h => image/IProgressObserver.h rename : image/src/Image.cpp => image/Image.cpp rename : image/src/Image.h => image/Image.h rename : image/src/ImageFactory.cpp => image/ImageFactory.cpp rename : image/src/ImageFactory.h => image/ImageFactory.h rename : image/src/ImageMetadata.cpp => image/ImageMetadata.cpp rename : image/src/ImageMetadata.h => image/ImageMetadata.h rename : image/src/ImageOps.cpp => image/ImageOps.cpp rename : image/src/ImageOps.h => image/ImageOps.h rename : image/src/ImageRegion.h => image/ImageRegion.h rename : image/src/ImageURL.h => image/ImageURL.h rename : image/src/ImageWrapper.cpp => image/ImageWrapper.cpp rename : image/src/ImageWrapper.h => image/ImageWrapper.h rename : image/src/MultipartImage.cpp => image/MultipartImage.cpp rename : image/src/MultipartImage.h => image/MultipartImage.h rename : image/src/Orientation.h => image/Orientation.h rename : image/src/OrientedImage.cpp => image/OrientedImage.cpp rename : image/src/OrientedImage.h => image/OrientedImage.h rename : image/src/ProgressTracker.cpp => image/ProgressTracker.cpp rename : image/src/ProgressTracker.h => image/ProgressTracker.h rename : image/src/RasterImage.cpp => image/RasterImage.cpp rename : image/src/RasterImage.h => image/RasterImage.h rename : image/src/SVGDocumentWrapper.cpp => image/SVGDocumentWrapper.cpp rename : image/src/SVGDocumentWrapper.h => image/SVGDocumentWrapper.h rename : image/src/ScriptedNotificationObserver.cpp => image/ScriptedNotificationObserver.cpp rename : image/src/ScriptedNotificationObserver.h => image/ScriptedNotificationObserver.h rename : image/src/ShutdownTracker.cpp => image/ShutdownTracker.cpp rename : image/src/ShutdownTracker.h => image/ShutdownTracker.h rename : image/src/SourceBuffer.cpp => image/SourceBuffer.cpp rename : image/src/SourceBuffer.h => image/SourceBuffer.h rename : image/src/SurfaceCache.cpp => image/SurfaceCache.cpp rename : image/src/SurfaceCache.h => image/SurfaceCache.h rename : image/src/VectorImage.cpp => image/VectorImage.cpp rename : image/src/VectorImage.h => image/VectorImage.h rename : image/src/imgFrame.cpp => image/imgFrame.cpp rename : image/src/imgFrame.h => image/imgFrame.h rename : image/src/imgLoader.cpp => image/imgLoader.cpp rename : image/src/imgLoader.h => image/imgLoader.h rename : image/src/imgRequest.cpp => image/imgRequest.cpp rename : image/src/imgRequest.h => image/imgRequest.h rename : image/src/imgRequestProxy.cpp => image/imgRequestProxy.cpp rename : image/src/imgRequestProxy.h => image/imgRequestProxy.h rename : image/src/imgTools.cpp => image/imgTools.cpp rename : image/src/imgTools.h => image/imgTools.h
2015-05-15 06:52:05 +03:00
#endif // mozilla_image_ImageRegion_h