⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcdmemc.c

📁 lpc2478+ucosII+ucgui源码
💻 C
📖 第 1 页 / 共 4 页
字号:
  case 7:                                         \
    p+=2;                                         \
    *p = (*p&~(7<<0))|(c);                        \
    break;                                        \
  }                                               \
}

#elif (LCD_BITSPERPIXEL == 6)

void SetPixelPhys222(int x, int y, LCD_PIXELINDEX c) {
  U8 LCD_VRAMTYPE* p0 = OFF2PTR_0(XY2OFF(x,y));
  U8 LCD_VRAMTYPE* p1 = OFF2PTR_1(XY2OFF(x,y));
  U8 c0 = ((c & 0x20) >> 3) + ((c & 0x08) >> 2) + ((c & 0x02) >> 1);
  U8 c1 = ((c & 0x10) >> 2) + ((c & 0x04) >> 1) +  (c & 0x01);
  switch (x&7) {
  case 0:
    *p0 = (*p0&~(7<<5))|(c0<<5);
    *p1 = (*p1&~(7<<5))|(c1<<5);
    break;
  case 1:
    *p0 = (*p0&~(7<<2))|(c0<<2);
    *p1 = (*p1&~(7<<2))|(c1<<2);
    break;
  case 2:
    *p0   = (*p0&~(3))|(c0>>1);
    *p1   = (*p1&~(3))|(c1>>1);
    p0++;
    p1++;
    *p0 = (*p0 &~(1<<7))|(c0<<7);
    *p1 = (*p1 &~(1<<7))|(c1<<7);
    break;
  case 3:
    p0++;
    p1++;
    *p0 = (*p0&~(7<<4))|(c0<<4);
    *p1 = (*p1&~(7<<4))|(c1<<4);
    break;
  case 4:
    p0++;
    p1++;
    *p0 = (*p0&~(7<<1))|(c0<<1);
    *p1 = (*p1&~(7<<1))|(c1<<1);
    break;
  case 5:
    p0++;
    p1++;
    *p0   = (*p0&~(1))|(c0>>2);
    *p1   = (*p1&~(1))|(c1>>2);
    p0++;
    p1++;
    *p0 = (*p0 &~(3<<6))|(c0<<6);
    *p1 = (*p1 &~(3<<6))|(c1<<6);
    break;
  case 6:
    p0+=2;
    p1+=2;
    *p0 = (*p0&~(7<<3))|(c0<<3);
    *p1 = (*p1&~(7<<3))|(c1<<3);
    break;
  case 7:
    p0+=2;
    p1+=2;
    *p0 = (*p0&~(7<<0))|(c0);
    *p1 = (*p1&~(7<<0))|(c1);
    break;
  }
}

#define SETPIXELPHYS(x,y,c) SetPixelPhys222(x,y,c) 

#endif

static void SetPixelPhys(int x, int y, LCD_PIXELINDEX c) {
  SETPIXELPHYS(x,y,c);
}


/*
        *********************************************************
        *                                                       *
        *       Next pixel routines, optimized for 3bpp
        *                                                       *
        *********************************************************
*/

#if      (LCD_OPTIMIZE)             \
      && (!LCD_MIRROR_X)            \
      && (!LCD_MIRROR_Y)            \
      && (!LCD_SWAP_XY)             \
      && (!LCD_SUPPORT_COMTRANS)    \
      && (!LCD_SUPPORT_SEGTRANS)    \
      && (LCD_BITSPERPIXEL == 3)

static int CurPosX;
static U8 LCD_VRAMTYPE* pCurPos;

static void SetPosXY(int x, int y) {
  CurPosX = x;
  pCurPos = OFF2PTR(XY2OFF(x,y));
  switch (x&7) {
  case 3:
  case 4:
  case 5:
    pCurPos++; break;
  case 6:
  case 7:
    pCurPos+=2;
  }
}

