Esempio n. 1
0
void ScreenShot()
{
  unsigned char b1;
  unsigned short int w1;
  int i,n; //zero 5.7.99
  char fnamestr[13];
  static int ss=0;
  FILE *pcxf;

//--- zero 5.7.99
  n=0;
  do
  {
    sprintf(fnamestr,"%d.pcx",n);
    pcxf=fopen(fnamestr,"r");
    i=(int)pcxf;
    if(pcxf) fclose(pcxf);
    n++;
  } while(i);
  n--;

  // Takes a snapshot of the current screen.

   sprintf(fnamestr,"%d.pcx",n);
//---

   pcxf=fopen(&fnamestr,"wb");
   ss++;

// Write PCX header

   b1=10; fwrite(&b1, 1, 1, pcxf); // manufacturer always = 10
   b1=5; fwrite(&b1, 1, 1, pcxf);  // version = 3.0, >16 colors
   b1=1; fwrite(&b1, 1, 1, pcxf);  // encoding always = 1
   b1=8; fwrite(&b1, 1, 1, pcxf);  // 8 bits per pixel, for 256 colors
   w1=0; fwrite(&w1, 1, 2, pcxf);  // xmin = 0;
   w1=0; fwrite(&w1, 1, 2, pcxf);  // ymin = 0;
 w1=sx-1; fwrite(&w1, 1, 2, pcxf);  // xmax = 319;
 w1=sy-1; fwrite(&w1, 1, 2, pcxf);  // ymax = 199;
 w1=sx; fwrite(&w1, 1, 2, pcxf);  // hres = 320;
 w1=sy; fwrite(&w1, 1, 2, pcxf);  // vres = 200;

 fwrite(screen,1,48,pcxf);

 b1=0; fwrite(&b1, 1, 1, pcxf);   // reserved always = 0.
 b1=1; fwrite(&b1, 1, 1, pcxf);   // number of color planes. Just 1 for 8bit.
 w1=sx; fwrite(&w1, 1, 2, pcxf); // number of bytes per line

 w1=0; fwrite(&w1, 1, 1, pcxf);
 fwrite(screen, 1, 59, pcxf);          // filler

 for (w1=0; w1<sy; w1++)
     WritePCXLine(screen+((w1+16)*tsx)+16, sx, pcxf);

 WritePalette(pcxf);
 fclose(pcxf);
 timer_count=0;
}
Esempio n. 2
0
void OutputVSPpcx()
{ int i,j,_x,_y;
  unsigned char *ptr;
  char b1;
  short int w1,w2;

  // First figure out the filename

  i=0;
  ptr=&vspname;
  while (*ptr != '.')
  {
    strbuf[i]=*ptr;
    ptr++;
    i++;
  }
  strbuf[i++]='.';
  strbuf[i++]='P';
  strbuf[i++]='C';
  strbuf[i++]='X';
  strbuf[i++]=0;

  pcxf=fopen(strbuf,"wb");

// Write PCX header

   b1=10; fwrite(&b1, 1, 1, pcxf); // manufacturer always = 10
   b1=5; fwrite(&b1, 1, 1, pcxf);  // version = 3.0, >16 colors
   b1=1; fwrite(&b1, 1, 1, pcxf);  // encoding always = 1
   b1=8; fwrite(&b1, 1, 1, pcxf);  // 8 bits per pixel, for 256 colors
   w1=0; fwrite(&w1, 1, 2, pcxf);  // xmin = 0;
   w1=0; fwrite(&w1, 1, 2, pcxf);  // ymin = 0;
 w1=319; fwrite(&w1, 1, 2, pcxf);  // xmax = 319;

 // At this point we need to figure out how many vertical rows tall the
 // PCX needs to be in order to accomidate the number of tiles in the VSP.

 w2=numtiles/18; w2++;
 w2=(w2*17); fwrite(&w2, 1, 2, pcxf);  // ymax = ?;
 w1=320; fwrite(&w1, 1, 2, pcxf);      // hres = 320;
 w2++; fwrite(&w2, 1, 2, pcxf);        // vres = ?;

 fwrite(screen, 1, 48, pcxf);  // 16-color palette data. Who knows what's
                               // actually in here. It doesn't matter since
                               // the 256-color palette is stored elsewhere.

 b1=0; fwrite(&b1, 1, 1, pcxf);   // reserved always = 0.
 b1=1; fwrite(&b1, 1, 1, pcxf);   // number of color planes. Just 1 for 8bit.
 w1=320; fwrite(&w1, 1, 2, pcxf); // number of bytes per line

 w1=0; fwrite(&w1, 1, 1, pcxf);
 fwrite(screen, 1, 59, pcxf);          // filler

 // The header is written. Now we need to generate a large buffer where we'll
 // "draw" the PCX, and then encode the data and save the PCX.

 ptr=(char *) malloc(320*w2);
 memset(ptr,255,(320*w2));            // Give the PCX a white background

 // Now we "draw" the tiles into the buffer.

 for (i=0; i<numtiles; i++)
 {
    j=i/18;
    _y=1+(j*17);
    j=i-(j*18);
    _x=1+(j*17);
    acopytile(_x,_y,vsp+(i*256),ptr);
 }

 // And now we save the rest of the PCX.

 for (w1=0; w1<w2; w1++)
     WritePCXLine(ptr+(w1*320),320,pcxf);

  WritePalette(pcxf);
  fclose(pcxf);

  vfree(ptr);
}
Esempio n. 3
0
//******************* 保存为PCX (由CDib对象) ***********************
BOOL LanImage::SavePcx(LPCTSTR lpstrFileName, CDib* pDib)
{
    int i = 0;
	if (pDib == NULL)
		return FALSE;

	HDIB hDib = CopyHandle(pDib->GetHandle());
	if (hDib == NULL)
		return FALSE;

	CDib* pDibTmp = new CDib();
	pDibTmp->Attach(hDib);

	UINT uWidth  = pDibTmp->GetWidth();
	UINT uHeight = pDibTmp->GetHeight();

	// 当打开的图像BitCount不为8时,转为8位格式
	if (pDibTmp->GetBitCount() != 8)
		pDibTmp->ConvertFormat(8);

	// make PCX header
	PCXHEAD header;
	memset((LPBYTE)&header, 0, sizeof(PCXHEAD));
	header.manufacturer = 0x0A;
	header.version = 5;
	header.encoding = 1;
	header.bit_per_pixel = 8;
	//header.bit_per_pixel = 24;
	header.xmin = 0;
	header.ymin = 0;
	header.xmax = uWidth-1;
	header.ymax = uHeight-1;
	//header.Xresolution;
	//header.Yresolution;
	header.palette[0] = (BYTE)0x00;  // for correct process for mono
	header.palette[1] = (BYTE)0x00;
	header.palette[2] = (BYTE)0x00;
	header.palette[3] = (BYTE)0xff;
	header.palette[4] = (BYTE)0xff;
	header.palette[5] = (BYTE)0xff;
	//header.palette[48];
	header.reserved = 0;
	header.color_planes = 1;
	header.byte_per_line = uWidth;
	header.palette_type = 1;
	//filler[58];

	// construct PCX palette from DIB color table
	PCXPALETTE palette[256];
	PALETTEENTRY PaletteColors[256];
	pDibTmp->GetPalette()->GetPaletteEntries(0, 256, PaletteColors);
	for (i=0;i<256;i++) 
	{
		palette[i].rgbRed   = PaletteColors[i].peRed;
		palette[i].rgbGreen = PaletteColors[i].peGreen;
		palette[i].rgbBlue  = PaletteColors[i].peBlue;
	}

	// get bits ptr
	HDIB hDIB = CopyHandle(pDibTmp->GetHandle());
	delete pDibTmp;
	LPBYTE lpDIB = (LPBYTE)GlobalLock(hDIB);
	BYTE* lpBuffer = (BYTE *)FindDIBBits(lpDIB);
	WORD wWidthBytes = (WORD)BytesPerLine(lpDIB);

	/*** Open the PCX file ***/
	FILE *outFile;
	if ((outFile=fopen(lpstrFileName,"wb")) == NULL)
	{
		GlobalUnlock(hDIB);
		GlobalFree(hDIB);
		return FALSE;
	}

	/*** Write the header ***/
	fwrite((char *)&header, sizeof(PCXHEAD), 1, outFile);

	/*** Write image data ***/
	for ( i=(int)uHeight-1; i>=0; --i)
	{
		if (! WritePCXLine(header.byte_per_line, lpBuffer+i*wWidthBytes, outFile))
		{
			fclose(outFile);
			GlobalUnlock(hDIB);
			GlobalFree(hDIB);
			return FALSE;
		}
	}

	/*** Write the palette data ***/
	fputc(0x0c, outFile);
	fwrite((char *)palette, 1, sizeof(palette), outFile);

	// clear & close
	fclose(outFile);
	GlobalUnlock(hDIB);
	GlobalFree(hDIB);

	return TRUE;
}