Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes
nsImageOS2 Class Reference

#include <nsImageOS2.h>

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

List of all members.

Public Member Functions

 nsImageOS2 ()
 ~nsImageOS2 ()
virtual NS_DECL_ISUPPORTS PRInt32 GetBytesPix ()
virtual PRInt32 GetHeight ()
 Get the height for the pixelmap - 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 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 PRInt32 GetLineStride ()
 Get the number of bytes needed to get to the next scanline for the pixelmap - dwc 2/1/99.
virtual PRBool GetHasAlphaMask ()
 Get whether this image has an alpha mask.
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.
virtual nsColorMapGetColorMap ()
 Get the colormap for the nsIImage - dwc 2/1/99.
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 nsresult Optimize (nsIDeviceContext *aContext)
 Converted this pixelmap to an optimized pixelmap for the device - dwc 2/1/99.
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.
NS_IMETHOD DrawTile (nsIRenderingContext &aContext, nsIDrawingSurface *aSurface, PRInt32 aSXOffset, PRInt32 aSYOffset, PRInt32 aPadX, PRInt32 aPadY, const nsRect &aTileRect)
 Draw a tiled version of the bitmap.
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.
virtual PRInt8 GetAlphaDepth ()
 Return the header size of the Device Independent Bitmap(DIB).
voidGetBitInfo ()
 Get the DIB specific informations for this bitmap.
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.

Private Member Functions

void CleanUp (PRBool aCleanUpAll)
 Clean up the memory used nsImageWin.
void DrawComposited24 (unsigned char *aBits, PRUint8 *aImageRGB, PRUint32 aStrideRGB, PRUint8 *aImageAlpha, PRUint32 aStrideAlpha, int aWidth, int aHeight)
 
This is a helper routine to do the blending for the Draw method
NS_IMETHODIMP UpdateImageBits (HPS mPS)
void NS2PM_ININ (const nsRect &in, RECTL &rcl)
void CreateBitmaps (nsDrawingSurfaceOS2 *surf)
void BuildTile (HPS hpsTile, PRUint8 *pImageBits, PBITMAPINFO2 pBitmapInfo, nscoord aTileWidth, nscoord aTileHeight, float scale)

Static Private Member Functions

static void BuildBlenderLookup (void)
static PRUint8 FAST_BLEND (PRUint8 Source, PRUint8 Dest, PRUint8 Alpha)

Private Attributes

BITMAPINFO2 * mInfo
PRUint32 mDeviceDepth
PRInt32 mRowBytes
PRUint8mImageBits
PRBool mIsOptimized
nsColorMapmColorMap
nsRect mDecodedRect
PRUint8mAlphaBits
PRInt8 mAlphaDepth
PRInt16 mARowBytes

Static Private Attributes

static PRUint8 gBlenderLookup [65536]
static PRBool gBlenderReady = PR_FALSE

Detailed Description

Definition at line 54 of file nsImageOS2.h.


Constructor & Destructor Documentation

Definition at line 128 of file nsImageOS2.cpp.

Here is the call graph for this function:


Member Function Documentation

void nsImageOS2::BuildBlenderLookup ( void  ) [static, private]

Definition at line 269 of file nsImageOS2.cpp.

{
  for (int y = 0 ; y < 256 ; y++)
    for (int x = 0 ; x < 256 ; x++)
      gBlenderLookup [y * 256 + x] = y * x / 255;

  gBlenderReady = PR_TRUE;
}
void nsImageOS2::BuildTile ( HPS  hpsTile,
PRUint8 pImageBits,
PBITMAPINFO2  pBitmapInfo,
nscoord  aTileWidth,
nscoord  aTileHeight,
float  scale 
) [private]

Definition at line 666 of file nsImageOS2.cpp.