static void SetNextPixel(LCD_PIXELINDEX c) {
  switch (CurPosX&7) {
  case 0: *pCurPos = (*pCurPos&~(7<<5))|(c<<5); break;
  case 1: *pCurPos = (*pCurPos&~(7<<2))|(c<<2); break;
  case 2: *pCurPos = (*pCurPos&~(3))|(c>>1);
           pCurPos++;
          *pCurPos = (*pCurPos &~(1<<7))|(c<<7);
           break;
  case 3: *pCurPos = (*pCurPos&~(7<<4))|(c<<4); break;
  case 4: *pCurPos = (*pCurPos&~(7<<1))|(c<<1); break;
  case 5: *pCurPos = (*pCurPos&~(1))|(c>>2);
           pCurPos++;
          *pCurPos = (*pCurPos &~(3<<6))|(c<<6);
           break;
  case 6: *pCurPos = (*pCurPos&~(7<<3))|(c<<3); break;
  case 7: *pCurPos = (*pCurPos&~(7<<0))|(c);
           pCurPos++;
           break;
  }
  CurPosX++;
}

/*
        *********************************************************
        *                                                       *
        *       Next pixel routines, optimized for 6bpp
        *                                                       *
        *********************************************************
*/

#elif    (LCD_OPTIMIZE)             \
      && (!LCD_MIRROR_X)            \
      && (!LCD_MIRROR_Y)            \
      && (!LCD_SWAP_XY)             \
      && (!LCD_SUPPORT_COMTRANS)    \
      && (!LCD_SUPPORT_SEGTRANS)    \
      && (LCD_BITSPERPIXEL == 6)

static int CurPosX;
static U8 LCD_VRAMTYPE* pCurPos_0;
static U8 LCD_VRAMTYPE* pCurPos_1;

static void SetPosXY(int x, int y) {
  CurPosX = x;
  pCurPos_0 = OFF2PTR_0(XY2OFF(x,y));
  pCurPos_1 = OFF2PTR_1(XY2OFF(x,y));
  switch (x&7) {
  case 3:
  case 4:
  case 5:
    pCurPos_0++;
    pCurPos_1++;
    break;
  case 6:
  case 7:
    pCurPos_0+=2;
    pCurPos_1+=2;
  }
}

static void SetNextPixel(LCD_PIXELINDEX c) {
  U8 c0 = ((c & 0x20) >> 3) + ((c & 0x08) >> 2) + ((c & 0x02) >> 1);
  U8 c1 = ((c & 0x10) >> 2) + ((c & 0x04) >> 1) +  (c & 0x01);
  switch (CurPosX&7) {
  case 0: 
    *pCurPos_0 = (*pCurPos_0&~(7<<5))|(c0<<5); 
    *pCurPos_1 = (*pCurPos_1&~(7<<5))|(c1<<5); 
    break;
  case 1: 
    *pCurPos_0 = (*pCurPos_0&~(7<<2))|(c0<<2); 
    *pCurPos_1 = (*pCurPos_1&~(7<<2))|(c1<<2); 
    break;
  case 2: 
    *pCurPos_0 = (*pCurPos_0&~(3))|(c0>>1);
    *pCurPos_1 = (*pCurPos_1&~(3))|(c1>>1);
    pCurPos_0++;
    pCurPos_1++;
    *pCurPos_0 = (*pCurPos_0 &~(1<<7))|(c0<<7);
    *pCurPos_1 = (*pCurPos_1 &~(1<<7))|(c1<<7);
    break;
  case 3: 
    *pCurPos_0 = (*pCurPos_0&~(7<<4))|(c0<<4); 
    *pCurPos_1 = (*pCurPos_1&~(7<<4))|(c1<<4); 
    break;
  case 4: 
    *pCurPos_0 = (*pCurPos_0&~(7<<1))|(c0<<1); 
    *pCurPos_1 = (*pCurPos_1&~(7<<1))|(c1<<1); 
    break;
  case 5: 
    *pCurPos_0 = (*pCurPos_0&~(1))|(c0>>2);
    *pCurPos_1 = (*pCurPos_1&~(1))|(c1>>2);
    pCurPos_0++;
    pCurPos_1++;
    *pCurPos_0 = (*pCurPos_0 &~(3<<6))|(c0<<6);
    *pCurPos_1 = (*pCurPos_1 &~(3<<6))|(c1<<6);
    break;
  case 6: 
    *pCurPos_0 = (*pCurPos_0&~(7<<3))|(c0<<3); 
    *pCurPos_1 = (*pCurPos_1&~(7<<3))|(c1<<3); 
    break;
  case 7: 
    *pCurPos_0 = (*pCurPos_0&~(7<<0))|(c0);
    *pCurPos_1 = (*pCurPos_1&~(7<<0))|(c1);
    pCurPos_0++;
    pCurPos_1++;
    break;
  }
  CurPosX++;
}

#endif

#if (LCD_BITSPERPIXEL == 3)

unsigned int GetPixel(int x, int y) {
  U8 LCD_VRAMTYPE* p = OFF2PTR(XY2OFF(x,y));
  switch(x&7) {
    case 0: return (*p>>5);
    case 1: return (*p>>2)&7;
    case 2: return ((*p&(3   )) <<1)|(*(p+1)>>7);
    case 3: return (*(p+1)>>4) &7;
    case 4: return (*(p+1)>>1) &7;
    case 5: return ((*(p+1)&(1)) <<2)|(*(p+2)>>6);
    case 6: return (*(p+2)&(7<<3)) >>3;
  }
  return (*(p+2)&(7<<0)) >>0;
}

unsigned int LCD_L0_GetPixelIndex(int x, int y) {
  return GETPIXEL(x, y);
}

#elif (LCD_BITSPERPIXEL == 6)

unsigned int GetPixel(int x, int y) {
  U8 LCD_VRAMTYPE* p0 = OFF2PTR_0(XY2OFF(x,y));
  U8 LCD_VRAMTYPE* p1 = OFF2PTR_1(XY2OFF(x,y));
  U8 c0, c1;
  switch(x&7) {
    case 0: 
      c0 = (*p0>>5);
      c1 = (*p1>>5);
      break;
    case 1: 
      c0 = (*p0>>2)&7;
      c1 = (*p1>>2)&7;
      break;
    case 2: 
      c0 = ((*p0&3)<<1)|(*(p0+1)>>7);
      c1 = ((*p1&3)<<1)|(*(p1+1)>>7);
      break;
    case 3: 
      c0 = (*(p0+1)>>4) &7;
      c1 = (*(p1+1)>>4) &7;
      break;
    case 4: 
      c0 = (*(p0+1)>>1) &7;
      c1 = (*(p1+1)>>1) &7;
      break;
    case 5: 
      c0 = ((*(p0+1)&(1)) <<2)|(*(p0+2)>>6);
      c1 = ((*(p1+1)&(1)) <<2)|(*(p1+2)>>6);
      break;
    case 6: 
      c0 = (*(p0+2)&(7<<3)) >>3;
      c1 = (*(p1+2)&(7<<3)) >>3;
      break;
    case 7: 
      c0 = (*(p0+2)&(7<<0)) >>0;
      c1 = (*(p1+2)&(7<<0)) >>0;
      break;
  }
  return ((c0 & 0x04) << 3) + ((c0 & 0x02) << 2) + ((c0 & 0x01) << 1)
       + ((c1 & 0x04) << 2) + ((c1 & 0x02) << 1) +  (c1 & 0x01);
}

unsigned int LCD_L0_GetPixelIndex(int x, int y) {
  return GETPIXEL(x, y);
}

#endif


static void XorPixel   (int x, int y) {
  LCD_PIXELINDEX Index = GetPixel(x,y);
  Index = LCD_NUM_COLORS-1-Index;
  SetPixelPhys(x,y,Index);
}

void LCD_L0_XorPixel   (int x, int y) {
  XORPIXEL(x,y);
}

void LCD_L0_SetPixelIndex   (int x, int y, int ColorIndex) {
  SETPIXELFAST(x,y,ColorIndex);
}



/*
        *********************************************************
        *                                                       *
        *          LCD_DrawHLine optimized                      *
        *                                                       *
        *          Normal display, 3 Bpp                        *
        *                                                       *
        *********************************************************
*/

