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

📄 show.c

📁 一个图形显示芯片s1d13505的应用程序
💻 C
📖 第 1 页 / 共 4 页
字号:
   long step1, step2, step3, step4, step5, step6;
   long dStep;
   
   step1 = width/6;
   step2 = width/3;
   step3 = width/2;
   step4 = (width * 2) / 3;
   step5 = (width * 5) / 6;
   step6 = width-1;
   dStep = step2 - step1;

      
   // red hue
   if (hue < step1)
      *red = MAX_COLOR;
   else if (hue < step2)
      *red = MAX_COLOR - (MAX_COLOR * (hue - step1) / dStep);
   else if (hue < step4)
      *red = 0;
   else if (hue < step5)
      *red = MAX_COLOR * (hue - step4) / dStep;
   else
      *red = MAX_COLOR;
      
   // green hue
   if (hue < step1)
      *green = (MAX_COLOR * hue) / dStep;
   else if (hue < step3)
      *green = MAX_COLOR;
   else if (hue < step4)
      *green = MAX_COLOR - (MAX_COLOR * (hue - step3) / dStep);
   else
      *green = 0;
      
   // blue hue
   if (hue < step2)
      *blue = 0;
   else if (hue < step3)
      *blue = (MAX_COLOR * (hue - step2) / dStep);
   else if (hue < step5)
      *blue = MAX_COLOR;
   else
      *blue = MAX_COLOR - (MAX_COLOR * (hue - step5) / dStep);
      
   // adjust red for sat and lum
   *red = LUM + ((((long) *red - LUM) * sat) / MAX_COLOR);
   
   // adjust green for sat and lum
   *green = LUM + ((((long) *green - LUM) * sat) / MAX_COLOR);

   // adjust blue for sat and lum
   *blue = LUM + ((((long) *blue - LUM) * sat) / MAX_COLOR);
}

/*-------------------------------------------------------------------------*/

// There are 256-15*4-1=195 LUT entries available for HSL
// (15 shades of red, green, blue, and gray shades, and one LUT entry for black)
// Let's break the HSL display into 15x13 (15 hue horz, 13 sat vert)
#undef WIDTH
#undef HEIGHT
#define WIDTH    15
#define HEIGHT   8

/*
** Note that only the upper four bits of the LUT are actually used.
*/
static BYTE LUT1[2*3] =
{
  0x00, 0x00, 0x00,  0xF0, 0xF0, 0xF0
};

static BYTE LUT2_Color[4*3] =
{  
   0x00, 0x00, 0x00,  0xF0, 0x00, 0x00,  0x00, 0x00, 0xF0,  0xF0, 0xF0, 0xF0
};

static BYTE LUT2_Mono[4*3] =
{  
   0x00, 0x00, 0x00,  0x50, 0x50, 0x50,  0xA0, 0xA0, 0xA0,  0xF0, 0xF0, 0xF0
};

static BYTE LUT4_Color[16*3] =
{ 
   0x00, 0x00, 0x00,  0x00, 0x00, 0xA0,  0x00, 0xA0, 0x00,  0x00, 0xA0, 0xA0,
   0xA0, 0x00, 0x00,  0xA0, 0x00, 0xA0,  0xA0, 0xA0, 0x00,  0xA0, 0xA0, 0xA0,
   0x00, 0x00, 0x00,  0x00, 0x00, 0xF0,  0x00, 0xF0, 0x00,  0x00, 0xF0, 0xF0,
   0xF0, 0x00, 0x00,  0xF0, 0x00, 0xF0,  0xF0, 0xF0, 0x00,  0xF0, 0xF0, 0xF0
};


void UpdateLut(void)
   {
   int LutIndex;
   BYTE lut[3];
   UINT BitsPerPixel;
   int x, y;
   int i;
   long sat;
   long red, green, blue;
   BYTE regPanelType;
   
   seGetBitsPerPixel(gDevID, &BitsPerPixel);
   
   seGetReg(gDevID, REG_PANEL_TYPE, &regPanelType);

   /*
   ** Based on the current BPP - set the LUT to default values.
   */
   if (regPanelType & 0x04)   /* color */
      {
      switch (BitsPerPixel)
         {
         case 1:
            seSetLut( gDevID, LUT1, 2 );
            break;

         case 2:
            seSetLut( gDevID, LUT2_Color, 4 );
            break;

         case 4:
            seSetLut( gDevID, LUT4_Color, 16 );
            break;

         case 8:
            // Use two decimal places
            #define DECIMAL  100L

            LutIndex = 0;
            
            lut[RED] = 0;
            lut[GREEN] = 0;
            lut[BLUE] = 0;
            seSetLutEntry(gDevID, LutIndex, lut);
            black = 0;
            ++LutIndex;


            // red bar
            for (x = 1; x <= WIDTH; ++x)
               {
               lut[RED] = (BYTE) (x << 4);  // red
               lut[GREEN] = 0;  // green
               lut[BLUE] = 0;  // blue
               seSetLutEntry(gDevID, LutIndex, lut);
               ++LutIndex;
               }

         
            // green bar
            for (x = 1; x <= WIDTH; ++x)
               {
               lut[RED] = 0;  // red
               lut[GREEN] = (BYTE) (x << 4);  // green
               lut[BLUE] = 0;  // blue
               seSetLutEntry(gDevID, LutIndex, lut);
               ++LutIndex;
               }


            // blue bar
            for (x = 1; x <= WIDTH; ++x)
               {
               lut[RED] = 0;  // red
               lut[GREEN] = 0;  // green
               lut[BLUE] = (BYTE) (x << 4);  // blue
               seSetLutEntry(gDevID, LutIndex, lut);
               ++LutIndex;
               }

         
            // gray bar
            for (x = 1; x <= WIDTH; ++x)
               {
               lut[RED] = (BYTE) (x << 4);  // red
               lut[GREEN] = (BYTE) (x << 4);  // green
               lut[BLUE] = (BYTE) (x << 4);  // blue
               seSetLutEntry(gDevID, LutIndex, lut);
               ++LutIndex;
               }
         
            white = LutIndex - 1;
         
            for (y = 0; y < HEIGHT; ++y)
               {
               sat = MAX_COLOR - ((MAX_COLOR * y) / 8);

               for (x = 0; x < WIDTH; ++x)
                  {
                  HSLtoRGB(x, sat, &red, &green, &blue, WIDTH);  // luminance = 0.5
            
                  lut[RED] = (BYTE) (((red * 0x0f) / MAX_COLOR) << 4);
                  lut[GREEN] = (BYTE) (((green * 0x0f) / MAX_COLOR) << 4);
                  lut[BLUE] = (BYTE) (((blue * 0x0f) / MAX_COLOR) << 4);

                  seSetLutEntry(gDevID, LutIndex, lut);
               
                  ++LutIndex;
            
                  if (LutIndex > 256)
                     break;
                  }
               }
            break;

         default:
            break;
         }
      }
   else switch (BitsPerPixel)   /* mono */
      {
      case 1:
         seSetLut( gDevID, LUT1, 2 );
         break;

      case 2:
         seSetLut( gDevID, LUT2_Mono, 4 );
         break;

      case 4:
         for (i = 0; i < 16; ++i)
            {
            lut[RED] = (BYTE) (i << 4);
            lut[GREEN] = (BYTE) (i << 4);
            lut[BLUE] = (BYTE) (i << 4);
            seSetLutEntry( gDevID, i, lut );
            }
         break;

      case 8:
         // Gray Shades go from black to white from width=0 to width=WIDTH
         black = 0;
         white = 0xff;

         i = 0;
            
         while (i < 256)
            {
            for (x = 0; (x < WIDTH) && (i < 256); ++x, ++i)
               {
               lut[RED] = (BYTE) (i << 4);
               lut[GREEN] = (BYTE) (i << 4);
               lut[BLUE] = (BYTE) (i << 4);
               seSetLutEntry(gDevID, i, lut);
               }
            }
         break;

      default:
         break;
      }
   }

/*-------------------------------------------------------------------------*/

//
// type: LUT_RED_BAR, LUT_GREEN_BAR, LUT_BLUE_BAR, or LUT_HUE
// For LUT_HUE, the top left corner of the HUE rectangle is x=0, y=0 and width
//
int GetLutIndex(int type, long x, long y, UINT width, UINT height)
   {
   UINT BitsPerPixel;
   BYTE regPanelType;
   long xTmp, yTmp;
   
   // Use two decimal places
   #define SCALE   100L
   
   seGetBitsPerPixel(gDevID, &BitsPerPixel);

   seGetReg(gDevID, REG_PANEL_TYPE, &regPanelType);

   switch (BitsPerPixel)
      {
      case 1:
         break;
         
      case 2:
         break;
         
      case 4:
         break;
         
      case 8:
         if (!(regPanelType & 0x04))   /* monochrome */
            {
            x = x % width;

            if (x == 0)
               return black;
            else
               return (int) ((x*14)/(width-1) + 1);
            }
            
         switch (type)
            {
            case LUT_RED_BAR:    // indices 1-15
               if (x == 0)
                  return black;
               else
                  return (int) ((x*14)/(width-1) + 1);
               break;
         
            case LUT_GREEN_BAR:  // indices 16-30
               if (x == 0)
                  return black;
               else
                  return (int) ((x*14)/(width-1) + 16);
               break;
         
            case LUT_BLUE_BAR:   // indices 31-45
               if (x == 0)
                  return black;
               else
                  return (int) ((x*14)/(width-1) + 31);
               break;
         
            case LUT_GRAY_BAR:   // indices 46-60
               if (x == 0)
                  return black;
               else
                  return (int) ((x*14)/(width-1) + 46);
               break;
         
            case LUT_HUE:        // indices 61-180
               xTmp = (x * (WIDTH-1))/(width-1);
               yTmp = (y * (HEIGHT-1))/(height-1);
               
               return (int) (xTmp + yTmp*WIDTH + 61);
               break;
            }
         break;
      }
   return 0;
   }

/*-------------------------------------------------------------------------*/

int ValidResolutionForDiagonalLines(UINT width, UINT height)
   {
   // Don't draw anything other than horizontal bars if resolution is greater than (64 x 16) or (16 x 64)
   //
   if ( ((width > 64) && (height > 16)) ||
        ((width > 16) && (height > 64)) )
      {
#ifdef _DEBUG      
      printf("ValidResolutionForDiagonalLines(%u, %u) returns TRUE\n", width, height);
#endif
      return TRUE;
      }
   else
      {
#ifdef _DEBUG      
      printf("ValidResolutionForDiagonalLines(%u, %u) returns FALSE\n", width, height);
#endif
      return FALSE;
      }
   }

/*-------------------------------------------------------------------------*/

int ValidResolutionForBorder(UINT width, UINT height)
   {
   // Don't draw anything other than horizontal bars if resolution is greater than (64 x 16) or (16 x 64)
   //
   if ( ((width > 8) && (height > 32)) ||
        ((width > 32) && (height > 8)) )
      {
#ifdef _DEBUG
      printf("ValidResolutionForBorder(%u, %u) returns TRUE\n", width, height);
#endif
      return TRUE;
      }
   else
      {
#ifdef _DEBUG
      printf("ValidResolutionForBorder(%u, %u) returns FALSE\n", width, height);
#endif
      return FALSE;
      }
   }

/*-------------------------------------------------------------------------*/

// for 8/16 bpp only
void DrawHslScreen(void)
   {
   UINT nWidth;
   UINT nHeight;
   UINT color = 0xffff;
   long x, y, dx, dy;
   long xMax;
   long xTmp1, yTmp1, xTmp2, yTmp2;
   long xc, yc;
   UINT BitsPerPixel;
   long x1, y1, x2, y2;
   long sat;
   long red, green, blue;
   BYTE regPanelType;
   long step1, step2, step3, step4;
   int LutIndex;
   int offset;
   

   seGetScreenSize(gDevID, &nWidth, &nHeight);
   seGetBitsPerPixel(gDevID, &BitsPerPixel);

   seGetReg(gDevID, REG_PANEL_TYPE, &regPanelType);

//   printf( "%d * %d * %d Bpp\n", nWidth, nHeight, BitsPerPixel );

   seDisplayFifo(gDevID, FALSE);

   xc = nWidth / 2;
   yc = nHeight / 2;

   x1 = 0;
   y1 = 0;
   x2 = nWidth-1;

⌨️ 快捷键说明

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