image/ImageMetadata.cpp
author Seth Fowler <mark.seth.fowler@gmail.com>
Wed, 12 Aug 2015 10:41:05 -0700
changeset 257517 fce34ae035239a2014509c8262424dcdccd07e9f
parent 255751 8372b72b359cb1265b7d6a93bfe4f180bee4a212
permissions -rw-r--r--
Bug 1191114 (Part 2) - Add support for creating an anonymous metadata decoder, for use in tests. r=tn

/* -*- 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 "nsISupportsPrimitives.h"
#include "nsXPCOMCID.h"

namespace mozilla {
namespace image {

nsresult
ImageMetadata::SetOnImage(RasterImage* aImage)
{
  nsresult rv = NS_OK;

  if (mHotspotX != -1 && mHotspotY != -1) {
    nsCOMPtr<nsISupportsPRUint32> intwrapx =
      do_CreateInstance(NS_SUPPORTS_PRUINT32_CONTRACTID);
    nsCOMPtr<nsISupportsPRUint32> intwrapy =
      do_CreateInstance(NS_SUPPORTS_PRUINT32_CONTRACTID);
    intwrapx->SetData(mHotspotX);
    intwrapy->SetData(mHotspotY);
    aImage->Set("hotspotX", intwrapx);
    aImage->Set("hotspotY", intwrapy);
  }

  aImage->SetLoopCount(mLoopCount);

  if (HasSize()) {
    MOZ_ASSERT(HasOrientation(), "Should have orientation");
    rv = aImage->SetSize(GetWidth(), GetHeight(), GetOrientation());
  }

  return rv;
}

} // namespace image
} // namespace mozilla