Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
nsImageBeOS Class Reference

#include <nsImageBeOS.h>

Inheritance diagram for nsImageBeOS:
Inheritance graph
[legend]
Collaboration diagram for nsImageBeOS:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsImageBeOS ()
virtual ~nsImageBeOS ()
virtual NS_DECL_ISUPPORTS PRInt32 GetBytesPix ()
 Get the number of bytes per pixel for this image - dwc 2/3/99.
virtual PRInt32 GetHeight ()
 Get the height for the pixelmap - dwc 2/1/99.
virtual PRInt32 GetWidth ()
 Get the width for the pixelmap - dwc 2/1/99.
virtual PRUint8GetBits ()
 Get a pointer to the bits for the pixelmap, only if it is not optimized - dwc 2/1/99.
virtual voidGetBitInfo ()
 Return information about the bits for this structure - dwc 2/1/99.
virtual PRBool GetIsRowOrderTopToBottom ()
 Get whether rows are organized top to bottom, or bottom to top - syd 3/29/99.
virtual PRInt32 GetLineStride ()
 Get the number of bytes needed to get to the next scanline for the pixelmap - dwc 2/1/99.
virtual nsColorMapGetColorMap ()
 Get the colormap for the nsIImage - dwc 2/1/99.
NS_IMETHOD Draw (nsIRenderingContext &aContext, nsIDrawingSurface *aSurface, PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
 BitBlit the nsIImage to a device, the source can be scaled to the dest - dwc 2/1/99.
NS_IMETHOD Draw (nsIRenderingContext &aContext, nsIDrawingSurface *aSurface, PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight, PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight)
 BitBlit the nsIImage to a device, the source and dest can be scaled - dwc 2/1/99.
NS_IMETHOD DrawToImage (nsIImage *aDstImage, nscoord aDX, nscoord aDY, nscoord aDWidth, nscoord aDHeight)
 BitBlit the entire (no cropping) nsIImage to another nsImage, the source and dest can be scaled - saari 03/08/01.
NS_IMETHOD DrawTile (nsIRenderingContext &aContext, nsIDrawingSurface *aSurface, PRInt32 aSXOffset, PRInt32 aSYOffset, PRInt32 aPadX, PRInt32 aPadY, const nsRect &aTileRect)
virtual void ImageUpdated (nsIDeviceContext *aContext, PRUint8 aFlags, nsRect *aUpdateRect)
 Update the nsIImage color table - dwc 2/1/99.
virtual PRBool GetIsImageComplete ()
 
See documentation in nsIImage.h
virtual nsresult Init (PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth, nsMaskRequirements aMaskRequirements)
 Build and initialize the nsIImage.
virtual PRBool IsOptimized ()
virtual nsresult Optimize (nsIDeviceContext *aContext)
 Converted this pixelmap to an optimized pixelmap for the device - dwc 2/1/99.
virtual PRBool GetHasAlphaMask ()
 Get whether this image has an alpha mask.
virtual PRUint8GetAlphaBits ()
 Get a pointer to the bits for the alpha mask - dwc 2/1/99.
virtual PRInt32 GetAlphaLineStride ()
 Get the number of bytes per scanline for the alpha mask - dwc 2/1/99.
virtual PRInt8 GetAlphaDepth ()
 Get the alpha depth for the image mask - lordpixel 2001/05/16.
NS_IMETHOD LockImagePixels (PRBool aMaskPixels)
 LockImagePixels Lock the image pixels so that we can access them directly, with safely.
NS_IMETHOD UnlockImagePixels (PRBool aMaskPixels)
 UnlockImagePixels Unlock the image pixels.

Protected Member Functions

void CreateImage (nsIDrawingSurface *aSurface)
nsresult BuildImage (nsIDrawingSurface *aDrawingSurface)

Private Member Functions

void ComputePaletteSize (PRIntn nBitCount)

Private Attributes

BBitmap * mImage
BBitmap * mTileBitmap
PRUint8mImageBits
PRInt32 mWidth
PRInt32 mHeight
PRInt32 mDepth
PRInt32 mRowBytes
PRInt32 mSizeImage
PRInt32 mDecodedX1
PRInt32 mDecodedY1
PRInt32 mDecodedX2
PRInt32 mDecodedY2
PRUint8mAlphaBits
PRInt16 mAlphaRowBytes
PRInt8 mAlphaDepth
PRUint8 mFlags
PRInt8 mNumBytesPixel
PRBool mImageCurrent
PRBool mOptimized

Detailed Description

Definition at line 46 of file nsImageBeOS.h.


Constructor & Destructor Documentation

Definition at line 71 of file nsImageBeOS.cpp.

{
       if (nsnull != mImage) 
       {
              delete mImage;
              mImage = nsnull;
       }
                     
       if (mTileBitmap) 
       {
              delete mTileBitmap;
              mTileBitmap = nsnull;
       }

       if (nsnull != mImageBits) 
       {
              delete [] mImageBits;
              mImageBits = nsnull;
       }
       if (nsnull != mAlphaBits) 
       {
              delete [] mAlphaBits;
              mAlphaBits = nsnull;
       }
}

Member Function Documentation

nsresult nsImageBeOS::BuildImage ( nsIDrawingSurface aDrawingSurface) [protected]

Definition at line 488 of file nsImageBeOS.cpp.

{
       CreateImage(aDrawingSurface);
       return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsImageBeOS::ComputePaletteSize ( PRIntn  nBitCount) [private]
void nsImageBeOS::CreateImage ( nsIDrawingSurface aSurface) [protected]

Definition at line 498 of file nsImageBeOS.cpp.

{
       PRInt32 validX = 0, validY = 0, validMostX = mWidth, validMostY = mHeight;

       if (mImageBits) 
       {
              if (24 != mDepth) 
              {
                     NS_ASSERTION(PR_FALSE, "unexpected image depth");
                     return;
              }
              
              // If the previous BBitmap is the right dimensions and colorspace, then reuse it.
              const color_space cs = B_RGBA32;
              if (nsnull != mImage) 
              {
                     BRect bounds = mImage->Bounds();
                     if (bounds.IntegerWidth() < validMostX - 1 || bounds.IntegerHeight() < validMostY - 1 ||
                            mImage->ColorSpace() != cs) 
                     {
                            
                            delete mImage;
                            mImage = new BBitmap(BRect(0, 0, validMostX - 1, validMostY - 1), cs, false);
                     } 
                     else 
                     {
                            // Don't copy the data twice if the BBitmap is up to date
                            if (mImageCurrent) return;
                     }
              } 
              else 
              {
                     // No BBitmap exists, so create one and update it
                     mImage = new BBitmap(BRect(0, 0, mWidth - 1, mHeight - 1), cs, false);
              }
              
              // Only the data that has changed (the rectangle supplied to ImageUpdated())
              // needs to be copied to the BBitmap. 
              
              if ((mDecodedY2 < mHeight)) 
                     validMostY = mDecodedY2;

              if ((mDecodedX2 < mWidth)) 
                     validMostX = mDecodedX2;

              if ((mDecodedY1 > 0)) 
                     validY = mDecodedY1;
              if ((mDecodedX1 > 0)) 
                     validX = mDecodedX1;
              
              if (mDecodedX2 < mDecodedX1 || mDecodedY2 < mDecodedY1)
                     return;

              // Making up a 32 bit double word for the destination is much more efficient
              // than writing each byte separately on some CPUs. For example, BeOS does not
              // support write-combining on the Athlon/Duron family.
              
              // Using mRowBytes as source stride due alignment of mImageBits array to 4.
              // Destination stride is mWidth, as mImage always uses RGB(A)32 
              if (mImage && mImage->IsValid()) 
              {
                     uint32 *dest, *dst0 = (uint32 *)mImage->Bits() + validX;
                     uint8 *src, *src0 = mImageBits + 3*validX; 
                     if (mAlphaBits) 
                     {
                            uint8 a, *alpha = mAlphaBits + validY*mAlphaRowBytes;;
                            for (int y = validY; y < validMostY; ++y) 
                            {
                                   dest = dst0 + y*mWidth;
                                   src = src0 + y*mRowBytes;
                                   for (int x = validX; x < validMostX; ++x) 
                                   {
                                          if(1 == mAlphaDepth)
                                                 a = (alpha[x / 8] & (1 << (7 - (x % 8)))) ? 255 : 0;
                                          else
                                                 a = alpha[x];
                                          *dest++ = (a << 24) | (src[2] << 16) | (src[1] << 8) | src[0];
                                          src += 3;
                                   }
                                   alpha += mAlphaRowBytes;
                            }
                     } 
                     else 
                     {
                            // Fixed 255 in the alpha channel to mean completely opaque
                            for (int y = validY; y < validMostY; ++y) 
                            {
                                   dest = dst0 + y*mWidth;
                                   src = src0 + y*mRowBytes;
                                   for (int x = validX; x < validMostX; ++x) 
                                   {
                                          *dest++ = 0xff000000 | (src[2] << 16) | (src[1] << 8) | src[0];
                                          src += 3;
                                   }
                            }
                     }
                     
                     // The contents of the BBitmap now match mImageBits (and mAlphaBits),
                     // so mark the flag up to date to prevent extra copies in the future.
                     mImageCurrent = PR_TRUE;
              }
       }
}

Here is the caller graph for this function:

NS_IMETHODIMP nsImageBeOS::Draw ( nsIRenderingContext aContext,
nsIDrawingSurface aSurface,
PRInt32  aX,
PRInt32  aY,
PRInt32  aWidth,
PRInt32  aHeight 
) [virtual]

BitBlit the nsIImage to a device, the source can be scaled to the dest - dwc 2/1/99.

Parameters:
aSurfacethe surface to blit to
aXThe destination horizontal location
aYThe destination vertical location
aWidthThe destination width of the pixelmap
aHeightThe destination height of the pixelmap
Returns:
if TRUE, no errors

Implements nsIImage.

Definition at line 255 of file nsImageBeOS.cpp.

{
       //Don't bother to draw nothing            
       if (!aWidth || !aHeight)
              return NS_OK;
       if (mDecodedX2 < mDecodedX1 || mDecodedY2 < mDecodedY1)
              return NS_OK;

       if (!mImageCurrent || (nsnull == mImage)) 
              BuildImage(aSurface);
       if (nsnull == mImage) 
              return NS_ERROR_FAILURE;

       PRInt32 validX = 0, validY = 0, validMostX = mWidth, validMostY = mHeight;

       // XXX kipp: this is temporary code until we eliminate the
       // width/height arguments from the draw method.
       aWidth = PR_MIN(aWidth, mWidth);
       aHeight = PR_MIN(aHeight, mHeight);

       if ((mDecodedY2 < aHeight)) 
              validMostY = mDecodedY2;

       if ((mDecodedX2 < aWidth)) 
              validMostX = mDecodedX2;

       if ((mDecodedY1 > 0)) 
              validY = mDecodedY1;
       if ((mDecodedX1 > 0)) 
              validX = mDecodedX1;
                     
       nsDrawingSurfaceBeOS *beosdrawing = (nsDrawingSurfaceBeOS *)aSurface;
       BView *view;

       if (((nsRenderingContextBeOS&)aContext).LockAndUpdateView()) 
       {
              beosdrawing->AcquireView(&view);
              if (view) 
              {
                     // See TODO clipping comment above - code ready for use:
                     // BRegion tmpreg(BRect(aX + validX, aY + validY, aX + validMostX - 1, aY + validMostY - 1));
                     // view->ConstrainClippingRegion(&tmpreg);
                     
                     // Only use B_OP_ALPHA when there is an alpha channel present, as it is much slower
                     if (0 != mAlphaDepth) 
                     {
                            view->SetDrawingMode(B_OP_ALPHA);
                            view->DrawBitmap(mImage, BRect(validX, validY, validMostX - 1, validMostY - 1), 
                                                        BRect(aX + validX, aY + validY, aX + validMostX - 1, aY + validMostY - 1));
                            view->SetDrawingMode(B_OP_COPY);
                     } 
                     else 
                     {
                            view->DrawBitmap(mImage, BRect(validX, validY, validMostX - 1, validMostY - 1), 
                                                        BRect(aX + validX, aY + validY, aX + validMostX - 1, aY + validMostY - 1));
                     }
              }
              ((nsRenderingContextBeOS&)aContext).UnlockView();
              beosdrawing->ReleaseView();
       }

       mFlags = 0;
       return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsImageBeOS::Draw ( nsIRenderingContext aContext,
nsIDrawingSurface aSurface,
PRInt32  aSX,
PRInt32  aSY,
PRInt32  aSWidth,
PRInt32  aSHeight,
PRInt32  aDX,
PRInt32  aDY,
PRInt32  aDWidth,
PRInt32  aDHeight 
) [virtual]

BitBlit the nsIImage to a device, the source and dest can be scaled - dwc 2/1/99.

Parameters:
aSurfacethe surface to blit to
aSXThe source width of the pixelmap
aSYThe source vertical location
aSWidthThe source width of the pixelmap
aSHeightThe source height of the pixelmap
aDXThe destination horizontal location
aDYThe destination vertical location
aDWidthThe destination width of the pixelmap
aDHeightThe destination height of the pixelmap
Returns:
if TRUE, no errors

Implements nsIImage.

Definition at line 176 of file nsImageBeOS.cpp.

{
       // Don't bother to draw nothing           
       if (!aSWidth || !aSHeight || !aDWidth || !aDHeight)
              return NS_OK;
       if (mDecodedX2 < mDecodedX1 || mDecodedY2 < mDecodedY1)
              return NS_OK;

       // As we do all scaling with Be API (DrawBitmap), using float is safe and convinient       
       float srcX = aSX, srcY = aSY, srcMostX = aSX + aSWidth, srcMostY = aSY + aSHeight;
       float dstX = aDX, dstY = aDY, dstMostX = aDX + aDWidth, dstMostY = aDY + aDHeight;
       float  scaleX = float(aDWidth)/float(aSWidth), scaleY = float(aDHeight)/float(aSHeight);

       if (!mImageCurrent || (nsnull == mImage)) 
              BuildImage(aSurface);
       if (nsnull == mImage || mImage->BitsLength() == 0) 
              return NS_ERROR_FAILURE;

       // Limit the image rectangle to the size of the image data which
       // has been validated. 
       if ((mDecodedY1 > 0)) 
       {
              srcY = float(PR_MAX(mDecodedY1, aSY));
       }
       if ((mDecodedX1 > 0))
       {
              srcX = float(PR_MAX(mDecodedX1, aSX));
       }
       // When targeting BRects, MostX/Y is more natural than Width/Heigh
       if ((mDecodedY2 < mHeight)) 
              srcMostY = float(PR_MIN(mDecodedY2, aSY + aSHeight));

       if ((mDecodedX2 < mWidth)) 
              srcMostX = float(PR_MIN(mDecodedX2, aSX + aSWidth));

       dstX = float(srcX - aSX)*scaleX + float(aDX);
       dstY = float(srcY - aSY)*scaleY + float(aDY);
       dstMostX = dstMostX - (float(aSWidth + aSX) - srcMostX)*scaleX;
       dstMostY =    dstMostY - (float(aSHeight + aSY) - srcMostY)*scaleY;

       nsDrawingSurfaceBeOS *beosdrawing = (nsDrawingSurfaceBeOS *)aSurface;
       BView *view;

       // LockAndUpdateView() sets proper clipping region here and elsewhere in nsImageBeOS.
       if (((nsRenderingContextBeOS&)aContext).LockAndUpdateView()) 
       {
              beosdrawing->AcquireView(&view);
              if (view) 
              {
                     // TODO: With future locking update check if restricting clipping region 
                     // to decoded values fastens things up - in this case clipping must be reset to 0
                     // at unlocking or before getting native region in LockAndUpdateView().

                     // Only use B_OP_ALPHA when there is an alpha channel present, as it is much slower
                     if (0 != mAlphaDepth) 
                     {
                            view->SetDrawingMode(B_OP_ALPHA);
                            view->DrawBitmap(mImage, BRect(srcX, srcY, srcMostX - 1, srcMostY - 1),
                                   BRect(dstX, dstY, dstMostX - 1, dstMostY - 1));
                            view->SetDrawingMode(B_OP_COPY);
                     }
                     else 
                     {
                            view->DrawBitmap(mImage, BRect(srcX, srcY, srcMostX - 1, srcMostY - 1),
                                   BRect(dstX, dstY, dstMostX - 1, dstMostY - 1));
                     }
                     // view was locked by LockAndUpdateView() before it was aquired. So unlock.
              }
              ((nsRenderingContextBeOS&)aContext).UnlockView();
              beosdrawing->ReleaseView();
       }
       
       mFlags = 0;
       return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsImageBeOS::DrawTile ( nsIRenderingContext aContext,
nsIDrawingSurface aSurface,
PRInt32  aSXOffset,
PRInt32  aSYOffset,
PRInt32  aPadX,
PRInt32  aPadY,
const nsRect aTileRect 
) [virtual]

Implements nsIImage.

Definition at line 321 of file nsImageBeOS.cpp.

{
       // Don't bother to draw nothing    
       if (!aTileRect.width || !aTileRect.height)
              return NS_OK;
       if (mDecodedX2 < mDecodedX1 || mDecodedY2 < mDecodedY1)
              return NS_OK;

       if (!mImageCurrent || (nsnull == mImage)) 
              BuildImage(aSurface);
       if (nsnull == mImage || mImage->BitsLength() == 0) 
              return NS_ERROR_FAILURE;

       PRInt32 validX = 0, validY = 0, validMostX = mWidth, validMostY = mHeight;

       // Limit the image rectangle to the size of the image data which
       // has been validated.
       if ((mDecodedY2 < mHeight)) 
              validMostY = mDecodedY2;

       if ((mDecodedX2 < mWidth)) 
              validMostX = mDecodedX2;

       if ((mDecodedY1 > 0)) 
              validY = mDecodedY1;

       if ((mDecodedX1 > 0)) 
              validX = mDecodedX1;

       nsDrawingSurfaceBeOS *beosdrawing = (nsDrawingSurfaceBeOS *)aSurface;
       BView *view = 0;
       if (((nsRenderingContextBeOS&)aContext).LockAndUpdateView()) 
       {
              beosdrawing->AcquireView(&view);
              if (view) 
              {
               BRegion rgn(BRect(aTileRect.x, aTileRect.y,
                                   aTileRect.x + aTileRect.width - 1, aTileRect.y + aTileRect.height - 1));
           view->ConstrainClippingRegion(&rgn);

                     // Force transparency for bitmap blitting in case of padding even if mAlphaDepth == 0
                     if (0 != mAlphaDepth || aPadX || aPadY) 
                            view->SetDrawingMode(B_OP_ALPHA);
                     // Creating temporary bitmap, compatible with mImage and  with size of area to be filled with tiles
                     // Reuse existing if possible
                     if (!mTileBitmap || mTileBitmap->Bounds().IntegerWidth() + 1 != aTileRect.width || mTileBitmap->Bounds().IntegerHeight() + 1 != aTileRect.height)
                     {
                            if (mTileBitmap)
                            {
                                   delete mTileBitmap;
                                   mTileBitmap = nsnull;
                            }
                            mTileBitmap = new BBitmap(BRect(0, 0, aTileRect.width - 1, aTileRect.height -1), mImage->ColorSpace(), false);
                     }
                     
                     int32 tmpbitlength = mTileBitmap->BitsLength();

                     if (!mTileBitmap || tmpbitlength == 0)
                     {
                            // Failed. Cleaning things a bit.
                            ((nsRenderingContextBeOS&)aContext).UnlockView();
                            if (mTileBitmap)
                            {
                                   delete mTileBitmap;
                                   mTileBitmap = nsnull;
                            }
                            beosdrawing->ReleaseView();
                            return NS_ERROR_FAILURE;
                     }

                     uint32 *dst0 = (uint32 *)mTileBitmap->Bits();
                     uint32 *src0 = (uint32 *)mImage->Bits();
                     uint32 *dst = dst0;
                     uint32 dstRowLength = mTileBitmap->BytesPerRow()/4;
                     uint32 dstColHeight = tmpbitlength/mTileBitmap->BytesPerRow();

                     // Filling mTileBitmap with transparent color to preserve padding areas on destination 
                     uint32 filllength = tmpbitlength/4;
                     if (0 != mAlphaDepth  || aPadX || aPadY) 
                     {
                            for (uint32 i=0, *dst = dst0; i < filllength; ++i)
                                   *(dst++) = B_TRANSPARENT_MAGIC_RGBA32;
                     }

                     // Rendering mImage tile to temporary bitmap
                     uint32 *src = src0; dst = dst0;
                     for (uint32 y = 0, yy = aSYOffset; y < dstColHeight; ++y) 
                     {                                  
                            src = src0 + yy*mWidth;
                            dst = dst0 + y*dstRowLength;
                            // Avoid unnecessary job outside update rect
                            if (yy >= validY && yy <= validMostY)
                            {
                                   for (uint32 x = 0, xx = aSXOffset; x < dstRowLength; ++x) 
                                   {
                                          // Avoid memwrite if outside update rect
                                          if (xx >= validX && xx <= validMostX)
                                                 dst[x] = src[xx];
                                          if (++xx == mWidth)
                                          {
                                                 // Width of source reached. Adding horizontal paddding.
                                                 xx = 0;
                                                 x += aPadX;
                                          }
                                   }
                            }
                            if (++yy == mHeight)
                            {
                                   // Height of source reached. Adding vertical paddding.
                                   yy = 0;
                                   y += aPadY;
                            }
                     }
                     // Flushing tile bitmap to proper area in drawable BView       
                     view->DrawBitmap(mTileBitmap, BPoint(aTileRect.x , aTileRect.y ));
                     view->SetDrawingMode(B_OP_COPY);
                     view->Sync();
              }
              ((nsRenderingContextBeOS&)aContext).UnlockView();
              beosdrawing->ReleaseView();
       }
       mFlags = 0;
       return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsImageBeOS::DrawToImage ( nsIImage aDstImage,
nscoord  aDX,
nscoord  aDY,
nscoord  aDWidth,
nscoord  aDHeight 
) [virtual]

BitBlit the entire (no cropping) nsIImage to another nsImage, the source and dest can be scaled - saari 03/08/01.

Parameters:
aDstImagethe nsImage to blit to
aDXThe destination horizontal location
aDYThe destination vertical location
aDWidthThe destination width of the pixelmap
aDHeightThe destination height of the pixelmap
Returns:
if TRUE, no errors

Implements nsIImage.

Definition at line 606 of file nsImageBeOS.cpp.

{
       nsImageBeOS *dest = NS_STATIC_CAST(nsImageBeOS *, aDstImage);

       if (!dest)
              return NS_ERROR_FAILURE;

       if (aDX >= dest->mWidth || aDY >= dest->mHeight)
              return NS_OK;

       PRUint8 *rgbPtr=0, *alphaPtr=0;
       PRUint32 rgbStride, alphaStride;

       rgbPtr = mImageBits;
       rgbStride = mRowBytes;
       alphaPtr = mAlphaBits;
       alphaStride = mAlphaRowBytes;

       PRInt32 y;
       PRInt32 ValidWidth = ( aDWidth < ( dest->mWidth - aDX ) ) ? aDWidth : ( dest->mWidth - aDX ); 
       PRInt32 ValidHeight = ( aDHeight < ( dest->mHeight - aDY ) ) ? aDHeight : ( dest->mHeight - aDY );

       // now composite the two images together
       switch (mAlphaDepth)
       {
              case 1:
              {
                     PRUint8 *dst = dest->mImageBits + aDY*dest->mRowBytes + 3*aDX;
                     PRUint8 *dstAlpha = dest->mAlphaBits + aDY*dest->mAlphaRowBytes;
                     PRUint8 *src = rgbPtr;
                     PRUint8 *alpha = alphaPtr;
                     PRUint8 offset = aDX & 0x7; // x starts at 0
                     PRUint8 offset_8U = 8U - offset;
                     int iterations = (ValidWidth+7)/8; // round up
                     PRUint32  dst_it_stride = dest->mRowBytes - 3*8*iterations;
                     PRUint32  src_it_stride = rgbStride - 3*8*iterations;
                     PRUint32  alpha_it_stride = alphaStride - iterations;

                     for (y=0; y < ValidHeight; ++y)
                     {
                            for (int x=0; x < ValidWidth; x += 8, dst += 24, src += 24)
                            {
                                   PRUint8 alphaPixels = *alpha++;
                                   PRInt32  VW_x = ValidWidth-x;
                                   if (alphaPixels == 0)
                                          continue; // all 8 transparent; jump forward

                                   // 1 or more bits are set, handle dstAlpha now - may not be aligned.
                                   // Are all 8 of these alpha pixels used?
                                   if (x+7 >= ValidWidth)
                                   {
                                          alphaPixels &= 0xff << (8 - VW_x); // no, mask off unused
                                          if (alphaPixels == 0)
                                                 continue;  // no 1 alpha pixels left
                                   }
                                   if (offset == 0)
                                   {
                                          dstAlpha[(aDX+x)>>3] |= alphaPixels; // the cheap aligned case
                                   }
                                   else
                                   {
                                          dstAlpha[(aDX+x)>>3] |= alphaPixels >> offset;
                                          // avoid write if no 1's to write - also avoids going past end of array
                                          // compiler should merge the common sub-expressions
                                          if (alphaPixels << offset_8U)
                                                 dstAlpha[((aDX+x)>>3) + 1] |= alphaPixels << offset_8U;
                                   }
          
                                   if (alphaPixels == 0xff)
                                   {
                                          // fix - could speed up by gathering a run of 0xff's and doing 1 memcpy
                                          // all 8 pixels set; copy and jump forward
                                          memcpy(dst,src,24);
                                          continue;
                                   }
                                   else
                                   {
                                          // else mix of 1's and 0's in alphaPixels, do 1 bit at a time
                                          // Don't go past end of line!
                                          PRUint8 *d = dst, *s = src;
                                          for (PRUint8 aMask = 1<<7, j = 0; aMask && j < VW_x; aMask >>= 1, ++j)
                                          {
                                                 // if this pixel is opaque then copy into the destination image
                                                 if (alphaPixels & aMask)
                                                 {
                                                        // might be faster with *d++ = *s++ 3 times?
                                                        d[0] = s[0];
                                                        d[1] = s[1];
                                                        d[2] = s[2];
                                                        // dstAlpha bit already set
                                                 }
                                                 d += 3;
                                                 s += 3;
                                          }
                                   }
                            }
                            // at end of each line, bump pointers. 
                            dst = dst + dst_it_stride;
                            src = src + src_it_stride;
                            alpha = alpha + alpha_it_stride;
                            dstAlpha += dest->mAlphaRowBytes;
                     }
              }
              break;
              case 0:
              default:
                     for (y=0; y < ValidHeight; ++y)
                            memcpy(dest->mImageBits + (y+aDY)*dest->mRowBytes + 3*aDX, 
                                          rgbPtr + y*rgbStride, 3*ValidWidth);
       }
       // ImageUpdated() won't be called in this case, so we need to mark the destination
       // image as changed. This will cause its data to be copied in the BBitmap when it
       // tries to blit. The source has not been modified, so its status has not changed.
       nsRect rect(aDX, aDY, ValidWidth, ValidHeight);
       dest->ImageUpdated(nsnull, 0, &rect);
       mImageCurrent = PR_TRUE;

       return NS_OK;
}

Here is the call graph for this function:

virtual PRUint8* nsImageBeOS::GetAlphaBits ( ) [inline, virtual]

Get a pointer to the bits for the alpha mask - dwc 2/1/99.

Returns:
address of the alpha mask pixel array

Implements nsIImage.

Definition at line 89 of file nsImageBeOS.h.

{ return mAlphaBits; }
virtual PRInt8 nsImageBeOS::GetAlphaDepth ( ) [inline, virtual]

Get the alpha depth for the image mask - lordpixel 2001/05/16.

Returns:
the alpha mask depth for the image, ie, 0, 1 or 8

Implements nsIImage.

Definition at line 92 of file nsImageBeOS.h.

{ return mAlphaDepth; }
virtual PRInt32 nsImageBeOS::GetAlphaLineStride ( ) [inline, virtual]

Get the number of bytes per scanline for the alpha mask - dwc 2/1/99.

Returns:
The number of bytes in each scanline

Implements nsIImage.

Definition at line 90 of file nsImageBeOS.h.

{ return mAlphaRowBytes; }
virtual void* nsImageBeOS::GetBitInfo ( ) [inline, virtual]

Return information about the bits for this structure - dwc 2/1/99.

Returns:
a bitmap info structure for the Device Dependent Bits

Implements nsIImage.

Definition at line 59 of file nsImageBeOS.h.

{ return nsnull; }
virtual PRUint8* nsImageBeOS::GetBits ( ) [inline, virtual]

Get a pointer to the bits for the pixelmap, only if it is not optimized - dwc 2/1/99.

Returns:
address of the DIB pixel array

Implements nsIImage.

Definition at line 58 of file nsImageBeOS.h.

{ return mImageBits; }
virtual NS_DECL_ISUPPORTS PRInt32 nsImageBeOS::GetBytesPix ( ) [inline, virtual]

Get the number of bytes per pixel for this image - dwc 2/3/99.

Returns:
- the number of bytes per pixel

Implements nsIImage.

Definition at line 55 of file nsImageBeOS.h.

{ return mNumBytesPixel; } 
virtual nsColorMap* nsImageBeOS::GetColorMap ( ) [inline, virtual]

Get the colormap for the nsIImage - dwc 2/1/99.

Returns:
if non null, the colormap for the pixelmap,otherwise the image is not color mapped

Implements nsIImage.

Definition at line 63 of file nsImageBeOS.h.

{ return nsnull; }
virtual PRBool nsImageBeOS::GetHasAlphaMask ( ) [inline, virtual]

Get whether this image has an alpha mask.

Preferable to testing if GetAlphaBits() is non-null. - sfraser 10/19/99

Returns:
PR_TRUE if the image has an alpha mask, PR_FALSE otherwise

Implements nsIImage.

Definition at line 88 of file nsImageBeOS.h.

{ return mAlphaBits != nsnull; }
virtual PRInt32 nsImageBeOS::GetHeight ( ) [inline, virtual]

Get the height for the pixelmap - dwc 2/1/99.

Returns:
The height in pixels for the pixelmap

Implements nsIImage.

Definition at line 56 of file nsImageBeOS.h.

{ return mHeight; }


See documentation in nsIImage.h

Implements nsIImage.

Definition at line 168 of file nsImageBeOS.cpp.

                                       {
  return mDecodedX1 == 0 &&
         mDecodedY1 == 0 &&
         mDecodedX2 == mWidth &&
         mDecodedY2 == mHeight;
}
virtual PRBool nsImageBeOS::GetIsRowOrderTopToBottom ( ) [inline, virtual]

Get whether rows are organized top to bottom, or bottom to top - syd 3/29/99.

Returns:
PR_TRUE if top to bottom, else PR_FALSE

Implements nsIImage.

Definition at line 60 of file nsImageBeOS.h.

{ return PR_TRUE; }
virtual PRInt32 nsImageBeOS::GetLineStride ( ) [inline, virtual]

Get the number of bytes needed to get to the next scanline for the pixelmap - dwc 2/1/99.

Returns:
The number of bytes in each scanline

Implements nsIImage.

Definition at line 61 of file nsImageBeOS.h.

{ return mRowBytes; }
virtual PRInt32 nsImageBeOS::GetWidth ( ) [inline, virtual]

Get the width for the pixelmap - dwc 2/1/99.

Returns:
The width in pixels for the pixelmap

Implements nsIImage.

Definition at line 57 of file nsImageBeOS.h.

{ return mWidth; }
void nsImageBeOS::ImageUpdated ( nsIDeviceContext aContext,
PRUint8  aFlags,
nsRect aUpdateRect 
) [virtual]

Update the nsIImage color table - dwc 2/1/99.

Parameters:
aFlagsUsed to pass in parameters for the update
aUpdateRectThe rectangle to update

Implements nsIImage.

Definition at line 150 of file nsImageBeOS.cpp.

{
       // This should be 0'd out by Draw()
       mFlags = aFlags;
       mImageCurrent = PR_FALSE;

       mDecodedX1 = PR_MIN(mDecodedX1, aUpdateRect->x);
       mDecodedY1 = PR_MIN(mDecodedY1, aUpdateRect->y);

       if (aUpdateRect->YMost() > mDecodedY2)
              mDecodedY2 = aUpdateRect->YMost();
       if (aUpdateRect->XMost() > mDecodedX2)
              mDecodedX2 = aUpdateRect->XMost();
} 

Here is the caller graph for this function:

nsresult nsImageBeOS::Init ( PRInt32  aWidth,
PRInt32  aHeight,
PRInt32  aDepth,
nsMaskRequirements  aMaskRequirements 
) [virtual]

Build and initialize the nsIImage.

Parameters:
aWidthThe width in pixels of the desired pixelmap
aHeightThe height in pixels of the desired pixelmap
aDepthThe number of bits per pixel for the pixelmap
aMaskRequirementsA flag indicating if a alpha mask should be allocated

Implements nsIImage.

Definition at line 97 of file nsImageBeOS.cpp.

{
       // Assumed: Init only gets called once by gfxIImageFrame
       // Only 24 bit depths are supported for the platform independent bits
       if (24 == aDepth) 
       {
              mNumBytesPixel = 3;
       }
       else 
       {
              NS_ASSERTION(PR_FALSE, "unexpected image depth");
              return NS_ERROR_UNEXPECTED;
       }
       
       mWidth = aWidth;
       mHeight = aHeight;
       mDepth = aDepth;
       mRowBytes = (mWidth * mDepth) >> 5;
       if (((PRUint32)mWidth * mDepth) & 0x1F) 
              mRowBytes++;
       mRowBytes <<= 2;
       mSizeImage = mRowBytes * mHeight;

       mImageBits = new PRUint8[mSizeImage];

       switch (aMaskRequirements) 
       {
              case nsMaskRequirements_kNeeds1Bit:
                     mAlphaRowBytes = (aWidth + 7) / 8;
                     mAlphaDepth = 1;
                     // 32-bit align each row
                     mAlphaRowBytes = (mAlphaRowBytes + 3) & ~0x3;
                     mAlphaBits = new PRUint8[mAlphaRowBytes * aHeight];
                     memset(mAlphaBits, 255, mAlphaRowBytes * aHeight);
                     break;
              case nsMaskRequirements_kNeeds8Bit:
                     mAlphaRowBytes = aWidth;
                     mAlphaDepth = 8;
                     // 32-bit align each row
                     mAlphaRowBytes = (mAlphaRowBytes + 3) & ~0x3;
                     mAlphaBits = new PRUint8[mAlphaRowBytes * aHeight];
                     break;
       }
       
       return NS_OK;
}

Here is the call graph for this function:

virtual PRBool nsImageBeOS::IsOptimized ( ) [inline, virtual]

Definition at line 85 of file nsImageBeOS.h.

{ return mOptimized; }

LockImagePixels Lock the image pixels so that we can access them directly, with safely.

May be a noop on some platforms.

aMaskPixels = PR_TRUE for the mask, PR_FALSE for the image

Must be balanced by a call to UnlockImagePixels().

- sfraser 10/18/99

Returns:
error result

Implements nsIImage.

Definition at line 476 of file nsImageBeOS.cpp.

{
       // we may need some sort of syncing here in future
       return NS_OK;
}
nsresult nsImageBeOS::Optimize ( nsIDeviceContext aContext) [virtual]

Converted this pixelmap to an optimized pixelmap for the device - dwc 2/1/99.

Parameters:
aContextThe device to optimize for
Returns:
the result of the operation, if NS_OK, then the pixelmap is optimized

Implements nsIImage.

Definition at line 450 of file nsImageBeOS.cpp.

{
       if (!mOptimized) 
       {
              // Make sure the BBitmap is up to date
              CreateImage(NULL);
              
              // Release Mozilla-specific data
              if (nsnull != mImageBits) 
              {
                     delete [] mImageBits;
                     mImageBits = nsnull;
              }
              if (nsnull != mAlphaBits) 
              {
                     delete [] mAlphaBits;
                     mAlphaBits = nsnull;
              }
              
              mOptimized = PR_TRUE;
       }
       return NS_OK;
}

Here is the call graph for this function:

UnlockImagePixels Unlock the image pixels.

May be a noop on some platforms.

Should balance an earlier call to LockImagePixels().

aMaskPixels = PR_TRUE for the mask, PR_FALSE for the image

- sfraser 10/18/99

Returns:
error result

Implements nsIImage.

Definition at line 483 of file nsImageBeOS.cpp.

{
       return NS_OK;
}

Member Data Documentation

Definition at line 121 of file nsImageBeOS.h.

PRInt8 nsImageBeOS::mAlphaDepth [private]

Definition at line 123 of file nsImageBeOS.h.

Definition at line 122 of file nsImageBeOS.h.

Definition at line 115 of file nsImageBeOS.h.

Definition at line 117 of file nsImageBeOS.h.

Definition at line 116 of file nsImageBeOS.h.

Definition at line 118 of file nsImageBeOS.h.

Definition at line 110 of file nsImageBeOS.h.

Definition at line 126 of file nsImageBeOS.h.

Definition at line 109 of file nsImageBeOS.h.

BBitmap* nsImageBeOS::mImage [private]

Definition at line 105 of file nsImageBeOS.h.

Definition at line 107 of file nsImageBeOS.h.

Definition at line 128 of file nsImageBeOS.h.

PRInt8 nsImageBeOS::mNumBytesPixel [private]

Definition at line 127 of file nsImageBeOS.h.

Definition at line 129 of file nsImageBeOS.h.

Definition at line 111 of file nsImageBeOS.h.

Definition at line 112 of file nsImageBeOS.h.

BBitmap* nsImageBeOS::mTileBitmap [private]

Definition at line 106 of file nsImageBeOS.h.

Definition at line 108 of file nsImageBeOS.h.


The documentation for this class was generated from the following files: