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

📄 show.c

📁 一个图形显示芯片s1d13505的应用程序
💻 C
📖 第 1 页 / 共 4 页
字号:
   y2 = nHeight-1;
   
   if (nHeight > 16)
      dy = nHeight / 16;
   else
      dy = nHeight / 4;
   
   step1 = dy + 1;    // don't include border
   step2 = dy*2 + 1;
   step3 = dy*3 + 1;
   step4 = dy*4 + 1;

   
   UpdateLut();
   
   /*
   ** Draw background colors
   */
   if (BitsPerPixel == 16) 
      {
      // Limit to 256 colors for testing.
      #undef WIDTH
      #undef HEIGHT
      #define WIDTH    12
      #define HEIGHT   8

      // Use two decimal places
      #define DECIMAL  100L

      white = 0xffff;
      
      //
      // First draw red, green, blue, and gray horizontal bars.
      //
      if (ValidResolutionForDiagonalLines(nWidth, nHeight))
         
         {
		 // Following routine will draw  color bars in Red, Green, Blue, and Grey shades faster
		 // then the code commented out below. It happens due to the fact that current HAL library does a horisontal line drawing
		 // faster then a vertical one.
		 // A bar's width is not necessary equal to a size of the screen. Here it is chosen to be this way.
		 // A bar's hight is chosen to be 1/16th of a screen hight.
		 // The forth parameter reflects a number of a color depth values possible for the 16bpp.
		 seDrawColorScale( gDevID,  x2+1, step1, 32 );
#ifdef DONT_USE
//		 printf ( " x2 %x\n", x2);
         for (x = 0; x < x2; ++x)
            {
           color = (UINT) ((0x20 * x) / x2);
//			printf ( " color %x\n", color);
            seDrawLine(gDevID, x, 1, x, step1-1, color << 11);  // red
            seDrawLine(gDevID, x, step2, x, step3-1, color);    // blue
            seDrawLine(gDevID, x, step3, x, step4-1, (color << 11) | (color << 6) | color);  // gray
            
            color = (UINT) ((0x40 * x) / x2);
            seDrawLine(gDevID, x, step1, x, step2-1, color << 5); // green
            }
#endif
         }
      else  // fill whole display with shades if resolution is too small for diagonal lines
         {
         dy = nHeight / 4;
         
         step1 = dy;
         step2 = dy*2;
         step3 = dy*3;
         step4 = nHeight;
         for (x = 0; x <= x2; ++x)
            {
            color = (UINT) ((0x1f * x) / x2);

            seDrawLine(gDevID, x, 0, x, step1-1, color << 11);  // red
            seDrawLine(gDevID, x, step2, x, step3-1, color);       // blue
            seDrawLine(gDevID, x, step3, x, step4-1, (color << 11) | (color << 6) | color);  // gray
            
            color = (UINT) ((0x3f * x) / x2);
            seDrawLine(gDevID, x, step1, x, step2-1, color << 5); // green
            }

         /* Virtual Screen Border for Screen */
         if (((nWidth > 32) && (nHeight > 8)) ||
             ((nWidth > 8) && (nHeight > 32)))
            seDrawRect(gDevID, x1, y1, (int) (x1+nWidth-1), (int) (y1+nHeight-1), white, FALSE);
         return;
         }
      

#ifdef DONT_USE
      for (y = step4; y < (long) nHeight; ++y)     // saturation
        {
         sat = MAX_COLOR - ((MAX_COLOR * (y - step4)) / (nHeight - step4));
         
         for (x = 0; x < (long) nWidth; ++x)   // hue
            {
            HSLtoRGB(x, sat, &red, &green, &blue, nWidth);  // luminance = 0.5

            red = (red * 0x1f) / MAX_COLOR;
            green = (green * 0x3f) / MAX_COLOR;
            blue = (blue * 0x1f) / MAX_COLOR;
            
            printf("(%ld,%ld)  h=%ld  s=%ld  r=%ld g=%ld b=%ld\n",
                    x, y, x, sat, red, green, blue);

            seSetPixel(gDevID, x, y, (red << 11) | (green << 5) | blue);
            }
         }
#endif         

      dx = ((nWidth-2) * DECIMAL) / WIDTH;          // dx has two decimal places
      dy = ((nHeight - step4 + 1) * DECIMAL) / HEIGHT;  // dy has two decimal places
      for (y = 0; y < HEIGHT; ++y)
         {
         sat = MAX_COLOR - ((MAX_COLOR * y) / HEIGHT);

         yTmp1 = step4 + (y*dy)/DECIMAL;
         yTmp2 = step4 + ((y+1)*dy)/DECIMAL - 1;
         
         if (yTmp2 >= (long) nHeight)
            yTmp2 = (long) nHeight - 1;

         for (x = 0; x < WIDTH; ++x)
            {
            HSLtoRGB(x, sat, &red, &green, &blue, WIDTH);  // luminance = 0.5
            
            red = (red * 0x1f) / MAX_COLOR;
            green = (green * 0x3f) / MAX_COLOR;
            blue = (blue * 0x1f) / MAX_COLOR;
            
            xTmp1 = x*dx/DECIMAL+1;
            xTmp2 = (x+1)*dx/DECIMAL;
            
            if (x == WIDTH-1)
               xTmp2 = nWidth-1;

            seDrawRect(gDevID, xTmp1, yTmp1, xTmp2, yTmp2, (red << 11) | (green << 5) | blue, TRUE);
            }
         }
      }
   else if (BitsPerPixel == 15)
      {
      // Limit to 256 colors for testing.
      #undef WIDTH
      #undef HEIGHT
      #define WIDTH    12
      #define HEIGHT   8

      // Use two decimal places
      #define DECIMAL  100L

      white = 0xffff;
      
      //
      // First draw red, green, blue, and gray horizontal bars.
      //
      if (ValidResolutionForDiagonalLines(nWidth, nHeight))
         {
		 // Same as for 16bpp.
		 seDrawColorScale( gDevID,  x2+1, step1, 32  );
#ifdef DONT_USE
         for (x = 0; x < x2; ++x)
            {

            color = (UINT) ((0x20 * x) / x2);
            seDrawLine(gDevID, x, 1, x, step1-1, color << 10);     // red
            seDrawLine(gDevID, x, step1, x, step2-1, color << 5);  // green
            seDrawLine(gDevID, x, step2, x, step3-1, color);       // blue
            seDrawLine(gDevID, x, step3, x, step4-1, (color << 10) | (color << 5) | color);  // gray
            }
#endif
         }
      else  // fill whole display with shades if resolution is too small for diagonal lines
         {
         dy = nHeight / 4;
         
         step1 = dy;
         step2 = dy*2;
         step3 = dy*3;
         step4 = nHeight;

         for (x = 0; x <= x2; ++x)
            {
            color = (UINT) ((0x1f * x) / x2);

            seDrawLine(gDevID, x, 0, x, step1-1, color << 10);     // red
            seDrawLine(gDevID, x, step1, x, step2-1, color << 5);  // green
            seDrawLine(gDevID, x, step2, x, step3-1, color);       // blue
            seDrawLine(gDevID, x, step3, x, step4-1, (color << 10) | (color << 5) | color);  // gray
            }
            

         /* Virtual Screen Border for Screen */
         if (((nWidth > 32) && (nHeight > 8)) ||
             ((nWidth > 8) && (nHeight > 32)))
            seDrawRect(gDevID, x1, y1, (int) (x1+nWidth-1), (int) (y1+nHeight-1), white, FALSE);
         return;
         }
      

#ifdef DONT_USE
      for (y = step4; y < (long) nHeight; ++y)     // saturation
        {
         sat = MAX_COLOR - ((MAX_COLOR * (y - step4)) / (nHeight - step4));
         
         for (x = 0; x < (long) nWidth; ++x)   // hue
            {
            HSLtoRGB(x, sat, &red, &green, &blue, nWidth);  // luminance = 0.5

            red = (red * 0x1f) / MAX_COLOR;
            green = (green * 0x1f) / MAX_COLOR;
            blue = (blue * 0x1f) / MAX_COLOR;
            
//            printf("(%ld,%ld)  h=%ld  s=%ld  r=%ld g=%ld b=%ld\n",
//                    x, y, x, sat, red, green, blue);

            seSetPixel(gDevID, x, y, (red << 10) | (green << 5) | blue);
            }
         }
#endif         

      dx = ((nWidth-2) * DECIMAL) / WIDTH;          // dx has two decimal places
      dy = ((nHeight - step4 + 1) * DECIMAL) / HEIGHT;  // dy has two decimal places
      
      for (y = 0; y < HEIGHT; ++y)
         {
         sat = MAX_COLOR - ((MAX_COLOR * y) / HEIGHT);

         yTmp1 = step4 + (y*dy)/DECIMAL;
         yTmp2 = step4 + ((y+1)*dy)/DECIMAL - 1;
         
         if (yTmp2 >= (long) nHeight)
            yTmp2 = (long) nHeight - 1;

         for (x = 0; x < WIDTH; ++x)
            {
            HSLtoRGB(x, sat, &red, &green, &blue, WIDTH);  // luminance = 0.5
            
            red = (red * 0x1f) / MAX_COLOR;
            green = (green * 0x1f) / MAX_COLOR;
            blue = (blue * 0x1f) / MAX_COLOR;

            xTmp1 = x*dx/DECIMAL+1;
            xTmp2 = (x+1)*dx/DECIMAL;
            
            if (x == WIDTH-1)
               xTmp2 = nWidth-1;

            seDrawRect(gDevID, xTmp1, yTmp1, xTmp2, yTmp2, (red << 11) | (green << 5) | blue, TRUE);
            }
         }
      }
   else if (BitsPerPixel == 8)
      {
      // 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
      
      // Use two decimal places
      #define DECIMAL  100L

      //
      // First draw red, green, blue, and gray horizontal bars.
      // Don't draw anything other than horizontal bars if resolution too small
      //
      if (!ValidResolutionForDiagonalLines(nWidth, nHeight))
         {
         if (nHeight >= 4)
            dy = nHeight / 4;
         else
            dy = 1;
         
         step1 = dy;
         step2 = dy*2;
         step3 = dy*3;
         step4 = nHeight;
         
         if (nWidth >= 16)
            xMax = 16;
         else
            xMax = nWidth-1;
         }
      else
         xMax = 16;

      // Avoid setting dx to 0
      if (nWidth >= 16)
         {
         dx = nWidth / 16;
         offset = -1;
         }
      else
         {
         dx = 1;
         offset = 0;
         }

      /*
      ** Draw background colors
      */

      // red bar
      seDrawRect(gDevID, 0, 0, dx+offset, step1-1, black, TRUE);
      
      for (x = 1; x < xMax; ++x)
         {
         LutIndex = GetLutIndex(LUT_RED_BAR, x, 0, (UINT) xMax, nHeight);
         
         seDrawRect(gDevID, x*dx, 0, (x+1)*dx+offset, step1+offset, LutIndex, TRUE);
         }
         
         
      // green bar
      seDrawRect(gDevID, 0, step1, dx+offset, step2-1, black, TRUE);

      for (x = 1; x < xMax; ++x)
         {
         LutIndex = GetLutIndex(LUT_GREEN_BAR, x, 0, (UINT) xMax, nHeight);

         seDrawRect(gDevID, x*dx, step1, (x+1)*dx+offset, step2-1, LutIndex, TRUE);
         }


      // blue bar
      seDrawRect(gDevID, 0, step2, dx+offset, step3-1, black, TRUE);

      for (x = 1; x < xMax; ++x)
         {
         LutIndex = GetLutIndex(LUT_BLUE_BAR, x, 0, (UINT) xMax, nHeight);

         seDrawRect(gDevID, x*dx, step2, (x+1)*dx+offset, step3-1, LutIndex, TRUE);
         }

         
      // gray bar
      seDrawRect(gDevID, 0, step3, dx+offset, step4-1, black, TRUE);

      for (x = 1; x < xMax; ++x)
         {
         LutIndex = GetLutIndex(LUT_GRAY_BAR, x, 0, (UINT) xMax, nHeight);

         seDrawRect(gDevID, x*dx, step3, (x+1)*dx+offset, step4-1, LutIndex, TRUE);
         }
         

      if (!ValidResolutionForDiagonalLines(nWidth, nHeight))
         {
         if (ValidResolutionForBorder(nWidth, nHeight))
            seDrawRect(gDevID, x1, y1, (int) (x1+nWidth-1), (int) (y1+nHeight-1), white, FALSE);

         return;
         }

      dx = ((nWidth-2) * DECIMAL) / WIDTH;              // dx has two decimal places
      dy = ((nHeight - step4 + 1) * DECIMAL) / HEIGHT;  // dy has two decimal places
      
      for (y = 0; y < HEIGHT; ++y)
         {
         sat = MAX_COLOR - ((MAX_COLOR * y) / 8);
         yTmp1 = step4 + (y*dy)/DECIMAL;
         yTmp2 = step4 + (((y+1)*dy)/DECIMAL) -1;

         for (x = 0; x < WIDTH; ++x)
            {
            xTmp1 = x*dx/DECIMAL+1;
            xTmp2 = (x+1)*dx/DECIMAL;

            if (x == WIDTH-1)
               xTmp2 = nWidth-1;

            LutIndex = GetLutIndex(LUT_HUE, x, y, WIDTH, HEIGHT);

            seDrawRect(gDevID, xTmp1, yTmp1, xTmp2, yTmp2, LutIndex, TRUE);
            }
         }
      }
   else
      return;

      
   /* Diagonal Lines */
   seDrawLine(gDevID, x1+1, y1+step4, (int) (x1+nWidth-2), (int) (y1+nHeight-2), white);
   seDrawLine(gDevID, (int) (x1+nWidth-2), y1+step4, x1+1, (int) (y1+nHeight-2), white);

   /* Virtual Screen Border for Screen */
   seDrawRect(gDevID, x1, y1, (int) (x1+nWidth-1), (int) (y1+nHeight-1), white, FALSE);
   }

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

void ShowOneMode( int BitsPerPixel, char *str )
   {
   UINT nWidth;
   UINT nHeight;
   int tmp;
   DWORD lSize;
   DWORD addr;
   DWORD dwVal;
   DWORD yVirt;

#ifdef LCEVBSH3
   volatile DWORD *dwPtr;
#endif

   /*
   ** It was decided that the 13505 HAL would not refuse an attempt to set
   ** a color depth greater than can be supported by display memory. So...
   ** we have to check for ourselves whether we can fit into memory.
   */
   seGetScreenSize( gDevID, &nWidth, &nHeight );

   seGetLastUsableByte( gDevID, &lSize );

   tmp = (BitsPerPixel == 15) ? 16 : BitsPerPixel;

   if ((((DWORD) nWidth * nHeight * 2 * tmp) / 16)  > lSize)
      return;

⌨️ 快捷键说明

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