Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
nsIconChannel.cpp File Reference
#include "nsIconChannel.h"
#include "nsIIconURI.h"
#include "nsReadableUtils.h"
#include "nsMemory.h"
#include "nsNetUtil.h"
#include "nsInt64.h"
#include "nsIFile.h"
#include "nsIFileURL.h"
#include "nsDirectoryServiceDefs.h"
#include <os2.h>

Go to the source code of this file.

Defines

#define INCL_PM
#define FIRSTPEL(x)   (0xF & (x >> 4))
#define SECONDPEL(x)   (0xF & x)
#define ALIGNEDBPR(cx, bits)   ((( ((cx)*(bits)) + 31) / 32) * 4)
#define UNALIGNEDBPR(cx, bits)   (( ((cx)*(bits)) + 7) / 8)

Functions

HPOINTER GetFileIcon (nsCString &file, PRBool fExists)
void ConvertColorBitMap (PRUint8 *inBuf, PBITMAPINFO2 pBMInfo, PRUint8 *outBuf)
void ShrinkColorBitMap (PRUint8 *inBuf, PBITMAPINFO2 pBMInfo, PRUint8 *outBuf)
void ConvertMaskBitMap (PRUint8 *inBuf, PBITMAPINFO2 pBMInfo, PRUint8 *outBuf)
void ShrinkMaskBitMap (PRUint8 *inBuf, PBITMAPINFO2 pBMInfo, PRUint8 *outBuf)
 NS_IMPL_THREADSAFE_ISUPPORTS4 (nsIconChannel, nsIChannel, nsIRequest, nsIRequestObserver, nsIStreamListener) nsresult nsIconChannel

Define Documentation

#define ALIGNEDBPR (   cx,
  bits 
)    ((( ((cx)*(bits)) + 31) / 32) * 4)

Definition at line 65 of file nsIconChannel.cpp.

#define FIRSTPEL (   x)    (0xF & (x >> 4))

Definition at line 61 of file nsIconChannel.cpp.

Definition at line 55 of file nsIconChannel.cpp.

#define SECONDPEL (   x)    (0xF & x)

Definition at line 62 of file nsIconChannel.cpp.

#define UNALIGNEDBPR (   cx,
  bits 
)    (( ((cx)*(bits)) + 7) / 8)

Definition at line 68 of file nsIconChannel.cpp.


Function Documentation

void ConvertColorBitMap ( PRUint8 inBuf,
PBITMAPINFO2  pBMInfo,
PRUint8 outBuf 
)

Definition at line 482 of file nsIconChannel.cpp.

{

  PRUint32  bprIn = ALIGNEDBPR(pBMInfo->cx, pBMInfo->cBitCount);
  PRUint8*  pIn   = inBuf + (pBMInfo->cy - 1) * bprIn;
  PRUint8*  pOut  = outBuf;
  PRGB2       pColorTable = &pBMInfo->argbColor[0];

  if (pBMInfo->cBitCount == 4) {
    PRUint32  ubprIn = UNALIGNEDBPR(pBMInfo->cx, pBMInfo->cBitCount);
    PRUint32  padIn  = bprIn - ubprIn;

    for (PRUint32 row = pBMInfo->cy; row > 0; row--) {
      for (PRUint32 ndx = 0; ndx < ubprIn; ndx++, pIn++) {
        pOut = 3 + (PRUint8*)memcpy( pOut, &pColorTable[FIRSTPEL(*pIn)], 3);
        pOut = 3 + (PRUint8*)memcpy( pOut, &pColorTable[SECONDPEL(*pIn)], 3);
      }
      pIn -= (2 * bprIn) - padIn;
    }
  }
  else
  if (pBMInfo->cBitCount == 8) {
    for (PRUint32 row = pBMInfo->cy; row > 0; row--) {
      for (PRUint32 ndx = 0; ndx < bprIn; ndx++, pIn++) {
        pOut = 3 + (PRUint8*)memcpy( pOut, &pColorTable[*pIn], 3);
      }
      pIn -= 2 * bprIn;
    }
  }
  else
  if (pBMInfo->cBitCount == 24) {
    for (PRUint32 row = pBMInfo->cy; row > 0; row--) {
      pOut = bprIn + (PRUint8*)memcpy( pOut, pIn, bprIn);
      pIn -= bprIn;
    }
  }

  return;
}

Here is the call graph for this function:

void ConvertMaskBitMap ( PRUint8 inBuf,
PBITMAPINFO2  pBMInfo,
PRUint8 outBuf 
)

Definition at line 578 of file nsIconChannel.cpp.

{

  PRUint32  bprIn  = ALIGNEDBPR(pBMInfo->cx, pBMInfo->cBitCount);
  PRUint32  lprIn  = bprIn / 4;
  PRUint32* pOut32 = (PRUint32*)outBuf;
  PRUint32* pIn32  = (PRUint32*)(inBuf + (pBMInfo->cy - 1) * bprIn);

  for (PRUint32 row = pBMInfo->cy/2; row > 0; row--) {
    for (PRUint32 ndx = 0; ndx < lprIn; ndx++) {
        *pOut32++ = ~(*pIn32++);
    }
    pIn32 -= 2 * lprIn;
  }

  return;
}
HPOINTER GetFileIcon ( nsCString file,
PRBool  fExists 
)

