Back to index

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

#include <nsPNGEncoder.h>

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

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_IMGIENCODER
NS_DECL_NSIINPUTSTREAM 
nsPNGEncoder ()
void encodeClipboardImage (in nsIClipboardImage aClipboardImage, out nsIFile aImageFile)

Protected Member Functions

void ConvertHostARGBRow (const PRUint8 *aSrc, PRUint8 *aDest, PRUint32 aPixelWidth, PRBool aUseTransparency)
void StripAlpha (const PRUint8 *aSrc, PRUint8 *aDest, PRUint32 aPixelWidth)

Static Protected Member Functions

static void WriteCallback (png_structp png, png_bytep data, png_size_t size)

Protected Attributes

PRUint8mImageBuffer
PRUint32 mImageBufferSize
PRUint32 mImageBufferUsed
PRUint32 mImageBufferReadPoint

Private Member Functions

 ~nsPNGEncoder ()

Detailed Description

Definition at line 57 of file nsPNGEncoder.h.


Constructor & Destructor Documentation

Definition at line 61 of file nsPNGEncoder.cpp.


Member Function Documentation

void nsPNGEncoder::ConvertHostARGBRow ( const PRUint8 aSrc,
PRUint8 aDest,
PRUint32  aPixelWidth,
PRBool  aUseTransparency 
) [protected]

Definition at line 271 of file nsPNGEncoder.cpp.

{
  PRUint32 pixelStride = aUseTransparency ? 4 : 3;
  for (PRUint32 x = 0; x < aPixelWidth; x ++) {
    const PRUint32& pixelIn = ((const PRUint32*)(aSrc))[x];
    PRUint8 *pixelOut = &aDest[x * pixelStride];

    PRUint8 alpha = (pixelIn & 0xff000000) >> 24;
    if (alpha == 0) {
      pixelOut[0] = pixelOut[1] = pixelOut[2] = pixelOut[3] = 0;
    } else {
      pixelOut[0] = (((pixelIn & 0xff0000) >> 16) * 255 + alpha / 2) / alpha;
      pixelOut[1] = (((pixelIn & 0x00ff00) >>  8) * 255 + alpha / 2) / alpha;
      pixelOut[2] = (((pixelIn & 0x0000ff) >>  0) * 255 + alpha / 2) / alpha;
      if (aUseTransparency)
        pixelOut[3] = alpha;
    }
  }
}
void imgIEncoder::encodeClipboardImage ( in nsIClipboardImage  aClipboardImage,
out nsIFile  aImageFile 
) [inherited]
void nsPNGEncoder::StripAlpha ( const PRUint8 aSrc,
PRUint8 aDest,
PRUint32  aPixelWidth 
) [protected]

Definition at line 298 of file nsPNGEncoder.cpp.

{
  for (PRUint32 x = 0; x < aPixelWidth; x ++) {
    const PRUint8* pixelIn = &aSrc[x * 4];
    PRUint8* pixelOut = &aDest[x * 3];
    pixelOut[0] = pixelIn[0];
    pixelOut[1] = pixelIn[1];
    pixelOut[2] = pixelIn[2];
  }
}
void nsPNGEncoder::WriteCallback ( png_structp  png,
png_bytep  data,
png_size_t  size 
) [static, protected]

Definition at line 314 of file nsPNGEncoder.cpp.

{
  nsPNGEncoder* that = NS_STATIC_CAST(nsPNGEncoder*, png_get_io_ptr(png));
  if (! that->mImageBuffer)
    return;

  if (that->mImageBufferUsed + size > that->mImageBufferSize) {
    // expand buffer, just double each time
    that->mImageBufferSize *= 2;
    PRUint8* newBuf = (PRUint8*)PR_Realloc(that->mImageBuffer,
                                           that->mImageBufferSize);
    if (! newBuf) {
      // can't resize, just zero (this will keep us from writing more)
      PR_Free(that->mImageBuffer);
      that->mImageBufferSize = 0;
      that->mImageBufferUsed = 0;
      return;
    }
    that->mImageBuffer = newBuf;
  }
  memcpy(&that->mImageBuffer[that->mImageBufferUsed], data, size);
  that->mImageBufferUsed += size;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 77 of file nsPNGEncoder.h.

Definition at line 81 of file nsPNGEncoder.h.

Definition at line 78 of file nsPNGEncoder.h.

Definition at line 79 of file nsPNGEncoder.h.


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