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

📄 blittest.c

📁 nucleus 文件系统,内核和彩色图形系统,在小系统上非常好用
💻 C
字号:
/*  %kw # %v    %n    %d    %t # */
/* Version # 2    blittest.C    22-Feb-96    12:02:10 # */
/***************************************************************/
#define byte unsigned char
#define word unsigned short
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include "metawndo.h"      /* master MetaWINDOW include file */
#include "neil2.h"

extern palData RGBdata[];
void* mcMalloc( unsigned int size );
void mcFree( void *address );
void Waiting(int a);

void blittest()
{
void ReadPalette(int plNum,int bgnIdx, int endIdx, palData *palPtr);
void TranslateTable( long *xlt, Byte imBits, Byte imPlanes,  palData *palette, palData *imgPal );
void ColorDiffusionDither(image *imgIn, palData *imgPal,
						  image *imgOut, palData *palPtr);
void quit(void);
long     xTable[256]; 
unsigned int imgSize;  
   int   i = 0, page = 0;
/*   grafPort *page1Port, *page2Port; */
   grafPort *scrnport;
   rect scrnR, neilR, neilR2, neilR3;
   imageHeader *imgHdr;
	image    *bmpImg, *dstImage, *dstImage2;
	mwEvent waitEvent;

   bmpImg=(image *)neil2;
   imgHdr=(imageHeader *)neil2;
   neilR.Xmin = 0;
   neilR.Ymin = 0;
   neilR.Xmax = imgHdr->imWidth - 1;
   neilR.Ymax = imgHdr->imHeight - 1;
   neilR2.Xmin = imgHdr->imWidth + 20;
   neilR2.Ymin = 0;
   neilR2.Xmax = imgHdr->imWidth + 20 + imgHdr->imWidth - 1;
   neilR2.Ymax = imgHdr->imHeight - 1;

   /* get pointer to current (default) port */
   GetPort( &scrnport );
   SetPort(scrnport);

   /* extend the ports bitmap to cover both display pages */
   ScreenRect( &scrnR );
   BackColor(0);
/*   page1Port = CreateBitmap(cMEMORY, scrnR.Xmax, scrnR.Ymax);
   if (page1Port == NULL) return;
   page2Port = CreateBitmap(cMEMORY, scrnR.Xmax, scrnR.Ymax);
   if (page2Port == NULL)
   {
	   DestroyBitmap(page1Port);
	   return;
   }*/

	ReadPalette(1, 0, 255, RGBdata);
	TranslateTable( xTable, 8, 1, RGBdata, neil2_palette );
    imgSize=XlateImage( bmpImg, NULL, scrnport->portMap->pixBits,1, xTable ); 
    dstImage = (byte *) mcMalloc( imgSize );
    dstImage2 = (byte *) mcMalloc( imgSize );
    XlateImage( bmpImg, dstImage, scrnport->portMap->pixBits,1, xTable ); 
	EraseRect( &scrnR );

	if (scrnport->portMap->pixBits == 8)
	{
/*	   OffsetRect(&neilR, ((scrnR.Xmax >> 1) - imgHdr->imWidth),
		   ((scrnR.Ymax - imgHdr->imHeight) >> 1));
	   OffsetRect(&neilR2, ((scrnR.Xmax >> 1) - imgHdr->imWidth),
		   ((scrnR.Ymax - imgHdr->imHeight) >> 1)); */
	   WriteImage(&neilR, dstImage);
	   MoveTo(neilR.Xmin, neilR.Ymax + 10);
	   DrawString("XlateImage");
		ColorDiffusionDither(bmpImg, neil2_palette, dstImage2, RGBdata);
	   WriteImage(&neilR2, dstImage2);
	   MoveTo(neilR2.Xmin, neilR2.Ymax + 10);
	   DrawString("ColorDiffusionDither");
	}
	else
	{
/*	   OffsetRect(&neilR, ((scrnR.Xmax - imgHdr->imWidth) >> 1),
		   ((scrnR.Ymax - imgHdr->imHeight) >> 1));
	   OffsetRect(&neilR2, ((scrnR.Xmax - imgHdr->imWidth) >> 1),
		   ((scrnR.Ymax - imgHdr->imHeight) >> 1)); */
	   WriteImage(&neilR, dstImage);
	   MoveTo(neilR.Xmin, neilR.Ymax + 10);
	   DrawString("XlateImage");
	}

    mcFree(dstImage);
    mcFree(dstImage2);

/*   SetPort(page1Port);
   EraseRect( &scrnR );

   while( i++ < 50 ) {*/

      /* use other page */
/*      if( page )
	  {
		 CopyBlit(page2Port, scrnport, &scrnR, &scrnR);
         page = 0;
		 SetPort(page1Port);
	  }
      else
	  {
		 CopyBlit(page1Port, scrnport, &scrnR, &scrnR);
         page = 1;
		 SetPort(page2Port);
	  }


   }

   SetPort(scrnport);
   DestroyBitmap(page1Port);
   DestroyBitmap(page2Port);*/

/*	neilR3.Xmin = 0;
	neilR3.Ymin = (scrnR.Ymax >> 1);
	neilR3.Xmax = (scrnR.Xmax >> 1);
	neilR3.Ymax = scrnR.Ymax;
	  ZoomBlit(scrnport, scrnport, &neilR, &neilR3);
	   MoveTo(neilR3.Xmin, neilR3.Ymin - 10);
	   DrawString("Zoom Up");
	  neilR.Xmin = neilR3.Xmax;
	  neilR.Xmax += neilR.Xmin;
	  ZoomBlit(scrnport, scrnport, &neilR3, &neilR);
	   MoveTo(neilR.Xmin, neilR.Ymax + 10);
	   DrawString("Zoom Down"); */
#ifndef CYCLE
	MoveTo( 0,scrnR.Ymax - 20 );
	DrawString( "Press 'x' to exit" );
	MoveTo( 0,scrnR.Ymax - 10 );
	DrawString( "any other key to continue" );
	  while(!KeyEvent(1, &waitEvent));
	  if((waitEvent.eventChar == 'x') || (waitEvent.eventChar == 'X')) quit();
#else
#ifdef _MNT_
	  KeyEvent(0, &waitEvent);
	  if((waitEvent.eventChar == 'x') || (waitEvent.eventChar == 'X')) quit();
#endif
   Waiting(150);
#endif

}


/* EXTRACTED FROM BMPMGR.C */
/* build a color translation table */
//void TranslateTable( long *xlt, pcxHead *pcxhdr, palData *palette )
void TranslateTable( long *xlt, Byte imBits, Byte imPlanes,  palData *palette, palData *imgPal )
{
   grafPort *thePort;      /* current port */
   long  dstcolors;        /* number of colors in port */
   long  srcolors;         /* number of colors in pcx file */
   palData  RGB;
   int i, maxcolors;
   srcolors=1;
   /* how many colors in source image file ? */
   srcolors = srcolors << (imBits * imPlanes);
   srcolors--;
   
   /* how many colors in current port ? */
   dstcolors = QueryColors();
   maxcolors = srcolors + 1;

   /* going from palette based to RGB ? */
   if( srcolors <= 255 && dstcolors > 255 ) {
      /*
      Make a translate table that will convert palette references into
      16 bit RGB values
      */
      GetPort( &thePort );
      for( i = 0; i < 256; i++ ) {
		  if (dstcolors > 65535)
		  {	/* 24-bit color */
				xlt[i]  = ((imgPal[i].palBlue & 0xFF00) << 8);
				xlt[i] |= (imgPal[i].palGreen & 0xFF00);
				xlt[i] |= ((imgPal[i].palRed & 0xFF00) >> 8);
		  }
		  else
		  {	/* 16-bit color */
			 if( thePort->portMap->mapFlags & mf565 ) {
				// 5:6:5 RGB format
				xlt[i]  = (imgPal[i].palRed         ) & 0xF800;
				xlt[i] |= (imgPal[i].palGreen >> 5  ) & 0x07E0;
			 }
			 else {
				// 5:5:5 RGB format
				xlt[i]  = ( imgPal[i].palRed  >> 1  ) & 0x7C00;
				xlt[i] |= (imgPal[i].palGreen >> 6  ) & 0x03E0;
			 }
			 xlt[i] |= (imgPal[i].palBlue  >> 11 ) & 0x001F;
		  }
      }

      return;
   }

   /* going from RGB based to palette based ? */
   if( srcolors > 255 && dstcolors <= 255 ) {
      /*
      Make a translate table that will reduce a 24 bit per pixel source
      to colors in the current (hopefull optimized for this image) palette.
      XlateImage reduces the colors to the 512 most significant,
      then we translate those to the best 256 we got
      */
      for( i = 0; i < 512; i++ ) {
         RGB.palRed   = (i & 0x1C0) << 7;    //  3 msbs of red
         RGB.palGreen = (i & 0x038) << 10;   //  3 msbs of green
         RGB.palBlue  = (i & 0x007) << 13;   //  3 msbs of blue
         xlt[i] = (long) FindClosestRGB( &RGB, palette );
      }

      return;
   }


   /* make a null translate table (no color conversion) 
   when the source color values are compatible with the current display */


   for( i = 0; i < maxcolors; i++ )
      xlt[i] =  (long) FindClosestRGB(&imgPal[i], palette );

}

⌨️ 快捷键说明

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