Definition at line 443 of file nsIconChannel.cpp.

{

  if (fExists)
    return WinLoadFileIcon( file.get(), FALSE);

  nsCOMPtr<nsIFile> dummyPath;
  if (NS_FAILED(NS_GetSpecialDirectory(NS_OS_TEMP_DIR,
                                       getter_AddRefs(dummyPath))))
    return 0;

  if (file.First() == '.')
    file.Insert("moztmp", 0);

  if (NS_FAILED(dummyPath->AppendNative(file)))
    return 0;

  nsCAutoString dummyFile;
  dummyPath->GetNativePath(dummyFile);

  HPOINTER  hRtn = 0;
  FILE*     fp = fopen( dummyFile.get(), "wb+");
  if (fp) {
    fclose( fp);
    hRtn = WinLoadFileIcon(dummyFile.get(), FALSE);
    remove(dummyFile.get());
  }

  return hRtn;
}

Here is the call graph for this function:

Definition at line 88 of file nsIconChannel.cpp.

{
  NS_ASSERTION(uri, "no uri");
  mUrl = uri;

  nsresult rv;
  mPump = do_CreateInstance(NS_INPUTSTREAMPUMP_CONTRACTID, &rv);
  return rv;
}

Here is the call graph for this function:

void ShrinkColorBitMap ( PRUint8 inBuf,
PBITMAPINFO2  pBMInfo,
PRUint8 outBuf 
)

Definition at line 528 of file nsIconChannel.cpp.

{

  PRUint32  bprIn = ALIGNEDBPR(pBMInfo->cx, pBMInfo->cBitCount);
  PRUint8*  pIn   = inBuf + (pBMInfo->cy - 1) * bprIn;
  PRUint8*  pOut  = outBuf;
  PRGB2       pColorTable = &pBMInfo->argbColor[0];

  if (pBMInfo->cBitCount == 4) {
    PRUint32  ubprIn = UNALIGNEDBPR(pBMInfo->cx, pBMInfo->cBitCount);
    PRUint32  padIn  = bprIn - ubprIn;

    for (PRUint32 row = pBMInfo->cy; row > 0; row -= 2) {
      for (PRUint32 ndx = 0; ndx < ubprIn; ndx++, pIn++) {
        pOut = 3 + (PRUint8*)memcpy( pOut, &pColorTable[FIRSTPEL(*pIn)], 3);
      }
      pIn -= (3 * bprIn) - padIn;
    }
  }
  else
  if (pBMInfo->cBitCount == 8) {
    for (PRUint32 row = pBMInfo->cy; row > 0; row -= 2) {
      for (PRUint32 ndx = 0; ndx < bprIn; ndx += 2, pIn += 2) {
        pOut = 3 + (PRUint8*)memcpy( pOut, &pColorTable[*pIn], 3);
      }
      pIn -= 3 * bprIn;
    }
  }
  else
  if (pBMInfo->cBitCount == 24) {
    for (PRUint32 row = pBMInfo->cy; row > 0; row -= 2) {
      for (PRUint32 ndx = 0; ndx < bprIn; ndx += 6, pIn += 3) {
        pOut = 3 + (PRUint8*)memcpy( pOut, pIn, 3);
        pIn += 3;
      }
      pIn -= 3 * bprIn;
    }
  }

  return;
}

Here is the call graph for this function:

void ShrinkMaskBitMap ( PRUint8 inBuf,
PBITMAPINFO2  pBMInfo,
PRUint8 outBuf 
)

Definition at line 602 of file nsIconChannel.cpp.

{

  PRUint32  bprIn  = ALIGNEDBPR(pBMInfo->cx, pBMInfo->cBitCount);
  PRUint32  padOut = (bprIn / 2) & 3;
  PRUint8*  pOut   = outBuf;
  PRUint8*  pIn    = inBuf + (pBMInfo->cy - 1) * bprIn;

  // for every other row
  for (PRUint32 row = pBMInfo->cy/2; row > 0; row -= 2) {
    PRUint8 dest = 0;
    PRUint8 destMask = 0x80;

    // for every byte in the row
    for (PRUint32 ndx = 0; ndx < bprIn; ndx++) {
      PRUint8 src = ~(*pIn++);
      PRUint8 srcMask = 0x80;

      // for every other bit in the current byte
      for (PRUint32 bitNdx = 0; bitNdx < 8; bitNdx += 2) {
        if (src & srcMask)
          dest |= destMask;
        srcMask >>= 2;
        destMask >>= 1;
      }

      // if we've filled an output byte from two input bytes, save it
      if (!destMask) {
        *pOut++ = dest;
        dest = 0;
        destMask = 0x80;
      }
    }

    // after we've processed every input byte in the row, 
    // does the output row need padding?
    if (padOut) {
      memset( pOut, 0, padOut);
      pOut += padOut;
    }

    pIn -= 3 * bprIn;
  }

  return;
}

Here is the call graph for this function: