Esempio n. 1
0
void Texture::vFlipImage(
  unsigned char *pImage,
  bool boFlipHorizontal,
  bool boFlipVertical,
  unsigned short width, //GLushort width,
  unsigned short height, //GLushort height,
  unsigned char bpp  //GLbyte bpp
)
/*
  Written: 21 Mar. 2010: JH
  Purpose: The image might come out flipped, so we flip it back
*/
{
  unsigned char // GLbyte
    m_iBpp = bpp / 8;        

  if (boFlipHorizontal){
    for (int h = 0; h < height; h++) {
      for (int w = 0; w < width / 2; w++){                
        vSwap(pImage + (h * width + w) * m_iBpp, pImage + (h * width + width - w - 1)* m_iBpp, m_iBpp);
      }
    }
  }

  if (boFlipVertical){
    for (int w = 0; w < width; w++){
      for (int h = 0; h < height / 2; h++) {
        vSwap(pImage + (h * width + w) * m_iBpp, pImage + ((height - h - 1) * width + w)* m_iBpp, m_iBpp);
      }
    }
  }
}
void m_rc4_init (BYTE *D, unsigned char *key, int keylen)  {

    BYTE  *S = D+8;
    unsigned char T[256];
    int i, j=0;

    // Initialization of the state vector  S
    for (i=0; i < 256; i++)  {
        S[i] = i;
        T[i] = key[i % keylen];
    }

    // Initial permutation of S using the key
    for (i=0; i < 256; i++)  {
        j = (j + S[i] + T[i]) % 256;
        vSwap (S, i, j);
    }

    // Initialize initial i and j
    int *p_int = (int *)D;
    *p_int = 0;
    *(p_int+1) = 0;

    return;
}
BYTE m_rc4_gen(BYTE *D)  {

    BYTE *S = D+8;
    int i, j, t;
    BYTE obyte;
    int *p_int = (int *)D;

    // Initialization of i and j
    i = *p_int;
    j = *(p_int+1);

    // Generate one byte of the PSRN stream
    i = (i+1) % 256;
    j = (j + S[i]) % 256;
    vSwap(S, i, j);
    t = (S[i] + S[j]) % 256;
    obyte = S[t];

    // Set the new values of i and j into the input vector
    *p_int = i;
    *(p_int+1) = j;

    return (obyte);
}