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

📄 bmp.c

📁 epson公司的一个关于s1d13706的低层驱动程序
💻 C
📖 第 1 页 / 共 3 页
字号:
   pImgBuf = ImgBuf;
   
   /*printf("pImgBuf:%lx, ff:%d, DstX:%d, DstY:%d ImgH:%d, ImgW:%d\n",pImgBuf, ff, DstX, DstY, ImgH, ImgW);
   **printf("VW:%d, VH:%d, Bpp:%d\n",VirtualW, VirtualH, Bpp );
   **getch();
   */
   
   pTmp = pImgBuf;
   
   Y=ImgH+DstY-1; 
   
   /* adjust ImgH */
   if ( ImgH > (VirtualH-DstY) )
   {
      /* read from the image file, decode it if necessary, 
      ** forward file pointer by (DstY+VirtualH-ImgH) lines
      */
      PreReadLine = DstY+ImgH-VirtualH;
      ImgH = VirtualH-DstY;
   }
   
   
   DesiredBpp = Bpp;
   
   while (forever)
   {
      memcpy(&Val, ptr, 2);    /* read in a word */
      ptr += 2;

      /*    printf("Val:%04x\n",Val);*/
      switch ( Val )
      {
      case 0x0100:   /* end of bmp */
         if ( LineCount >= PreReadLine )
         {
            Translate( pImgBuf, LineWidth, Bpp );
            seLineBlt( pImgBuf, LineWidth, DstX+ColumnCount, Y-LineCount, VirtualW, PhysicalWidth, DesiredBpp );
         }
         return SUCCEED;
         
      case 0x0000:   /* end of a line */
         if ( LineCount >= PreReadLine )
         {
            Translate( pImgBuf, LineWidth, Bpp );
            seLineBlt( pImgBuf, LineWidth, DstX+ColumnCount, Y-LineCount, VirtualW, PhysicalWidth, DesiredBpp );
         }
         LineCount++;
         LineWidth = 0;
         ColumnCount = 0;
         pTmp = pImgBuf;
         break;
         
      case 0x0200:   /* delta mode, jump right & down */
         if ( LineCount >= PreReadLine )
         {
            Translate( pImgBuf, LineWidth, Bpp );
            seLineBlt( pImgBuf, LineWidth, DstX+ColumnCount, Y-LineCount, VirtualW, PhysicalWidth, DesiredBpp );
         }

         memcpy(&tmp, ptr, 2);    /* read in the next word */
         ptr += 2;
         ColumnCount += (tmp&0xff) + LineWidth;
         LineCount += (tmp&0xff00)>>8;
         LineWidth = 0;
         pTmp = pImgBuf;
         break;
         
      default:
         if ( !(Val&0xff) )
         {
            /* absolute mode */
            tmp =  ( ((Val&0xff00)>>8) * Bpp +4 ) /8;

            len = (tmp+1)&0xfffe;
            memcpy(pTmp, ptr, len);      /* read in more bytes, WORD aligned */
            ptr += len;

            pTmp += tmp;
            LineWidth += tmp*8/Bpp;
         }
         else
         {
            /* encode mode */
            tmp = ((Val & 0xff) * Bpp +4)/8;    /* # of bytes to repeat */
            tmp1 = (Val& 0xff00)>>8;   /* value of the byte */
            for ( i=0; i<tmp; i++ )
            {
               *pTmp = (BYTE)tmp1;
               pTmp++;
            }
            LineWidth += tmp*8/Bpp;
         }
         break;
      }
   }

   return FAIL;
}

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

#else

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

unsigned ShowCompressed( int ff, unsigned DstX, unsigned DstY, unsigned ImgH, unsigned ImgW, unsigned VirtualW, unsigned VirtualH, unsigned PhysicalWidth, unsigned Bpp )
{
   unsigned LineCount=0;
   unsigned LineWidth=0;
   unsigned ColumnCount=0;
   unsigned Val, Y, tmp, tmp1, i;
   unsigned PreReadLine=0;
   unsigned retVal = SUCCEED;

#if defined(INTEL_W32) || defined(INTEL_DOS)
   BYTE far * pTmp;
   BYTE far *pImgBuf;
#else
   BYTE *pTmp;
   BYTE *pImgBuf;
#endif

   unsigned DesiredBpp;
   int forever = TRUE;
   
   pImgBuf = (BYTE far*) malloc( 256+ImgW*Bpp/8 );

   if( pImgBuf == NULL )
      {
      printf("\n no memory...");
      close(ff);
      free(pImgBuf);
      retVal = FAIL;
      }
   else
      {
      /*printf("pImgBuf:%lx, ff:%d, DstX:%d, DstY:%d ImgH:%d, ImgW:%d\n",pImgBuf, ff, DstX, DstY, ImgH, ImgW);
      **printf("VW:%d, VH:%d, Bpp:%d\n",VirtualW, VirtualH, Bpp );
      **getch();
      */
      
      pTmp = pImgBuf;
      
      Y=ImgH+DstY-1; 
      
      /* adjust ImgH */
      if ( ImgH > (VirtualH-DstY) )
      {
         /* read from the image file, decode it if necessary, 
         ** forward file pointer by (DstY+VirtualH-ImgH) lines
         */
         PreReadLine = DstY+ImgH-VirtualH;
         ImgH = VirtualH-DstY;
      }
      
      
      DesiredBpp = Bpp;
      
      while (forever)
      {
         read( ff, &Val, 2 );    /* read in a word */
         /*    printf("Val:%04x\n",Val);*/
         switch ( Val )
         {
         case 0x0100:   /* end of bmp */
            if ( LineCount >= PreReadLine )
            {
               Translate( pImgBuf, LineWidth, Bpp );
               seLineBlt( pImgBuf, LineWidth, DstX+ColumnCount, Y-LineCount, VirtualW, PhysicalWidth, DesiredBpp );
            }
            free(pImgBuf);
            retVal = SUCCEED;
            forever = FALSE;
            break;
            
         case 0x0000:   /* end of a line */
            if ( LineCount >= PreReadLine )
            {
               Translate( pImgBuf, LineWidth, Bpp );
               seLineBlt( pImgBuf, LineWidth, DstX+ColumnCount, Y-LineCount, VirtualW, PhysicalWidth, DesiredBpp );
            }
            LineCount++;
            LineWidth = 0;
            ColumnCount = 0;
            pTmp = pImgBuf;
            break;
            
         case 0x0200:   /* delta mode, jump right & down */
            if ( LineCount >= PreReadLine )
            {
               Translate( pImgBuf, LineWidth, Bpp );
               seLineBlt( pImgBuf, LineWidth, DstX+ColumnCount, Y-LineCount, VirtualW, PhysicalWidth, DesiredBpp );
            }
            read( ff, &tmp, 2 );    /* read in the next word */
            ColumnCount += (tmp&0xff) + LineWidth;
            LineCount += (tmp&0xff00)>>8;
            LineWidth = 0;
            pTmp = pImgBuf;
            break;
            
         default:
            if ( !(Val&0xff) )
            {
               /* absolute mode */
               tmp =  ( ((Val&0xff00)>>8) * Bpp +4 ) /8;
               read( ff, pTmp, (tmp+1)&0xfffe );      /* read in more bytes, WORD aligned */
               pTmp += tmp;
               LineWidth += tmp*8/Bpp;
            }
            else
            {
               /* encode mode */
               tmp = ((Val & 0xff) * Bpp +4)/8;    /* # of bytes to repeat */
               tmp1 = (Val& 0xff00)>>8;   /* value of the byte */
               for ( i=0; i<tmp; i++ )
               {
                  *pTmp = (BYTE)tmp1;
                  pTmp++;
               }
               LineWidth += tmp*8/Bpp;
            }
            break;
         }
      }
   }

   return retVal;
}

#endif
   
/*-----------------------------------------------------------------------*/
#ifdef BUILD_WITH_INTERNAL_BMP_IMAGES

unsigned ShowUncompressed( unsigned char *ptr, unsigned DstX, unsigned DstY, unsigned ImgH, unsigned ImgW, unsigned VirtualW, unsigned VirtualH, unsigned PhysicalWidth, unsigned Bpp )
{
   unsigned Count, Y;
   unsigned len;

#ifdef LINEAR_ADDRESSES_SUPPORTED
   BYTE *pImgBuf;
#else
   BYTE far *pImgBuf;
#endif

   unsigned DesiredBpp;
   
   pImgBuf = ImgBuf;

   /* adjust ImgH */
   if ( ImgH > (VirtualH-DstY) )
   {
      /* 
      ** read from the image file, decode it if necessary, 
      ** forward file pointer by (DstY+VirtualH-ImgH) lines
      */
      
      for ( Y=DstY+ImgH-VirtualH; Y!=0; Y--)
         {
         len = (unsigned)((ImgW*Bpp/8+3)&0xfffc);
         memcpy(pImgBuf, ptr, len);
         ptr += len;
         }
      ImgH = VirtualH-DstY;
   }
   

   DesiredBpp = Bpp;
   
   if (DesiredBpp == 24)
      DesiredBpp = 16;
   
   
   for( Y=ImgH+DstY; Y!=DstY; Y-- )
   {
      /* Read a line from the image file, decode RLE if required to pImgBuf */
      /* line break if find word 0x0000 or 0x0200. */
      Count = (unsigned)((ImgW*Bpp/8+3)&0xfffc); 
      memcpy(pImgBuf, ptr, Count);
      ptr += Count;
      Translate( pImgBuf, Count, Bpp );

      /* Blt a line to the virtual screen */
      seLineBlt( pImgBuf, ImgW, DstX, Y-1, VirtualW, PhysicalWidth, DesiredBpp );
   }
   
   return SUCCEED;
}

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

#else

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

unsigned ShowUncompressed( int ff, unsigned DstX, unsigned DstY, unsigned ImgH, unsigned ImgW, unsigned VirtualW, unsigned VirtualH, unsigned PhysicalWidth, unsigned Bpp )
{
   unsigned Count, Y;
#ifdef LINEAR_ADDRESSES_SUPPORTED
   BYTE *pImgBuf;
#else
   BYTE far *pImgBuf;
#endif
   unsigned DesiredBpp;
   
   pImgBuf = (BYTE *) malloc( 256+ImgW*Bpp/8 );

   if( pImgBuf == NULL )
   {
      printf("\n no memory...");
      close(ff);
      free(pImgBuf);
      return FAIL;
   }
   
   /* adjust ImgH */
   if ( ImgH > (VirtualH-DstY) )
   {
      /* 
      ** read from the image file, decode it if necessary, 
      ** forward file pointer by (DstY+VirtualH-ImgH) lines
      */
      
      for ( Y=DstY+ImgH-VirtualH; Y!=0; Y--)
         read ( ff, pImgBuf, (unsigned)((ImgW*Bpp/8+3)&0xfffc) );
      ImgH = VirtualH-DstY;
   }
   

   DesiredBpp = Bpp;
   
   if (DesiredBpp == 24)
      DesiredBpp = 16;
   
   
   for( Y=ImgH+DstY; Y!=DstY; Y-- )
   {
      /* Read a line from the image file, decode RLE if required to pImgBuf */
      /* line break if find word 0x0000 or 0x0200. */
      Count = (unsigned)((ImgW*Bpp/8+3)&0xfffc); 
      read ( ff, pImgBuf, Count);
      Translate( pImgBuf, Count, Bpp );

      /* Blt a line to the virtual screen */
      seLineBlt( pImgBuf, ImgW, DstX, Y-1, VirtualW, PhysicalWidth, DesiredBpp );
   }
   
   free(pImgBuf);
   return SUCCEED;
}

#endif

/*--------------------------------------------------------------------
* Function:
* Translate 24 Bpp image to 16 bpp image.
*--------------------------------------------------------------------*/

#if defined(INTEL_W32) || defined(INTEL_DOS)
void Translate( BYTE far *pImgBuf, unsigned LineWidth, unsigned Bpp )
#else
void Translate( BYTE *pImgBuf, unsigned LineWidth, unsigned Bpp )
#endif
{
#if defined(INTEL_W32) || defined(INTEL_DOS)
   BYTE far *pTmp1;
   WORD far *pTmp2;
#else
   BYTE *pTmp1;
   WORD *pTmp2;
#endif

   unsigned b, g, r, i;
   
   if ( Bpp==24 )
   {
   /*
   ** Truncate the 24bpp color to 16bpp color.
   ** Only the most significant bits of the colors are saved.
   */
      pTmp1 = pImgBuf;
      pTmp2 = (WORD *)pImgBuf;
      for ( i=0; i<LineWidth/3; i++ )
      {
         b = (*pTmp1++) >>3;
         g = (*pTmp1++) <<3 & 0x07e0;
         r = (*pTmp1++) <<8 & 0xf800;
         *pTmp2++ = (WORD) (b|g|r);
      }
   }
}

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

⌨️ 快捷键说明

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