以下是左转的源代码,请各位大侠指教
 #define ROTATE_LEFT(type)\
{\
  type d;\
  type s;\
  (__u8 *) dest += (height - 1) * dest_pitch;\
  for (w = 0; w < width; w++)\
    {\
      h = height;\
      d = (type) dest + w;\
      s = src;\
      while (h--)\
        {\
          *d = *s;\
          s++;\
          (__u8*)d -= dest_pitch;\
        }\
      (__u8*)src += src_pitch;\
    }\
}\
static void
rotate (void         *dest,
        int           dest_pitch,
        void         *src,
        int           src_pitch,
        int           width,
        int           height,
        int           bpp,
        RotationType  rot)
{
  int w, h, tmp;  switch (rot)
    {
    case ROT_LEFT:
      SWAP (&width, &height, tmp);
      switch (bpp)
        {
        case 2:
          ROTATE_LEFT (__u16 *)
          break;
        case 4:
          ROTATE_LEFT (__u32 *)
          break;
        default:
          break;
        }
      break;
如果是位色的问题,我加载上2、4位的图片也不能 正常显示。 请问是什么原因?

解决方案 »

  1.   

    旋转1Bit&4Bit的是按位旋转的,你的:
          while (h--)\
            {\
              *d = *s;\ //<-----拜托,整个字节旋了过去能正常显示才怪 -_-
              s++;\
              (__u8*)d -= dest_pitch;\
            }\
    ===============================================
    估计你这样做在8Bit情况下是可以正常显示的 ^0^  最后:你的代码里的什么_u8*/_u16*等,把它的定义帖出来最好,要不会看得莫名其妙..
    估计又是:
    #typedef _u8* LPBYTE之类的DD...
      

  2.   

    to "lambochan " 定义如下
     #define __u8 unsigned char
     #define __u16 unsigned short
     #define __u32 unsigned long那大侠指点一下该怎么改呢?
    我要是想显示24位色的可以显示么 ?
                                    万分感谢!!
      

  3.   

    给你个函数自己看着转,呵呵,自己改着用:
    ============================================================================
    #define WIDTHBYTES(bits) (((bits) + 31) / 32 * 4)/*
    * 参数:
    *
    * BYTE *pDestBits   - 旋转后的位数据指针
    *
    * BYTE *pSrcBits    - 原图的位数据指针
    *
    * DWORD nWidth      - 原图的宽
    *
    * DWORD nHeight     - 原图的高
    *
    * WORD nBpp         - 原图的颜色深度(Bits Per Pixel)
    *
    * 返回值:
    *
    * void              - 
    *
    * 说明:
    *
    * 本函数将要旋转的位图直角旋转90度
    *
    */
    void RotaBMP90(BYTE *pDestBits,BYTE *pSrcBits,DWORD nWidth,DWORD nHeight,WORD nBpp)
    {
        DWORD newBytesPerLine = WIDTHBYTES(nHeight * nBpp);
        DWORD oldBytesPerLine = WIDTHBYTES(nWidth * nBpp);
        DWORD i,j;    switch(nBpp){
            case 1://1bpp
                for(i = 0;i < nHeight;++i)
                {
                    for(j = 0;j < nWidth;++j)
                    {
                        *(pDestBits + (newBytesPerLine * j + (nHeight - i - 1) / 8)) &=
                            ~(1 << (7 - ((nHeight - i - 1) % 8)));
                        *(pDestBits + (newBytesPerLine * j + (nHeight - i - 1) / 8)) |=
                            ((*(pSrcBits + (oldBytesPerLine * i + j / 8)) << (j % 8)) >> 7)
                            << (7 - ((nHeight - i - 1) % 8));
                    }
                }
                break;
            case 4:
                for(i = 0;i < nHeight;++i)
                {
                    for(j = 0;j < nWidth;++j)
                    {
                        *(pDestBits + (newBytesPerLine * j + (nHeight - i - 1) / 2)) &=
                            ((nHeight - i - 1) % 2) ? 0xf0 : 0x0f;
                        *(pDestBits + (newBytesPerLine * j + (nHeight - i - 1) / 2)) |=
                            ((*(pSrcBits + (oldBytesPerLine * i + j / 2)) << (j % 2 ? 4 : 0)) >> 4)
                            << (((nHeight - i - 1) % 2) ? 0 : 4);
                    }
                }
                break;
            case 8:
                for(i = 0;i < nHeight;++i)
                {
                    for(j = 0;j < nWidth;++j)
                    {
                        *(pDestBits + (newBytesPerLine * j + (nHeight - i - 1))) =
                            *(pSrcBits + (oldBytesPerLine * i + j));                }
                }
                break;
            case 16:
                for(i = 0;i < nHeight;++i)
                {
                    for(j = 0;j < nWidth;++j)
                    {
                        *(pDestBits + (newBytesPerLine * j + (nHeight - i - 1) * 2)) =
                            *(pSrcBits + (oldBytesPerLine * i + j * 2));
                        *(pDestBits + (newBytesPerLine * j + (nHeight - i - 1) * 2) + 1) =
                            *(pSrcBits + (oldBytesPerLine * i +j * 2) + 1);
                    }
                }
                break;
            case 24:
                for(i = 0;i < nHeight;++i)
                {
                    for(j = 0;j < nWidth;++j)
                    {
                        *(pDestBits + (newBytesPerLine * j + (nHeight - i - 1) * 3)) =
                            *(pSrcBits + (oldBytesPerLine * i + j * 3));
                        *(pDestBits + (newBytesPerLine * j + (nHeight - i - 1) * 3) + 1) =
                            *(pSrcBits + (oldBytesPerLine * i +j * 3) + 1);
                        *(pDestBits + (newBytesPerLine * j + (nHeight - i - 1) * 3) + 2) =
                            *(pSrcBits + (oldBytesPerLine * i +j * 3) + 2);
                    }
                }
                break;
            case 32:
                for(i = 0;i < nHeight;++i)
                {
                    for(j = 0;j < nWidth;++j)
                    {
                        *(pDestBits + (newBytesPerLine * j + (nHeight - i - 1) * 4)) =
                            *(pSrcBits + (oldBytesPerLine * i + j * 4));
                        *(pDestBits + (newBytesPerLine * j + (nHeight - i - 1) * 4) + 1) =
                            *(pSrcBits + (oldBytesPerLine * i +j * 4) + 1);
                        *(pDestBits + (newBytesPerLine * j + (nHeight - i - 1) * 4) + 2) =
                            *(pSrcBits + (oldBytesPerLine * i +j * 4) + 2);
                        *(pDestBits + (newBytesPerLine * j + (nHeight - i - 1) * 4) + 3) =
                            *(pSrcBits + (oldBytesPerLine * i +j * 4) + 3);
                    }
                }
                break;
        }
    }
    ===============================================================================
    btw: 有错误不关我事,随手用notepad写的,hohoho~~~