зеркало из https://github.com/mozilla/gecko-dev.git
Bug 716140 - Track image metadata in a separate object, and sync it to the image once decoding is done. r=jlebar
--HG-- extra : rebase_source : ba1173bc1cf090ed02f3a9a7927382c302576088
This commit is contained in:
Родитель
eeeeac4775
Коммит
b56f5d3a1f
|
@ -11,14 +11,8 @@
|
|||
#include "EndianMacros.h"
|
||||
#include "nsICODecoder.h"
|
||||
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "RasterImage.h"
|
||||
|
||||
#include "nsIProperties.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
#include <algorithm>
|
||||
|
||||
namespace mozilla {
|
||||
namespace image {
|
||||
|
||||
|
@ -211,18 +205,7 @@ nsICODecoder::SetHotSpotIfCursor() {
|
|||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISupportsPRUint32> intwrapx =
|
||||
do_CreateInstance("@mozilla.org/supports-PRUint32;1");
|
||||
nsCOMPtr<nsISupportsPRUint32> intwrapy =
|
||||
do_CreateInstance("@mozilla.org/supports-PRUint32;1");
|
||||
|
||||
if (intwrapx && intwrapy) {
|
||||
intwrapx->SetData(mDirEntry.mXHotspot);
|
||||
intwrapy->SetData(mDirEntry.mYHotspot);
|
||||
|
||||
mImage.Set("hotspotX", intwrapx);
|
||||
mImage.Set("hotspotY", intwrapy);
|
||||
}
|
||||
mImageMetadata.SetHotspot(mDirEntry.mXHotspot, mDirEntry.mYHotspot);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -281,14 +281,12 @@ Decoder::PostDecodeDone(int32_t aLoopCount /* = 0 */)
|
|||
NS_ABORT_IF_FALSE(!mDecodeDone, "Decode already done!");
|
||||
mDecodeDone = true;
|
||||
|
||||
// Set premult before DecodingComplete(), since DecodingComplete() calls Optimize()
|
||||
int frames = GetFrameCount();
|
||||
bool isNonPremult = GetDecodeFlags() & DECODER_NO_PREMULTIPLY_ALPHA;
|
||||
for (int i = 0; i < frames; i++) {
|
||||
mImage.SetFrameAsNonPremult(i, isNonPremult);
|
||||
}
|
||||
// Set metadata before DecodingComplete(), since DecodingComplete() calls Optimize()
|
||||
mImageMetadata.SetLoopCount(aLoopCount);
|
||||
mImageMetadata.SetIsNonPremultiplied(GetDecodeFlags() & DECODER_NO_PREMULTIPLY_ALPHA);
|
||||
|
||||
mImage.SetLoopCount(aLoopCount);
|
||||
// Sync metadata to image
|
||||
mImageMetadata.SetOnImage(&mImage);
|
||||
|
||||
// Notify
|
||||
mImage.DecodingComplete();
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "RasterImage.h"
|
||||
#include "imgDecoderObserver.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "ImageMetadata.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace image {
|
||||
|
@ -188,6 +189,7 @@ protected:
|
|||
*/
|
||||
RasterImage &mImage;
|
||||
RefPtr<imgDecoderObserver> mObserver;
|
||||
ImageMetadata mImageMetadata;
|
||||
|
||||
uint32_t mDecodeFlags;
|
||||
bool mDecodeDone;
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/* -*- 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/. */
|
||||
|
||||
#include "ImageMetadata.h"
|
||||
|
||||
#include "RasterImage.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsSupportsPrimitives.h"
|
||||
|
||||
using namespace mozilla::image;
|
||||
|
||||
void
|
||||
ImageMetadata::SetOnImage(RasterImage* image)
|
||||
{
|
||||
if (mHotspotX != -1 && mHotspotY != -1) {
|
||||
nsCOMPtr<nsISupportsPRUint32> intwrapx = do_CreateInstance("@mozilla.org/supports-PRUint32;1");
|
||||
nsCOMPtr<nsISupportsPRUint32> intwrapy = do_CreateInstance("@mozilla.org/supports-PRUint32;1");
|
||||
intwrapx->SetData(mHotspotX);
|
||||
intwrapy->SetData(mHotspotY);
|
||||
image->Set("hotspotX", intwrapx);
|
||||
image->Set("hotspotY", intwrapy);
|
||||
}
|
||||
|
||||
image->SetLoopCount(mLoopCount);
|
||||
|
||||
for (uint32_t i = 0; i < image->GetNumFrames(); i++) {
|
||||
image->SetFrameAsNonPremult(i, mIsNonPremultiplied);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/* -*- 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/. */
|
||||
|
||||
#include "mozilla/StandardInteger.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace image {
|
||||
|
||||
class RasterImage;
|
||||
|
||||
// The metadata about an image that decoders accumulate as they decode.
|
||||
class ImageMetadata
|
||||
{
|
||||
public:
|
||||
ImageMetadata()
|
||||
: mHotspotX(-1)
|
||||
, mHotspotY(-1)
|
||||
, mLoopCount(-1)
|
||||
, mIsNonPremultiplied(false)
|
||||
{}
|
||||
|
||||
// Set the metadata this object represents on an image.
|
||||
void SetOnImage(RasterImage* image);
|
||||
|
||||
void SetHotspot(uint16_t hotspotx, uint16_t hotspoty)
|
||||
{
|
||||
mHotspotX = hotspotx;
|
||||
mHotspotY = hotspoty;
|
||||
}
|
||||
void SetLoopCount(int32_t loopcount)
|
||||
{
|
||||
mLoopCount = loopcount;
|
||||
}
|
||||
|
||||
void SetIsNonPremultiplied(bool nonPremult)
|
||||
{
|
||||
mIsNonPremultiplied = nonPremult;
|
||||
}
|
||||
|
||||
private:
|
||||
// The hotspot found on cursors, or -1 if none was found.
|
||||
int32_t mHotspotX;
|
||||
int32_t mHotspotY;
|
||||
|
||||
// The loop count for animated images, or -1 for infinite loop.
|
||||
int32_t mLoopCount;
|
||||
|
||||
bool mIsNonPremultiplied;
|
||||
};
|
||||
|
||||
} // namespace image
|
||||
} // namespace mozilla
|
|
@ -26,6 +26,7 @@ EXPORTS = imgLoader.h \
|
|||
CPPSRCS = \
|
||||
Image.cpp \
|
||||
ImageFactory.cpp \
|
||||
ImageMetadata.cpp \
|
||||
ImageWrapper.cpp \
|
||||
Decoder.cpp \
|
||||
DiscardTracker.cpp \
|
||||
|
|
Загрузка…
Ссылка в новой задаче