Bug 367281 - "Remove SetImageData/SetAlphaData from gfxImageFrame" [p=alfredkayser@nl.ibm.com (Alfred Kayser) r=stuart sr=tor a1.9=stuart]
authorreed@reedloden.com
Sun, 30 Sep 2007 20:32:40 -0700
changeset 6471 88dee8ed6ddb0b7478c0b51c8571ddad9c8e64e3
parent 6470 80f1459fc59ff0ecea23260dc8a60b2f4d0cf71c
child 6472 0aaebe1cefa078911c3af052b5a4bebd8a2bc057
push idunknown
push userunknown
push dateunknown
reviewersstuart, tor
bugs367281
milestone1.9a9pre
Bug 367281 - "Remove SetImageData/SetAlphaData from gfxImageFrame" [p=alfredkayser@nl.ibm.com (Alfred Kayser) r=stuart sr=tor a1.9=stuart]
gfx/idl/gfxIImageFrame.idl
gfx/src/shared/gfxImageFrame.cpp
gfx/src/shared/gfxImageFrame.h
--- a/gfx/idl/gfxIImageFrame.idl
+++ b/gfx/idl/gfxIImageFrame.idl
@@ -128,80 +128,32 @@ interface gfxIImageFrame : nsISupports
    * returns the number of bytes allocated for the image
    */
   readonly attribute unsigned long imageDataLength;
 
   // XXX do we copy here?  lets not...
   void getImageData([array, size_is(length)] out PRUint8 bits, out unsigned long length);
 
   /**
-   * Sets \a length bytes of \a data in this object.
-   * @param offset The offset from the first pixel in bytes.  To set
-   *   data beginning with the first (top left) pixel in the image, \a offset
-   *   should be 0; to set data beginning with, for example, the sixth pixel in
-   *   the first row of a RGBA32 image, the offset should be 20.
-   * @attension should we use PRUint32 instead?
-   */
-  void setImageData([array, size_is(length), const] in PRUint8 data,
-                    in unsigned long length,
-                    in long offset);
-
-  /**
    * Lock image pixels before addressing the data directly
    */
   void lockImageData();
 
   /**
    * Unlock image pixels
    */
   void unlockImageData();
 
 
-
-  /* alpha stuff.. used for _A1 and _A8 formated images */
-  readonly attribute unsigned long alphaBytesPerRow;
-
-  /**
-   * returns the number of bytes allocated for the alpha mask
-   */
-  readonly attribute unsigned long alphaDataLength;
-
-  // XXX do we copy here?  lets not...
-  void getAlphaData([array, size_is(length)] out PRUint8 bits, out unsigned long length);
-
-  /**
-   * Sets \a length bytes of \a data in this object.
-   */
-  void setAlphaData([array, size_is(length), const] in PRUint8 data,
-                    in unsigned long length,
-                    in long offset);
-
-  /**
-   * Lock alpha pixels before addressing the data directly
-   */
-  void lockAlphaData();
-
-  /**
-   * Unlock alpha pixels
-   */
-  void unlockAlphaData();
-
-
-
   /* GIF Specific methods.  These should be in a different class or interface. */
 
   /**
    * Represents the number of milliseconds until the next frame should be displayed.
    * @note -1 means that this frame should be displayed forever.
    */
   attribute long timeout;
 
   /* frame disposal method, used only by GIFs. Should probably subclass image frame
    * and image container for GIFs special needs, but for simplicity it is here for the
    * moment
    */
   attribute long frameDisposalMethod;
-
-  /* frame background color
-   * GIF specific, should be in a GIF specific frame
-   */  
-  attribute gfx_color backgroundColor;
 };
--- a/gfx/src/shared/gfxImageFrame.cpp
+++ b/gfx/src/shared/gfxImageFrame.cpp
@@ -40,19 +40,17 @@
 #include "gfxImageFrame.h"
 #include "nsIServiceManager.h"
 
 NS_IMPL_ISUPPORTS2(gfxImageFrame, gfxIImageFrame, nsIInterfaceRequestor)
 
 gfxImageFrame::gfxImageFrame() :
   mInitialized(PR_FALSE),
   mMutable(PR_TRUE),