#if      (LCD_OPTIMIZE)             \
      && (!LCD_MIRROR_X)            \
      && (!LCD_MIRROR_Y)            \
      && (!LCD_SWAP_XY)             \
      && (!LCD_SUPPORT_COMTRANS)    \
      && (!LCD_SUPPORT_SEGTRANS)    \
      && (LCD_BITSPERPIXEL == 3)

static U8 MaskLeft[8][3] = {
  { 0xff, 0xff, 0xff},
  { 0x1f, 0xff, 0xff},
  { 0x03, 0xff, 0xff},
  { 0x00, 0x7f, 0xff},
  { 0x00, 0x0f, 0xff},
  { 0x00, 0x01, 0xff},
  { 0x00, 0x00, 0x3f},
  { 0x00, 0x00, 0x07}/*!!!0x0e*/
};

static U8 MaskRight[8][3] = {
  { 0xe0, 0x00, 0x00},
  { 0xfc, 0x00, 0x00},
  { 0xff, 0x80, 0x00},
  { 0xff, 0xf0, 0x00},
  { 0xff, 0xfe, 0x00},
  { 0xff, 0xff, 0xc0},
  { 0xff, 0xff, 0xf8},
  { 0xff, 0xff, 0xff}
};

static U8* GetMaskRight(int x) { return &MaskRight[(x&7)][0]; }
static U8* GetMaskLeft (int x) { return &MaskLeft[(x&7)][0]; }

void LCD_L0_DrawHLine  (int x0, int y,  int x1) {
  if (x0>x1) return;  /* Check if nothing to draw */
  if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
    while (x0 <= x1) {
      XORPIXEL(x0, y);
      x0++;
    }
  } else {
    int i;
    U8 LCD_VRAMTYPE* p = OFF2PTR(XY2OFF(x0,y));
    U8* pMask = GetMaskLeft(x0);
    U8 aData[3];
    U8 aDataMasked[3];
    aData[0] = (COLOR<<5)|(COLOR<<2)|(COLOR>>1);            /* hhhgggff */
    aData[1] = (COLOR<<7)|(COLOR<<4)|(COLOR<<1)|(COLOR>>2); /* feeedddc */
    aData[2] = (COLOR<<6)|(COLOR<<3)|(COLOR);               /* ccbbbaaa */
    for (i=0; i<3; i++, pMask++) {
      aDataMasked[i] = (*(p+i) &~*pMask) | (aData[i] &*pMask);
    }
    if ((x0&~7) == (x1&~7)) {    /* Do we have to clip left and right side ? */
      U8* pMask = GetMaskRight(x1);
#if 0
      for (i=0; i<3; i++, pMask++) {
        *(p+i) = (*(p+i) &~*pMask) | (aDataMasked[i]&*pMask);
      }
#else
      *(p+0) = (*(p+0) &~*(pMask+0)) | (aDataMasked[0]&*(pMask+0));
      *(p+1) = (*(p+1) &~*(pMask+1)) | (aDataMasked[1]&*(pMask+1));
      *(p+2) = (*(p+2) &~*(pMask+2)) | (aDataMasked[2]&*(pMask+2));
#endif
      return;
    }
    *p = aDataMasked[0];
    *(p+1) = aDataMasked[1];
    *(p+2) = aDataMasked[2];
    p+=3;
    x0 = (x0&~7)+8;
/* Draw optimized portion */
    {
      int Len = (x1-x0+1)>>3;
      if (Len >0) {
        x0 += Len<<3;
        do {
          *p     = aData[0];
          *(p+1) = aData[1];
          *(p+2) = aData[2];
          p+=3;
        } while (--Len);
      }
    }
    /* Draw right portion */
    if ((x1&7)!=7) {
      U8* pMask = GetMaskRight(x1);
      for (i=0; i<3; i++, pMask++) {
        *(p+i) = (*(p+i) &~*pMask) | (aData[i]&*pMask);
      }
    }
    
  }
}

/*
        *********************************************************
        *                                                       *

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -