Bug 1102048 (Part 30, imgTools) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth

This commit is contained in:
Glenn Randers-Pehrson 2015-04-02 13:41:00 -07:00
parent abf7e02404
commit 3eda954ef7
2 changed files with 51 additions and 35 deletions

View File

@ -45,9 +45,10 @@ imgTools::~imgTools()
/* destructor code */ /* destructor code */
} }
NS_IMETHODIMP imgTools::DecodeImageData(nsIInputStream* aInStr, NS_IMETHODIMP
const nsACString& aMimeType, imgTools::DecodeImageData(nsIInputStream* aInStr,
imgIContainer **aContainer) const nsACString& aMimeType,
imgIContainer** aContainer)
{ {
MOZ_ASSERT(*aContainer == nullptr, MOZ_ASSERT(*aContainer == nullptr,
"Cannot provide an existing image container to DecodeImageData"); "Cannot provide an existing image container to DecodeImageData");
@ -55,9 +56,10 @@ NS_IMETHODIMP imgTools::DecodeImageData(nsIInputStream* aInStr,
return DecodeImage(aInStr, aMimeType, aContainer); return DecodeImage(aInStr, aMimeType, aContainer);
} }
NS_IMETHODIMP imgTools::DecodeImage(nsIInputStream* aInStr, NS_IMETHODIMP
const nsACString& aMimeType, imgTools::DecodeImage(nsIInputStream* aInStr,
imgIContainer **aContainer) const nsACString& aMimeType,
imgIContainer** aContainer)
{ {
nsresult rv; nsresult rv;
@ -68,16 +70,18 @@ NS_IMETHODIMP imgTools::DecodeImage(nsIInputStream* aInStr,
nsRefPtr<image::Image> image = ImageFactory::CreateAnonymousImage(mimeType); nsRefPtr<image::Image> image = ImageFactory::CreateAnonymousImage(mimeType);
nsRefPtr<ProgressTracker> tracker = image->GetProgressTracker(); nsRefPtr<ProgressTracker> tracker = image->GetProgressTracker();
if (image->HasError()) if (image->HasError()) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
}
// Prepare the input stream. // Prepare the input stream.
nsCOMPtr<nsIInputStream> inStream = aInStr; nsCOMPtr<nsIInputStream> inStream = aInStr;
if (!NS_InputStreamIsBuffered(aInStr)) { if (!NS_InputStreamIsBuffered(aInStr)) {
nsCOMPtr<nsIInputStream> bufStream; nsCOMPtr<nsIInputStream> bufStream;
rv = NS_NewBufferedInputStream(getter_AddRefs(bufStream), aInStr, 1024); rv = NS_NewBufferedInputStream(getter_AddRefs(bufStream), aInStr, 1024);
if (NS_SUCCEEDED(rv)) if (NS_SUCCEEDED(rv)) {
inStream = bufStream; inStream = bufStream;
}
} }
// Figure out how much data we've been passed. // Figure out how much data we've been passed.
@ -87,7 +91,8 @@ NS_IMETHODIMP imgTools::DecodeImage(nsIInputStream* aInStr,
NS_ENSURE_TRUE(length <= UINT32_MAX, NS_ERROR_FILE_TOO_BIG); NS_ENSURE_TRUE(length <= UINT32_MAX, NS_ERROR_FILE_TOO_BIG);
// Send the source data to the Image. // Send the source data to the Image.
rv = image->OnImageDataAvailable(nullptr, nullptr, inStream, 0, uint32_t(length)); rv = image->OnImageDataAvailable(nullptr, nullptr, inStream, 0,
uint32_t(length));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// Let the Image know we've sent all the data. // Let the Image know we've sent all the data.
@ -106,10 +111,11 @@ NS_IMETHODIMP imgTools::DecodeImage(nsIInputStream* aInStr,
* GetDataSurface on such surfaces since that may incure a conversion to * GetDataSurface on such surfaces since that may incure a conversion to
* SurfaceType::DATA which we don't need. * SurfaceType::DATA which we don't need.
*/ */
static nsresult EncodeImageData(DataSourceSurface* aDataSurface, static nsresult
const nsACString& aMimeType, EncodeImageData(DataSourceSurface* aDataSurface,
const nsAString& aOutputOptions, const nsACString& aMimeType,
nsIInputStream **aStream) const nsAString& aOutputOptions,
nsIInputStream** aStream)
{ {
MOZ_ASSERT(aDataSurface->GetFormat() == SurfaceFormat::B8G8R8A8, MOZ_ASSERT(aDataSurface->GetFormat() == SurfaceFormat::B8G8R8A8,
"We're assuming B8G8R8A8"); "We're assuming B8G8R8A8");
@ -119,8 +125,9 @@ static nsresult EncodeImageData(DataSourceSurface* aDataSurface,
NS_LITERAL_CSTRING("@mozilla.org/image/encoder;2?type=") + aMimeType); NS_LITERAL_CSTRING("@mozilla.org/image/encoder;2?type=") + aMimeType);
nsCOMPtr<imgIEncoder> encoder = do_CreateInstance(encoderCID.get()); nsCOMPtr<imgIEncoder> encoder = do_CreateInstance(encoderCID.get());
if (!encoder) if (!encoder) {
return NS_IMAGELIB_ERROR_NO_ENCODER; return NS_IMAGELIB_ERROR_NO_ENCODER;
}
DataSourceSurface::MappedSurface map; DataSourceSurface::MappedSurface map;
if (!aDataSurface->Map(DataSourceSurface::MapType::READ, &map)) { if (!aDataSurface->Map(DataSourceSurface::MapType::READ, &map)) {
@ -145,10 +152,11 @@ static nsresult EncodeImageData(DataSourceSurface* aDataSurface,
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP imgTools::EncodeImage(imgIContainer *aContainer, NS_IMETHODIMP
const nsACString& aMimeType, imgTools::EncodeImage(imgIContainer* aContainer,
const nsAString& aOutputOptions, const nsACString& aMimeType,
nsIInputStream **aStream) const nsAString& aOutputOptions,
nsIInputStream** aStream)
{ {
// Use frame 0 from the image container. // Use frame 0 from the image container.
RefPtr<SourceSurface> frame = RefPtr<SourceSurface> frame =
@ -172,12 +180,13 @@ NS_IMETHODIMP imgTools::EncodeImage(imgIContainer *aContainer,
return EncodeImageData(dataSurface, aMimeType, aOutputOptions, aStream); return EncodeImageData(dataSurface, aMimeType, aOutputOptions, aStream);
} }
NS_IMETHODIMP imgTools::EncodeScaledImage(imgIContainer *aContainer, NS_IMETHODIMP
const nsACString& aMimeType, imgTools::EncodeScaledImage(imgIContainer* aContainer,
int32_t aScaledWidth, const nsACString& aMimeType,
int32_t aScaledHeight, int32_t aScaledWidth,
const nsAString& aOutputOptions, int32_t aScaledHeight,
nsIInputStream **aStream) const nsAString& aOutputOptions,
nsIInputStream** aStream)
{ {
NS_ENSURE_ARG(aScaledWidth >= 0 && aScaledHeight >= 0); NS_ENSURE_ARG(aScaledWidth >= 0 && aScaledHeight >= 0);
@ -238,14 +247,15 @@ NS_IMETHODIMP imgTools::EncodeScaledImage(imgIContainer *aContainer,
return EncodeImageData(dataSurface, aMimeType, aOutputOptions, aStream); return EncodeImageData(dataSurface, aMimeType, aOutputOptions, aStream);
} }
NS_IMETHODIMP imgTools::EncodeCroppedImage(imgIContainer *aContainer, NS_IMETHODIMP
const nsACString& aMimeType, imgTools::EncodeCroppedImage(imgIContainer* aContainer,
int32_t aOffsetX, const nsACString& aMimeType,
int32_t aOffsetY, int32_t aOffsetX,
int32_t aWidth, int32_t aOffsetY,
int32_t aHeight, int32_t aWidth,
const nsAString& aOutputOptions, int32_t aHeight,
nsIInputStream **aStream) const nsAString& aOutputOptions,
nsIInputStream** aStream)
{ {
NS_ENSURE_ARG(aOffsetX >= 0 && aOffsetY >= 0 && aWidth >= 0 && aHeight >= 0); NS_ENSURE_ARG(aOffsetX >= 0 && aOffsetY >= 0 && aWidth >= 0 && aHeight >= 0);
@ -300,7 +310,8 @@ NS_IMETHODIMP imgTools::EncodeCroppedImage(imgIContainer *aContainer,
map.mStride, map.mStride,
SurfaceFormat::B8G8R8A8); SurfaceFormat::B8G8R8A8);
if (!dt) { if (!dt) {
gfxWarning() << "imgTools::EncodeCroppedImage failed in CreateDrawTargetForData"; gfxWarning() <<
"imgTools::EncodeCroppedImage failed in CreateDrawTargetForData";
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }
dt->CopySurface(frame, dt->CopySurface(frame,
@ -312,8 +323,9 @@ NS_IMETHODIMP imgTools::EncodeCroppedImage(imgIContainer *aContainer,
return EncodeImageData(dataSurface, aMimeType, aOutputOptions, aStream); return EncodeImageData(dataSurface, aMimeType, aOutputOptions, aStream);
} }
NS_IMETHODIMP imgTools::CreateScriptedObserver(imgIScriptedNotificationObserver* aInner, NS_IMETHODIMP
imgINotificationObserver** aObserver) imgTools::CreateScriptedObserver(imgIScriptedNotificationObserver* aInner,
imgINotificationObserver** aObserver)
{ {
NS_ADDREF(*aObserver = new ScriptedNotificationObserver(aInner)); NS_ADDREF(*aObserver = new ScriptedNotificationObserver(aInner));
return NS_OK; return NS_OK;

View File

@ -4,6 +4,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_image_src_imgITools_h
#define mozilla_image_src_imgITools_h
#include "imgITools.h" #include "imgITools.h"
#define NS_IMGTOOLS_CID \ #define NS_IMGTOOLS_CID \
@ -25,3 +28,4 @@ public:
private: private:
virtual ~imgTools(); virtual ~imgTools();
}; };
#endif // mozilla_image_src_imgITools_h