-  mHasBackgroundColor(PR_FALSE),
   mTimeout(100),
-  mBackgroundColor(0),
   mDisposalMethod(0)
 {
   /* member initializers and constructor code */
 }
 
 gfxImageFrame::~gfxImageFrame()
 {
   /* destructor code */
@@ -99,17 +97,16 @@ NS_IMETHODIMP gfxImageFrame::Init(PRInt3
   mSize.SizeTo(aWidth, aHeight);
 
   mFormat = aFormat;
 
   mImage = do_CreateInstance("@mozilla.org/gfx/image;1", &rv);
   NS_ASSERTION(mImage, "creation of image failed");
   if (NS_FAILED(rv)) return rv;
 
-  gfx_depth depth = aDepth;
   nsMaskRequirements maskReq;
 
   switch (aFormat) {
   case gfxIFormats::BGR:
   case gfxIFormats::RGB:
     maskReq = nsMaskRequirements_kNoMask;
     break;
 
@@ -130,21 +127,19 @@ NS_IMETHODIMP gfxImageFrame::Init(PRInt3
 
   default:
 #ifdef DEBUG
     printf("unsupported gfx_format\n");
 #endif
     break;
   }
 
-  rv = mImage->Init(aWidth, aHeight, depth, maskReq);
+  rv = mImage->Init(aWidth, aHeight, aDepth, maskReq);
   if (NS_FAILED(rv)) return rv;
 
-  mTopToBottom = mImage->GetIsRowOrderTopToBottom();
-
   mInitialized = PR_TRUE;
   return NS_OK;
 }
 
 
 /* attribute boolean mutable */
 NS_IMETHODIMP gfxImageFrame::GetMutable(PRBool *aMutable)
 {
@@ -271,108 +266,16 @@ NS_IMETHODIMP gfxImageFrame::GetImageDat
     return NS_ERROR_NOT_INITIALIZED;
 
   *aData = mImage->GetBits();
   *length = mImage->GetLineStride() * mSize.height;
 
   return NS_OK;
 }
 
-/* void setImageData ([array, size_is (length), const] in PRUint8 data, in unsigned long length, in long offset); */
-NS_IMETHODIMP gfxImageFrame::SetImageData(const PRUint8 *aData, PRUint32 aLength, PRInt32 aOffset)
-{
-  return SetData(aData, aLength, aOffset, PR_FALSE);
-}
-
-nsresult gfxImageFrame::SetData(const PRUint8 *aData, PRUint32 aLength, 
-                                PRInt32 aOffset, PRBool aSetAlpha)
-{
-  if (!mInitialized)
-    return NS_ERROR_NOT_INITIALIZED;
-
-  NS_ASSERTION(mMutable, "trying to set data on an immutable frame");
-  NS_ASSERTION(!(aOffset<0), "can't have a negative offset");
-  if (!mMutable || aOffset < 0)
-    return NS_ERROR_FAILURE;
-
-  if (aSetAlpha && !mImage->GetHasAlphaMask())
-    return NS_ERROR_NOT_INITIALIZED;
-
-  if (aLength == 0)
-    return NS_OK;
-
-  mImage->LockImagePixels(aSetAlpha);
-  PRUint8 *imgData = aSetAlpha ? mImage->GetAlphaBits() : mImage->GetBits();
-  const PRUint32 rowStride = aSetAlpha ? mImage->GetAlphaLineStride() : mImage->GetLineStride();
-  const PRUint32 dataLength = rowStride * mSize.height;
-  const PRUint32 numRowsToSet = 1 + ((aLength-1) / rowStride);
-  const PRUint32 firstRowToSet = (aOffset / rowStride);
-
-  // Independent from which order the rows are sorted in, 
-  // the number of bytes to set + offset should never exceed the image data space
-  if ((((PRUint32)aOffset + aLength) > dataLength) || !imgData) {
-    mImage->UnlockImagePixels(aSetAlpha);
-    return NS_ERROR_FAILURE;
-  }
-
-  if (mTopToBottom) {
-    // Easy situation
-    if (aData)
-      memcpy(imgData + aOffset, aData, aLength);
-    else
-      memset(imgData + aOffset, 0, aLength);
-  } else {
-    // Rows are stored in reverse order (BottomToTop) from those supplied (TopToBottom)
-    // yOffset is the offset into the reversed image data for firstRowToSet
-    PRUint32 xOffset = aOffset % rowStride;
-    PRUint32 yOffset = (mSize.height - firstRowToSet - 1) * rowStride;
-    if (aData) {
-      // Set the image data in reverse order
-      for (PRUint32 i=0; i<numRowsToSet; i++) {
-        PRUint32 lengthOfRowToSet = rowStride - xOffset;
-        lengthOfRowToSet = PR_MIN(lengthOfRowToSet, aLength);
-        memcpy(imgData + yOffset + xOffset, aData, lengthOfRowToSet);
-        aData += lengthOfRowToSet;
-        aLength -= lengthOfRowToSet;
-        yOffset -= rowStride;
-        xOffset = 0;
-      }
-    } else {
-      // Clear the image data in reverse order
-      if (xOffset) {
-        // First row, if not starting at first column
-        PRUint32 lengthOfRowToSet = rowStride - xOffset;
-        lengthOfRowToSet = PR_MIN(lengthOfRowToSet, aLength);
-        memset(imgData + yOffset + xOffset, 0, lengthOfRowToSet);
-        aLength -= lengthOfRowToSet;
-        yOffset -= rowStride;
-      }
-      if (aLength > rowStride) {
-        // Zero all the whole rows
-        const PRUint32 wholeRows = rowStride * (PRUint32)(aLength / rowStride);
-        memset(imgData + yOffset - (wholeRows - rowStride), 0, wholeRows);
-        aLength -= wholeRows;
-        yOffset -= wholeRows;
-      }
-      if (aLength) {
-        // Last incomplete row
-        memset(imgData + yOffset, 0, aLength);
-      }
-    }
-  }
-  mImage->UnlockImagePixels(aSetAlpha);
-
-  if (!aSetAlpha) {
-    // adjust for aLength < rowStride
-    nsIntRect r(0, firstRowToSet, mSize.width, numRowsToSet);
-    mImage->ImageUpdated(nsnull, nsImageUpdateFlags_kBitsChanged, &r);
-  }
-  return NS_OK;
-}
-
 /* void lockImageData (); */
 NS_IMETHODIMP gfxImageFrame::LockImageData()
 {
   if (!mInitialized)
     return NS_ERROR_NOT_INITIALIZED;
 
   return mImage->LockImagePixels(PR_FALSE);
 }
@@ -381,74 +284,16 @@ NS_IMETHODIMP gfxImageFrame::LockImageDa
 NS_IMETHODIMP gfxImageFrame::UnlockImageData()
 {
   if (!mInitialized)
     return NS_ERROR_NOT_INITIALIZED;
 
   return mImage->UnlockImagePixels(PR_FALSE);
 }
 
-/* readonly attribute unsigned long alphaBytesPerRow; */
-NS_IMETHODIMP gfxImageFrame::GetAlphaBytesPerRow(PRUint32 *aBytesPerRow)
-{
-  if (!mInitialized || !mImage->GetHasAlphaMask())
-    return NS_ERROR_NOT_INITIALIZED;
-
-  *aBytesPerRow = mImage->GetAlphaLineStride();
-  return NS_OK;
-}
-
-/* readonly attribute unsigned long alphaDataLength; */
-NS_IMETHODIMP gfxImageFrame::GetAlphaDataLength(PRUint32 *aBitsLength)
-{
-  if (!mInitialized || !mImage->GetHasAlphaMask())
-    return NS_ERROR_NOT_INITIALIZED;
-
-  *aBitsLength = mImage->GetAlphaLineStride() * mSize.height;
-  return NS_OK;
-}
-
-/* void getAlphaData([array, size_is(length)] out PRUint8 bits, out unsigned long length); */
-NS_IMETHODIMP gfxImageFrame::GetAlphaData(PRUint8 **aData, PRUint32 *length)
-{
-  if (!mInitialized || !mImage->GetHasAlphaMask())
-    return NS_ERROR_NOT_INITIALIZED;
-
-  NS_ASSERTION(mMutable, "trying to get data on an immutable frame");
-
-  *aData = mImage->GetAlphaBits();
-  *length = mImage->GetAlphaLineStride() * mSize.height;
-
-  return NS_OK;
-}
-
-/* void setAlphaData ([array, size_is (length), const] in PRUint8 data, in unsigned long length, in long offset); */
-NS_IMETHODIMP gfxImageFrame::SetAlphaData(const PRUint8 *aData, PRUint32 aLength, PRInt32 aOffset)
-{
-  return SetData(aData, aLength, aOffset, PR_TRUE);
-}
-
-/* void lockAlphaData (); */
-NS_IMETHODIMP gfxImageFrame::LockAlphaData()
-{
-  if (!mInitialized || !mImage->GetHasAlphaMask())
-    return NS_ERROR_NOT_INITIALIZED;
-
-  return mImage->LockImagePixels(PR_TRUE);
-}
-
-/* void unlockAlphaData (); */
-NS_IMETHODIMP gfxImageFrame::UnlockAlphaData()
-{
-  if (!mInitialized || !mImage->GetHasAlphaMask())
-    return NS_ERROR_NOT_INITIALIZED;
-
-  return mImage->UnlockImagePixels(PR_TRUE);
-}
-
 /* attribute long timeout; */
 NS_IMETHODIMP gfxImageFrame::GetTimeout(PRInt32 *aTimeout)
 {
   if (!mInitialized)
     return NS_ERROR_NOT_INITIALIZED;
 
   // Ensure a minimal time between updates so we don't throttle the UI thread.
   // consider 0 == unspecified and make it fast but not too fast.  See bug
@@ -493,35 +338,16 @@ NS_IMETHODIMP gfxImageFrame::SetFrameDis
 {
   if (!mInitialized)
     return NS_ERROR_NOT_INITIALIZED;
 
   mDisposalMethod = aFrameDisposalMethod;
   return NS_OK;
 }
 
-/* attribute gfx_color backgroundColor; */
-NS_IMETHODIMP gfxImageFrame::GetBackgroundColor(gfx_color *aBackgroundColor)
-{
-  if (!mInitialized || !mHasBackgroundColor)
-    return NS_ERROR_NOT_INITIALIZED;
-
-  *aBackgroundColor = mBackgroundColor;
-  return NS_OK;
-}
-NS_IMETHODIMP gfxImageFrame::SetBackgroundColor(gfx_color aBackgroundColor)
-{
-  if (!mInitialized)
-    return NS_ERROR_NOT_INITIALIZED;
-
-  mBackgroundColor = aBackgroundColor;
-  mHasBackgroundColor = PR_TRUE;
-  return NS_OK;
-}
-
 NS_IMETHODIMP gfxImageFrame::GetInterface(const nsIID & aIID, void * *result)
 {
   if (!mInitialized)
     return NS_ERROR_NOT_INITIALIZED;
 
   NS_ENSURE_ARG_POINTER(result);
 
   if (NS_SUCCEEDED(QueryInterface(aIID, result)))
--- a/gfx/src/shared/gfxImageFrame.h
+++ b/gfx/src/shared/gfxImageFrame.h
@@ -66,26 +66,18 @@ public:
 
   gfxImageFrame();
   virtual ~gfxImageFrame();
 
 protected:
   nsIntSize mSize;
 
 private:
-  nsresult  SetData(const PRUint8 *aData, PRUint32 aLength, 
-                    PRInt32 aOffset, PRBool aSetAlpha);
-
   nsCOMPtr<nsIImage> mImage;
 
   PRPackedBool mInitialized;
   PRPackedBool mMutable;
-  PRPackedBool mHasBackgroundColor;
-  PRPackedBool mTopToBottom;
   gfx_format   mFormat;
 
-  PRInt32 mTimeout; // -1 means display forever
-  nsIntPoint mOffset;
-
-  gfx_color mBackgroundColor;
-
-  PRInt32   mDisposalMethod;
+  PRInt32      mTimeout; // -1 means display forever
+  nsIntPoint   mOffset;
+  PRInt32      mDisposalMethod;
 };