{
   // If bitmap not fully loaded, then first fill area with background color.
   if (nsRect (0, 0, mInfo->cx, mInfo->cy) != mDecodedRect)
   {
      POINTL pt1 = { 0, 0 };                                                   // LL - in
      POINTL pt2 = { mInfo->cx, mInfo->cy };                                   // UR - ex

#ifdef DEBUG
      GFX (::GpiSetColor (hpsTile, MK_RGB (255, 255, 0)), FALSE);              // yellow eye-catcher
#else
      GFX (::GpiSetColor (hpsTile, MK_RGB (255, 255, 255)), FALSE);
#endif
      GFX (::GpiMove (hpsTile, &pt1), FALSE);
      GFX (::GpiBox (hpsTile, DRO_FILL, &pt2, 0, 0), GPI_ERROR);
   }

   // Set up blit coord array
   POINTL aptl [4] = { {mDecodedRect.x, mDecodedRect.y},                         // TLL - in
                       {mDecodedRect.XMost () - 1, mDecodedRect.YMost () - 1},   // TUR - in
                       {mDecodedRect.x, mDecodedRect.y},                         // SLL - in
                       {mDecodedRect.XMost (), mDecodedRect.YMost ()} };         // SUR - ex

   // Scale up
   aptl[0].x = (LONG)(aptl[0].x * scale);
   aptl[0].y = (LONG)(aptl[0].y * scale);
   aptl[1].x = (LONG)(mDecodedRect.XMost() * scale) - 1;
   aptl[1].y = (LONG)(mDecodedRect.YMost() * scale) - 1;
   
   // Draw bitmap once into temporary PS
   GFX (::GpiDrawBits (hpsTile, (PBYTE)pImageBits, pBitmapInfo, 4, aptl, ROP_SRCCOPY, BBO_IGNORE), GPI_ERROR);

   PRInt32 DestWidth  = (PRInt32)(mInfo->cx * scale);
   PRInt32 DestHeight = (PRInt32)(mInfo->cy * scale);

   // Copy bitmap horizontally, doubling each time
   if (DestWidth > 0) {
      while (DestWidth < aTileWidth)
      {
         POINTL aptlCopy [3] = { {DestWidth, 0},                     // TLL - in
                                 {2 * DestWidth, DestHeight},        // TUR - ex
                                 {0, 0} };                           // SLL - in

         GFX (::GpiBitBlt (hpsTile, hpsTile, 3, aptlCopy, ROP_SRCCOPY, 0L), GPI_ERROR);
         DestWidth *= 2;
      }
   }

   // Copy bitmap vertically, doubling each time
   if (DestHeight > 0) {
      while (DestHeight < aTileHeight)
      {
         POINTL aptlCopy [4] = { {0, DestHeight},                    // TLL - in
                                 {DestWidth, 2 * DestHeight},        // TUR - ex
                                 {0, 0} };                           // SLL - in

         GFX (::GpiBitBlt (hpsTile, hpsTile, 3, aptlCopy, ROP_SRCCOPY, 0L), GPI_ERROR);
         DestHeight *= 2;
      }
   }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsImageOS2::CleanUp ( PRBool  aCleanUpAll) [private]

Clean up the memory used nsImageWin.

dc - 10/29/98

Parameters:
aCleanUpAll- if True, all the memory used will be released otherwise just clean up the DIB memory

Definition at line 201 of file nsImageOS2.cpp.

{
   // OS2TODO to handle aCleanUpAll param

   if( mImageBits) {
      delete [] mImageBits; 
      mImageBits = 0;
   }
   if( mInfo) {
      free( mInfo);
      mInfo = 0;
   }
   if( mColorMap) {
      if( mColorMap->Index)
         delete [] mColorMap->Index;
      delete mColorMap;
      mColorMap = 0;
   }
   if( mAlphaBits) {
      delete [] mAlphaBits; 
      mAlphaBits = 0;
   }
}

Here is the caller graph for this function:

nsresult nsImageOS2::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 278 of file nsImageOS2.cpp.

{
   return Draw( aContext, aSurface,
                0, 0, mInfo->cx, mInfo->cy,
                aX, aY, aWidth, aHeight);
}

Here is the caller graph for this function:

NS_IMETHODIMP nsImageOS2::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 314 of file nsImageOS2.cpp.

{
  nsresult rv = NS_OK;

   PRInt32 origSHeight = aSHeight, origDHeight = aDHeight;
   PRInt32 origSWidth = aSWidth, origDWidth = aDWidth;

   if (mInfo == nsnull || aSWidth < 0 || aDWidth < 0 || aSHeight < 0 || aDHeight < 0) 
      return NS_ERROR_FAILURE;

   if (0 == aSWidth || 0 == aDWidth || 0 == aSHeight || 0 == aDHeight)
      return NS_OK;

   // limit the size of the blit to the amount of the image read in
   PRInt32 aSX2 = aSX + aSWidth;

   if (aSX2 > mDecodedRect.XMost()) 
      aSX2 = mDecodedRect.XMost();

   if (aSX < mDecodedRect.x) {
      aDX += (mDecodedRect.x - aSX) * origDWidth / origSWidth;
      aSX = mDecodedRect.x;
   }
  
   aSWidth = aSX2 - aSX;
   aDWidth -= (origSWidth - aSWidth) * origDWidth / origSWidth;
  
   if (aSWidth <= 0 || aDWidth <= 0)
      return NS_OK;

   PRInt32 aSY2 = aSY + aSHeight;

   if (aSY2 > mDecodedRect.YMost())
      aSY2 = mDecodedRect.YMost();

   if (aSY < mDecodedRect.y) {
      aDY += (mDecodedRect.y - aSY) * origDHeight / origSHeight;
      aSY = mDecodedRect.y;
   }

   aSHeight = aSY2 - aSY;
   aDHeight -= (origSHeight - aSHeight) * origDHeight / origSHeight;

   if (aSHeight <= 0 || aDHeight <= 0)
      return NS_OK;

   nsDrawingSurfaceOS2 *surf = (nsDrawingSurfaceOS2*) aSurface;
 

   nsRect trect( aDX, aDY, aDWidth, aDHeight);
   RECTL  rcl;
   surf->NS2PM_ININ (trect, rcl);

   // Set up blit coord array
   POINTL aptl[ 4] = { { rcl.xLeft, rcl.yBottom },              // TLL
                       { rcl.xRight, rcl.yTop },                // TUR
                       { aSX, mInfo->cy - (aSY + aSHeight) },   // SLL
                       { aSX + aSWidth, mInfo->cy - aSY } };    // SUR
                       
   PRBool fPrinting = PR_FALSE;
   nsIDeviceContext*  context;
   aContext.GetDeviceContext(context);
   if (((nsDeviceContextOS2 *)context)->mPrintDC) {
      fPrinting = PR_TRUE;
   }

   if( mAlphaDepth == 0)
   {
      // no transparency, just blit it
      GFX (::GpiDrawBits (surf->GetPS (), mImageBits, mInfo, 4, aptl, ROP_SRCCOPY, BBO_IGNORE), GPI_ERROR);
   }
   else if( mAlphaDepth == 1)
   {
      if (!fPrinting) {
         // > The transparent areas of the mask are coloured black (0).
         // > the transparent areas of the pixmap are coloured black (0).
         // > Note this does *not* mean that all black pels are transparent!
         // >
         // > Thus all we need to do is AND the mask onto the target, taking
         // > out pels that are not transparent, and then OR the image onto
         // > the target.
         // >
         // > For monochrome bitmaps GPI replaces 1 with IMAGEBUNDLE foreground
         // > color and 0 with background color. To make this work with ROP_SRCAND
         // > we set foreground to black and background to white. Thus AND with 
         // > 1 (opaque) in mask maps to AND with IMAGEBUNDLE foreground (which is 0)
         // > always gives 0 - clears opaque region to zeros. 
   
         // Apply mask to target, clear pels we will fill in from the image
         MONOBITMAPINFO MaskBitmapInfo (mInfo);
         GFX (::GpiDrawBits (surf->GetPS (), mAlphaBits, MaskBitmapInfo, 4, aptl, ROP_SRCAND, BBO_IGNORE), GPI_ERROR);
   
         // Now combine image with target
         GFX (::GpiDrawBits (surf->GetPS (), mImageBits, mInfo, 4, aptl, ROP_SRCPAINT, BBO_IGNORE), GPI_ERROR);
      } else {
         // Find the compatible device context and create a memory one
         HDC hdcCompat = GFX (::GpiQueryDevice (surf->GetPS ()), HDC_ERROR);
   
         rv = NS_ERROR_FAILURE;
       
         // create non-inclusive rect for GpiBitBlt
         RECTL dest;
         surf->NS2PM_INEX (trect, dest);
   
         DEVOPENSTRUC dop = { 0, 0, 0, 0, 0 };
         HDC MemDC = ::DevOpenDC( (HAB)0, OD_MEMORY, "*", 5, (PDEVOPENDATA) &dop, hdcCompat);
   
         if( MemDC != DEV_ERROR )
         {   
           // create the PS
           SIZEL sizel = { 0, 0 };
           HPS MemPS = GFX (::GpiCreatePS (0, MemDC, &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC), GPI_ERROR);
   
           if( MemPS != GPI_ERROR )
           {
             GFX (::GpiCreateLogColorTable (MemPS, 0, LCOLF_RGB, 0, 0, 0), FALSE);
   
             // now create a bitmap of the right size
             HBITMAP hMemBmp;
             BITMAPINFOHEADER2 bihMem = { 0 };
   
             bihMem.cbFix = sizeof (BITMAPINFOHEADER2);
             bihMem.cx = aSWidth;
             bihMem.cy = aSHeight;
             bihMem.cPlanes = 1;
             LONG lBitCount = 0;
             GFX (::DevQueryCaps( hdcCompat, CAPS_COLOR_BITCOUNT, 1, &lBitCount), FALSE);
             lBitCount = 24; // For printing
             bihMem.cBitCount = lBitCount;
             
             hMemBmp = GFX (::GpiCreateBitmap (MemPS, &bihMem, 0, 0, 0), GPI_ERROR);
   
             if( hMemBmp != GPI_ERROR )
             {
               GFX (::GpiSetBitmap (MemPS, hMemBmp), HBM_ERROR);
               zeroStack(10);
               GpiErase(MemPS);
   
               // Now combine image with target
               // Set up blit coord array
               POINTL aptlNew[ 4] = { { 0, 0 },              // TLL
                                      { bihMem.cx, bihMem.cy },                // TUR
                                      { aSX, mInfo->cy - (aSY + aSHeight) },   // SLL
                                      { aSX + aSWidth+1, mInfo->cy - aSY+1 } };    // SUR
   
               // Apply mask to target, clear pels we will fill in from the image
               MONOBITMAPINFO MaskBitmapInfo (mInfo);                                   
               GFX (::GpiDrawBits (MemPS, mAlphaBits, MaskBitmapInfo, 4, aptlNew, ROP_SRCAND, BBO_IGNORE), GPI_ERROR);
          
               // Now combine image with target
               GFX (::GpiDrawBits (MemPS, mImageBits, mInfo, 4, aptlNew, ROP_SRCPAINT, BBO_IGNORE), GPI_ERROR);
   
               // Transfer bitmap from memory bitmap back to device
               POINTL aptlMemToDev [4] = { {dest.xLeft, dest.yBottom},   // TLL - device (Dx1, Dy2)
                                           {dest.xRight, dest.yTop},     // TUR - device (Dx2, Dy1)
                                           {0, 0},                       // SLL - mem bitmap (0, 0)
                                           {bihMem.cx, bihMem.cy} };      // SUR - mem bitmap (cx, cy)
   
               GFX (::GpiBitBlt (surf->GetPS (), MemPS, 4, aptlMemToDev, ROP_SRCCOPY, BBO_IGNORE), GPI_ERROR);
               
               rv = NS_OK;
                                                                   
               GFX (::GpiSetBitmap (MemPS, NULLHANDLE), HBM_ERROR);
               GFX (::GpiDeleteBitmap (hMemBmp), FALSE);
             }
           
             GFX (::GpiDestroyPS (MemPS), FALSE);
           }
       
           ::DevCloseDC (MemDC);
         }
      }
   } else
   {
      // Find the compatible device context and create a memory one
      HDC hdcCompat = GFX (::GpiQueryDevice (surf->GetPS ()), HDC_ERROR);

      rv = NS_ERROR_FAILURE;
    
       // create non-inclusive rect for GpiBitBlt
      RECTL dest;
      surf->NS2PM_INEX (trect, dest);

      DEVOPENSTRUC dop = { 0, 0, 0, 0, 0 };
      HDC MemDC = ::DevOpenDC( (HAB)0, OD_MEMORY, "*", 5, (PDEVOPENDATA) &dop, hdcCompat);

      if( MemDC != DEV_ERROR )
      {   
        // create the PS
        SIZEL sizel = { 0, 0 };
        HPS MemPS = GFX (::GpiCreatePS (0, MemDC, &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC), GPI_ERROR);

        if( MemPS != GPI_ERROR )
        {
          GFX (::GpiCreateLogColorTable (MemPS, 0, LCOLF_RGB, 0, 0, 0), FALSE);

          // now create a bitmap of the right size
          HBITMAP hMemBmp;
          BITMAPINFOHEADER2 bihMem = { 0 };

          bihMem.cbFix = sizeof (BITMAPINFOHEADER2);
          bihMem.cx = aDWidth;
          bihMem.cy = aDHeight;
          bihMem.cPlanes = 1;
          LONG lBitCount = 0;
          GFX (::DevQueryCaps( hdcCompat, CAPS_COLOR_BITCOUNT, 1, &lBitCount), FALSE);
          if (!fPrinting)
          {
            bihMem.cBitCount = (USHORT) lBitCount;
          }
          else  // Printing
          {
            // bihMem.cBitCount = (USHORT) lBitCount;
            bihMem.cBitCount = 24;
          }

          hMemBmp = GFX (::GpiCreateBitmap (MemPS, &bihMem, 0, 0, 0), GPI_ERROR);

          if( hMemBmp != GPI_ERROR )
          {
            GFX (::GpiSetBitmap (MemPS, hMemBmp), HBM_ERROR);

            POINTL aptlDevToMem [4] = { {0, 0},                       // TLL - mem bitmap (0, 0)
                                        {bihMem.cx, bihMem.cy},       // TUR - mem bitmap (cx, cy)
                                        {dest.xLeft, dest.yBottom},   // SLL - device (Dx1, Dy2)
                                        {dest.xRight, dest.yTop} };   // SUR - device (Dx2, Dy1)

            GFX (::GpiBitBlt (MemPS, surf->GetPS (), 4, aptlDevToMem, ROP_SRCCOPY, BBO_IGNORE), GPI_ERROR);

            // Now we want direct access to bitmap raw data. 
            // Must copy data again because GpiSetBitmap doesn't provide pointer to
            // start of raw bit data ?? (DJ)
            BITMAPINFOHEADER2 bihDirect = { 0 };
            bihDirect.cbFix   = sizeof (BITMAPINFOHEADER2);
            bihDirect.cPlanes = 1;
            bihDirect.cBitCount = 24;

            int RawDataSize = bihMem.cy * RASWIDTH (bihMem.cx, 24);
            PRUint8* pRawBitData = (PRUint8*)malloc (RawDataSize);

            if( pRawBitData )
            {
              LONG rc = GFX (::GpiQueryBitmapBits (MemPS, 0, bihMem.cy, (PBYTE)pRawBitData, (PBITMAPINFO2)&bihDirect), GPI_ALTERROR);

              if( rc != GPI_ALTERROR )
              {
              PRUint8 *imageRGB, *imageAlpha;
              PRUint32 strideRGB, strideAlpha;

              /* Both scaled and unscaled images come through this code - save
                 work if not scaling */
              if ((aSWidth != aDWidth) || (aSHeight != aDHeight)) {
                /* Scale our image to match */
                imageRGB = (PRUint8 *)nsMemory::Alloc(3*aDWidth*aDHeight);
                imageAlpha = (PRUint8 *)nsMemory::Alloc(aDWidth*aDHeight);
                    
                if (!imageRGB || !imageAlpha) {
                  if (imageRGB)
                    nsMemory::Free(imageRGB);
                  if (imageAlpha)
                    nsMemory::Free(imageAlpha);

                  free(pRawBitData);
                  GFX (::GpiSetBitmap (MemPS, NULLHANDLE), HBM_ERROR);
                  GFX (::GpiDeleteBitmap (hMemBmp), FALSE);
                  GFX (::GpiDestroyPS (MemPS), FALSE);
                  ::DevCloseDC (MemDC);

                  return NS_ERROR_FAILURE;
                }
                    
                strideRGB = 3 * aDWidth;
                strideAlpha = aDWidth;
                RectStretch(aSWidth, aSHeight, aDWidth, aDHeight, 0, 0, aDWidth-1, aDHeight-1,
                           mImageBits, mRowBytes, imageRGB, strideRGB, 24);
                RectStretch(aSWidth, aSHeight, aDWidth, aDHeight, 0, 0, aDWidth-1, aDHeight-1,
                           mAlphaBits, mARowBytes, imageAlpha, strideAlpha, 8);
              } else {
                  PRUint32 srcy = mInfo->cy - (aSY + aSHeight);
                imageRGB = mImageBits + srcy * mRowBytes + aSX * 3;
                imageAlpha = mAlphaBits + srcy * mARowBytes + aSX;
                strideRGB = mRowBytes;
                strideAlpha = mARowBytes;
              }

              /* Do composite */
              DrawComposited24(pRawBitData, imageRGB, strideRGB, imageAlpha, strideAlpha,
                             aDWidth, aDHeight);
                
              if ((aSWidth != aDWidth) || (aSHeight != aDHeight)) {
                /* Free scaled images */
                nsMemory::Free(imageRGB);
                nsMemory::Free(imageAlpha);
              }
        
                // Copy modified memory back to memory bitmap
                GFX (::GpiSetBitmapBits (MemPS, 0, bihMem.cy, (PBYTE)pRawBitData, (PBITMAPINFO2)&bihDirect), GPI_ALTERROR);
              
                // Transfer bitmap from memory bitmap back to device
                POINTL aptlMemToDev [4] = { {dest.xLeft, dest.yBottom},   // TLL - device (Dx1, Dy2)
                                            {dest.xRight, dest.yTop},     // TUR - device (Dx2, Dy1)
                                            {0, 0},                       // SLL - mem bitmap (0, 0)
                                            {bihMem.cx, bihMem.cy} };      // SUR - mem bitmap (cx, cy)

                GFX (::GpiBitBlt (surf->GetPS (), MemPS, 4, aptlMemToDev, ROP_SRCCOPY, BBO_IGNORE), GPI_ERROR);
            
                rv = NS_OK;
              }

              free (pRawBitData);
            }

            GFX (::GpiSetBitmap (MemPS, NULLHANDLE), HBM_ERROR);
            GFX (::GpiDeleteBitmap (hMemBmp), FALSE);
          }
        
          GFX (::GpiDestroyPS (MemPS), FALSE);
        }
    
        ::DevCloseDC (MemDC);
      }
   }

   return rv;
}

Here is the call graph for this function:

void nsImageOS2::DrawComposited24 ( unsigned char *  aBits,
PRUint8 aImageRGB,
PRUint32  aStrideRGB,
PRUint8 aImageAlpha,
PRUint32  aStrideAlpha,
int  aWidth,
int  aHeight 
) [private]


This is a helper routine to do the blending for the Draw method

Definition at line 291 of file nsImageOS2.cpp.

{
  PRInt32 targetRowBytes = ((aWidth * 3) + 3) & ~3;

  for (int y = 0; y < aHeight; y++) {
    unsigned char *targetRow = aBits + y * targetRowBytes;
    unsigned char *imageRow = aImageRGB + y * aStrideRGB;
    unsigned char *alphaRow = aImageAlpha + y * aStrideAlpha;

    for (int x = 0; x < aWidth;
         x++, targetRow += 3, imageRow += 3, alphaRow++) {
      unsigned alpha = *alphaRow;
      MOZ_BLEND(targetRow[0], targetRow[0], imageRow[0], alpha);
      MOZ_BLEND(targetRow[1], targetRow[1], imageRow[1], alpha);
      MOZ_BLEND(targetRow[2], targetRow[2], imageRow[2], alpha);
    }
  }
}

Here is the caller graph for this function:

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

Draw a tiled version of the bitmap.


See documentation in nsIRenderingContext.h 3/16/00 dwc

Parameters:
aSurfacethe surface to blit to
aSXOffsetOffset from image's upper right corner that will be located at
aSYOffsetupper right corner of filled area
aTileRectArea which must be filled with tiled image
Returns:
if TRUE, no errors

Implements nsIImage.

Definition at line 733 of file nsImageOS2.cpp.

{
   if (aTileRect.IsEmpty ())
      return NS_OK;

   PRBool didTile = PR_FALSE;
   PRInt32 ImageWidth = mInfo->cx;
   PRInt32 ImageHeight = mInfo->cy;
   PRBool padded = (aPadX || aPadY);

   // Get the scale - if greater than 1 then do slow tile which
   nsIDeviceContext *theDeviceContext;
   float scale;
   aContext.GetDeviceContext(theDeviceContext);
   theDeviceContext->GetCanonicalPixelScale(scale);

   nsRect ValidRect (0, 0, ImageWidth, ImageHeight);
   ValidRect.IntersectRect (ValidRect, mDecodedRect);
   PRInt32 DestScaledWidth = PR_MAX(PRInt32(ValidRect.width * scale), 1);
   PRInt32 DestScaledHeight = PR_MAX(PRInt32(ValidRect.height * scale), 1);

   nsRect DrawRect = aTileRect;
   DrawRect.MoveBy (-aSXOffset, -aSYOffset);
   DrawRect.SizeBy (aSXOffset, aSYOffset);

   // Don't bother tiling if we only have to draw the bitmap a couple of times
   // Can't tile with 8bit alpha masks because need access destination bitmap values
   if ((ImageWidth < DrawRect.width / 2 || ImageHeight < DrawRect.height / 2) &&
       (ImageWidth <= MAX_BUFFER_WIDTH) && (ImageHeight <= MAX_BUFFER_HEIGHT) &&
       mAlphaDepth <= 1 &&
       !padded)
   {
      nsDrawingSurfaceOS2 *surf = (nsDrawingSurfaceOS2*) aSurface;

      // Find the compatible device context and create a memory one
      HDC hdcCompat = GFX (::GpiQueryDevice (surf->GetPS ()), HDC_ERROR);

      DEVOPENSTRUC dop = { 0, 0, 0, 0, 0 };
      HDC MemDC = GFX (::DevOpenDC( (HAB)0, OD_MEMORY, "*", 5, (PDEVOPENDATA) &dop, hdcCompat), DEV_ERROR);

      if( DEV_ERROR != MemDC)
      {
         // create the PS
         SIZEL sizel = { 0, 0 };
         HPS MemPS = GFX (::GpiCreatePS (0, MemDC, &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC), GPI_ERROR);

         if( GPI_ERROR != MemPS)
         {
            GFX (::GpiCreateLogColorTable (MemPS, 0, LCOLF_RGB, 0, 0, 0), FALSE);

            // now create a bitmap of the right size
            BITMAPINFOHEADER2 hdr = { 0 };

            hdr.cbFix = sizeof( BITMAPINFOHEADER2);
            // Maximum size of tiled area (could do this better)
            PRInt32 endWidth = DestScaledWidth;
            while( endWidth < DrawRect.width)
               endWidth *= 2;

            PRInt32 endHeight = DestScaledHeight;
            while( endHeight < DrawRect.height)
               endHeight *= 2;

            hdr.cx = endWidth;
            hdr.cy = endHeight;
            hdr.cPlanes = 1;

            // find bitdepth
            LONG lBitCount = 0;
            GFX (::DevQueryCaps( hdcCompat, CAPS_COLOR_BITCOUNT, 1, &lBitCount), FALSE);
            hdr.cBitCount = (USHORT) lBitCount;

            RECTL  rcl;
            surf->NS2PM_INEX (aTileRect, rcl);

            POINTL aptlTile [3] = { {rcl.xLeft, rcl.yBottom},                                 // TLL - in
                                    {rcl.xRight, rcl.yTop},                                   // TUR - ex
                                    {aSXOffset, endHeight - aTileRect.height - aSYOffset} };  // SLL - in
            // For some reason offset does not work well with scaled output
            if (scale > 1.0)
            {
               aptlTile[2].x = 0;
               aptlTile[2].y = endHeight - aTileRect.height;
            }
            HBITMAP hMemBmp = GFX (::GpiCreateBitmap (MemPS, &hdr, 0, 0, 0), GPI_ERROR);
            if (hMemBmp != GPI_ERROR)
            {
               LONG ImageROP = ROP_SRCCOPY;

               GFX (::GpiSetBitmap (MemPS, hMemBmp), HBM_ERROR);

               if (mAlphaDepth == 1)
               {
                  LONG BlackColor = GFX (::GpiQueryColorIndex (MemPS, 0, MK_RGB (0x00, 0x00, 0x00)), GPI_ALTERROR);    // CLR_BLACK;
                  LONG WhiteColor = GFX (::GpiQueryColorIndex (MemPS, 0, MK_RGB (0xFF, 0xFF, 0xFF)), GPI_ALTERROR);    // CLR_WHITE;

                  // WORKAROUND:
                  // PostScript drivers up to version 30.732 have problems with GpiQueryColorIndex.
                  // If we are in LCOL_RGB mode it doesn't return passed RGB color but returns error instead.

                  if (BlackColor == GPI_ALTERROR) BlackColor = MK_RGB (0x00, 0x00, 0x00);
                  if (WhiteColor == GPI_ALTERROR) WhiteColor = MK_RGB (0xFF, 0xFF, 0xFF);

                  // Set image foreground and background colors. These are used in transparent images for blitting 1-bit masks.
                  // To invert colors on ROP_SRCAND we map 1 to black and 0 to white
                  IMAGEBUNDLE ib;
                  ib.lColor     = BlackColor;        // map 1 in mask to 0x000000 (black) in destination
                  ib.lBackColor = WhiteColor;        // map 0 in mask to 0xFFFFFF (white) in destination
                  ib.usMixMode  = FM_OVERPAINT;
                  ib.usBackMixMode = BM_OVERPAINT;
                  GFX (::GpiSetAttrs (MemPS, PRIM_IMAGE, IBB_COLOR | IBB_BACK_COLOR | IBB_MIX_MODE | IBB_BACK_MIX_MODE, 0, (PBUNDLE)&ib), FALSE);

                  MONOBITMAPINFO MaskBitmapInfo (mInfo);
                  BuildTile (MemPS, mAlphaBits, MaskBitmapInfo, DrawRect.width, DrawRect.height, scale);

                  // Apply mask to target, clear pels we will fill in from the image
                  GFX (::GpiBitBlt (surf->GetPS (), MemPS, 3, aptlTile, ROP_SRCAND, 0L), GPI_ERROR);

                  ImageROP = ROP_SRCPAINT;    // Original image must be combined with mask
               }

               BuildTile (MemPS, mImageBits, mInfo, DrawRect.width, DrawRect.height, scale);

               GFX (::GpiBitBlt (surf->GetPS (), MemPS, 3, aptlTile, ImageROP, 0L), GPI_ERROR);

               didTile = PR_TRUE;

               // Must deselect bitmap from PS before freeing bitmap and PS.
               GFX (::GpiSetBitmap (MemPS, NULLHANDLE), HBM_ERROR);
               GFX (::GpiDeleteBitmap (hMemBmp), FALSE);
            }
            GFX (::GpiDestroyPS (MemPS), FALSE);
         }
         GFX (::DevCloseDC (MemDC), DEV_ERROR);
      }
   }

   // If we failed to tile the bitmap, then use the old, slow, reliable way
   if( didTile == PR_FALSE)
   {
      // put the DestRect into absolute coordintes of the device
      PRInt32 y0 = aTileRect.y - aSYOffset;
      PRInt32 x0 = aTileRect.x - aSXOffset;
      PRInt32 y1 = aTileRect.y + aTileRect.height;
      PRInt32 x1 = aTileRect.x + aTileRect.width;

      // this is the width and height of the image in pixels
      // we need to map this to the pixel height of the device
      nscoord ScaledTileWidth = PR_MAX(PRInt32(ImageWidth*scale), 1);
      nscoord ScaledTileHeight = PR_MAX(PRInt32(ImageHeight*scale), 1);

      for (PRInt32 y = y0; y < y1; y += (PRInt32)(ScaledTileHeight + aPadY * scale))
      {
        for (PRInt32 x = x0; x < x1;  x += (PRInt32)(ScaledTileWidth + aPadX * scale))
        {
          Draw(aContext, aSurface,
               0, 0, PR_MIN(ValidRect.width, x1 - x), PR_MIN(ValidRect.height, y1 - y),
               x, y, PR_MIN(DestScaledWidth, x1-x), PR_MIN(DestScaledHeight, y1 - y));
        }
      }
   }
   return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsImageOS2::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 937 of file nsImageOS2.cpp.

{
  nsresult rc = NS_OK;

  DEVOPENSTRUC dop = { 0, 0, 0, 0, 0 };
  SIZEL sizel = { 0, 0 };

  if (mInfo == nsnull || aDWidth < 0 || aDHeight < 0) 
    return NS_ERROR_FAILURE;

  if (0 == aDWidth || 0 == aDHeight)
    return NS_OK;

  // Create a memory DC that is compatible with the screen
  HDC MemDC = GFX (::DevOpenDC( 0/*hab*/, OD_MEMORY, "*", 5,
                   (PDEVOPENDATA) &dop, (HDC)0), DEV_ERROR);

  // create the PS
  HPS MemPS = GFX (::GpiCreatePS (0/*hab*/, MemDC, &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC), GPI_ERROR);

  GFX (::GpiCreateLogColorTable (MemPS, 0, LCOLF_RGB, 0, 0, 0), FALSE);

  nsImageOS2* destImg = NS_STATIC_CAST(nsImageOS2*, aDstImage); 

  HBITMAP hTmpBitmap = GFX (::GpiCreateBitmap (MemPS, (PBITMAPINFOHEADER2)destImg->mInfo,
                                               CBM_INIT, (PBYTE)destImg->mImageBits,
                                               destImg->mInfo), GPI_ERROR);
  GFX (::GpiSetBitmap (MemPS, hTmpBitmap), HBM_ERROR);
  
  nsRect trect( aDX, aDY, aDWidth, aDHeight);
  RECTL  rcl;
  destImg->NS2PM_ININ (trect, rcl);

  // Set up blit coord array
  POINTL aptl [4] = { {rcl.xLeft, rcl.yBottom},              // TLL - in
                      {rcl.xRight, rcl.yTop},                // TUR - in
                      {0, 0},                                // SLL - in
                      {mInfo->cx, mInfo->cy} };              // SUR - ex

  if( 1==mAlphaDepth && mAlphaBits)
  {
    LONG BlackColor = GFX (::GpiQueryColorIndex (MemPS, 0, MK_RGB (0x00, 0x00, 0x00)), GPI_ALTERROR);    // CLR_BLACK;
    LONG WhiteColor = GFX (::GpiQueryColorIndex (MemPS, 0, MK_RGB (0xFF, 0xFF, 0xFF)), GPI_ALTERROR);    // CLR_WHITE;
    if (BlackColor == GPI_ALTERROR) BlackColor = MK_RGB (0x00, 0x00, 0x00);
    if (WhiteColor == GPI_ALTERROR) WhiteColor = MK_RGB (0xFF, 0xFF, 0xFF);

    // Set image foreground and background colors. These are used in transparent images for blitting 1-bit masks.
    // To invert colors on ROP_SRCAND we map 1 to black and 0 to white
    IMAGEBUNDLE ib;
    ib.lColor     = BlackColor;        // map 1 in mask to 0x000000 (black) in destination
    ib.lBackColor = WhiteColor;        // map 0 in mask to 0xFFFFFF (white) in destination
    ib.usMixMode  = FM_OVERPAINT;
    ib.usBackMixMode = BM_OVERPAINT;
    GFX (::GpiSetAttrs (MemPS, PRIM_IMAGE, IBB_COLOR | IBB_BACK_COLOR | IBB_MIX_MODE | IBB_BACK_MIX_MODE, 0, (PBUNDLE)&ib), FALSE);

    // Apply mask to target, clear pels we will fill in from the image
    MONOBITMAPINFO MaskBitmapInfo (mInfo);
    GFX (::GpiDrawBits (MemPS, mAlphaBits, MaskBitmapInfo, 4, aptl, ROP_SRCAND,
                        BBO_IGNORE), GPI_ERROR);

    // Now combine image with target
    GFX (::GpiDrawBits (MemPS, mImageBits, mInfo, 4, aptl, ROP_SRCPAINT, 
                        BBO_IGNORE), GPI_ERROR);
  } else {
    // alpha depth of 8 not used (yet?)
    NS_ASSERTION( mAlphaDepth != 8, "Alpha depth of 8 not implemented in DrawToImage" );

    // no transparency, just blit it
    GFX (::GpiDrawBits (MemPS, mImageBits, mInfo, 4, aptl, ROP_SRCCOPY,
                        BBO_IGNORE), GPI_ERROR);
  }

  rc = destImg->UpdateImageBits (MemPS);

  GFX (::GpiSetBitmap (MemPS, NULLHANDLE), HBM_ERROR);
  GFX (::GpiDeleteBitmap (hTmpBitmap), FALSE);
  GFX (::GpiDestroyPS (MemPS), FALSE);
  GFX (::DevCloseDC (MemDC), DEV_ERROR);

  return rc;
}

Here is the call graph for this function:

static PRUint8 nsImageOS2::FAST_BLEND ( PRUint8  Source,
PRUint8  Dest,
PRUint8  Alpha 
) [inline, static, private]

Definition at line 208 of file nsImageOS2.h.

                                                                               { return gBlenderLookup [(Alpha << 8) + Source] + 
                                                                                        gBlenderLookup [((255 - Alpha) << 8) + Dest]; }
virtual PRUint8* nsImageOS2::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 81 of file nsImageOS2.h.

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

Return the header size of the Device Independent Bitmap(DIB).

Returns:
size of header in bytes Return the image size of the Device Independent Bitmap(DIB). dc - 10/29/98
size of image in bytes Calculate the number of bytes spaned for this image for a given width
Parameters:
aWidthis the width to calculate the number of bytes for
Returns:
the number of bytes in this span Get the alpha depth for the image mask - lordpixel 2001/05/16
the alpha mask depth for the image, ie, 0, 1 or 8

Implements nsIImage.

Definition at line 132 of file nsImageOS2.h.

{return(mAlphaDepth);}
virtual PRInt32 nsImageOS2::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 82 of file nsImageOS2.h.

{ return mARowBytes; }
void* nsImageOS2::GetBitInfo ( ) [inline, virtual]

Get the DIB specific informations for this bitmap.

dc - 10/29/98

Returns:
VOID

Implements nsIImage.

Definition at line 139 of file nsImageOS2.h.

{ return mInfo; }
virtual PRUint8* nsImageOS2::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 68 of file nsImageOS2.h.

{ return mImageBits; }
virtual NS_DECL_ISUPPORTS PRInt32 nsImageOS2::GetBytesPix ( ) [inline, virtual]
See also:
nsIImage.h

Implements nsIImage.

Definition at line 64 of file nsImageOS2.h.

{ return mInfo ? (mInfo->cBitCount <= 8 ? 1 : mInfo->cBitCount / 8) : 0; }
virtual nsColorMap* nsImageOS2::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 76 of file nsImageOS2.h.

{return mColorMap;}
virtual PRBool nsImageOS2::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 71 of file nsImageOS2.h.

{ return mAlphaBits != nsnull; }
virtual PRInt32 nsImageOS2::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 65 of file nsImageOS2.h.

{ return mInfo ? mInfo->cy : 0; }

Here is the caller graph for this function:


See documentation in nsIImage.h

Implements nsIImage.

Definition at line 261 of file nsImageOS2.cpp.

                                      {
  return mInfo &&
         mDecodedRect.x == 0 &&
         mDecodedRect.y == 0 &&
         mDecodedRect.width == (PRInt32)mInfo->cx &&
         mDecodedRect.height == (PRInt32)mInfo->cy;
}
virtual PRBool nsImageOS2::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 66 of file nsImageOS2.h.

{ return PR_FALSE; }
virtual PRInt32 nsImageOS2::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 69 of file nsImageOS2.h.

{ return mRowBytes; }
virtual PRInt32 nsImageOS2::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 67 of file nsImageOS2.h.

{ return mInfo ? mInfo->cx : 0; }
void nsImageOS2::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 225 of file nsImageOS2.cpp.

{
   mDecodedRect.UnionRect(mDecodedRect, *aUpdateRect);

   if (!aContext) {
      return;
   } /* endif */
   // This is where we can set the bitmap colour table, as the XP code
   // has filled in the colour map.  It would be cute to be able to alias
   // the bitmap colour table as the mColorMap->Index thing, but the formats
   // are unfortunately different.  Rats.

   aContext->GetDepth( mDeviceDepth);

   if( (aFlags & nsImageUpdateFlags_kColorMapChanged) && mInfo->cBitCount == 8)
   {
      PRGB2 pBmpEntry  = mInfo->argbColor;
      PRUint8 *pMapByte = mColorMap->Index;

      for( PRInt32 i = 0; i < mColorMap->NumColors; i++, pBmpEntry++)
      {
         pBmpEntry->bRed   = *pMapByte++;
         pBmpEntry->bGreen = *pMapByte++;
         pBmpEntry->bBlue  = *pMapByte++;
      }
   }
   else if( aFlags & nsImageUpdateFlags_kBitsChanged)
   {
      // jolly good...
   }
}

Here is the call graph for this function:

nsresult nsImageOS2::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 133 of file nsImageOS2.cpp.

{
   // gfxIImageFrame only allows one init of nsImageOS2

   // (copying windows code - what about monochrome?  Oh well.)
   NS_ASSERTION( aDepth == 24 || aDepth == 8, "Bad image depth");

   // Work out size of bitmap to allocate
   mRowBytes = RASWIDTH(aWidth,aDepth);

   mImageBits = new(std::nothrow) PRUint8 [aHeight * mRowBytes];
   if (!mImageBits) 
     return NS_ERROR_OUT_OF_MEMORY;

   // Set up bitmapinfo header
   int cols = -1;
   if( aDepth == 8) cols = COLOR_CUBE_SIZE;
   else if( aDepth <= 32) cols = 0;

   int szStruct = sizeof( BITMAPINFOHEADER2) + cols * sizeof( RGB2);

   mInfo = (PBITMAPINFO2) calloc( szStruct, 1);
   mInfo->cbFix = sizeof( BITMAPINFOHEADER2);
   mInfo->cx = aWidth;
   mInfo->cy = aHeight;
   mInfo->cPlanes = 1;
   mInfo->cBitCount = (USHORT) aDepth;

   // We can't set up the bitmap colour table yet.

   // init color map.
   // XP will update the color map & then call ImageUpdated(), at which
   // point we can change the color table in the bitmapinfo.
   if( aDepth == 8)
   {
      mColorMap = new nsColorMap;
      mColorMap->NumColors = COLOR_CUBE_SIZE;
      mColorMap->Index = new PRUint8[3 * mColorMap->NumColors];
   }

   // Allocate stuff for mask bitmap
   if( aMaskRequirements != nsMaskRequirements_kNoMask)
   {
      if( aMaskRequirements == nsMaskRequirements_kNeeds1Bit)
      {
         mAlphaDepth = 1;
      }
      else
      {
         NS_ASSERTION( nsMaskRequirements_kNeeds8Bit == aMaskRequirements,
                       "unexpected mask depth");
         mAlphaDepth = 8;
      }

      // 32-bit align each row
      mARowBytes = RASWIDTH (aWidth, mAlphaDepth);

      mAlphaBits = new(std::nothrow) PRUint8 [aHeight * mARowBytes];
      if (!mAlphaBits) {
        // deallocation is done in ::CleanUp() from the destructor
        return NS_ERROR_OUT_OF_MEMORY;
      }
   }

   return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsImageOS2::LockImagePixels ( PRBool  aMaskPixels) [virtual]

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 652 of file nsImageOS2.cpp.

{
  return NS_OK;
}
void nsImageOS2::NS2PM_ININ ( const nsRect in,
RECTL &  rcl 
) [private]

Definition at line 902 of file nsImageOS2.cpp.

{
  PRUint32 ulHeight = GetHeight ();

  rcl.xLeft = in.x;
  rcl.xRight = in.x + in.width - 1;
  rcl.yTop = ulHeight - in.y - 1;
  rcl.yBottom = rcl.yTop - in.height + 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsImageOS2::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 642 of file nsImageOS2.cpp.

{
   // Defer this until we have a PS...
   mIsOptimized = PR_TRUE;
   return NS_OK;
}

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 660 of file nsImageOS2.cpp.

{
  return NS_OK;
} 

Definition at line 916 of file nsImageOS2.cpp.

{
  BITMAPINFOHEADER2 rawInfo = { 0 };
  rawInfo.cbFix   = sizeof (BITMAPINFOHEADER2);
  rawInfo.cPlanes = 1;
  rawInfo.cBitCount = mInfo->cBitCount;

  int RawDataSize = mInfo->cy * RASWIDTH (mInfo->cx, mInfo->cBitCount);
  PRUint8* pRawBitData = new(std::nothrow) PRUint8 [RawDataSize];

  if (pRawBitData)
  {
    GFX (::GpiQueryBitmapBits (aPS, 0, mInfo->cy, (PBYTE)pRawBitData, (PBITMAPINFO2)&rawInfo), GPI_ALTERROR);
    delete [] mImageBits;
    mImageBits = pRawBitData;
    return NS_OK;
  }
  else
    return NS_ERROR_OUT_OF_MEMORY;
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 205 of file nsImageOS2.h.

Definition at line 206 of file nsImageOS2.h.

Definition at line 201 of file nsImageOS2.h.

PRInt8 nsImageOS2::mAlphaDepth [private]

Definition at line 202 of file nsImageOS2.h.

Definition at line 203 of file nsImageOS2.h.

Definition at line 196 of file nsImageOS2.h.

Definition at line 198 of file nsImageOS2.h.

Definition at line 192 of file nsImageOS2.h.

Definition at line 194 of file nsImageOS2.h.

BITMAPINFO2* nsImageOS2::mInfo [private]

Definition at line 191 of file nsImageOS2.h.

Definition at line 195 of file nsImageOS2.h.

Definition at line 193 of file nsImageOS2.h.


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