Exemplo n.º 1
0
int
freadscan(			/* read in a scanline */
	COLOR  *scanline,
	int  len,
	FILE  *fp
)
{
	COLR  *clrscan;

	if ((clrscan = (COLR *)tempbuffer(len*sizeof(COLR))) == NULL)
		return(-1);
	if (freadcolrs(clrscan, len, fp) < 0)
		return(-1);
					/* convert scanline */
	colr_color(scanline[0], clrscan[0]);
	while (--len > 0) {
		scanline++; clrscan++;
		if (clrscan[0][GRN] == clrscan[-1][GRN] &&
			    (clrscan[0][RED] == clrscan[-1][RED]) &
			    (clrscan[0][BLU] == clrscan[-1][BLU]) &
			    (clrscan[0][EXP] == clrscan[-1][EXP]))
			copycolor(scanline[0], scanline[-1]);
		else
			colr_color(scanline[0], clrscan[0]);
	}
	return(0);
}
Exemplo n.º 2
0
int
fwritescan(			/* write out a scanline */
	COLOR  *scanline,
	int  len,
	FILE  *fp
)
{
	COLR  *clrscan;
	int  n;
	COLR  *sp;
					/* get scanline buffer */
	if ((sp = (COLR *)tempbuffer(len*sizeof(COLR))) == NULL)
		return(-1);
	clrscan = sp;
					/* convert scanline */
	n = len;
	while (n-- > 0) {
		setcolr(sp[0], scanline[0][RED],
				  scanline[0][GRN],
				  scanline[0][BLU]);
		scanline++;
		sp++;
	}
	return(fwritecolrs(clrscan, len, fp));
}
Exemplo n.º 3
0
void NetSocket::ReceiveData( void )
{
	char pTempBuffer[RECV_BUFFER_SIZE];
	memset( pTempBuffer, 0, sizeof( RECV_BUFFER_SIZE ) );
//	int iCurrentReceLen = 0;
	int result_select = TestingNet( 0, 1000, 1 );// 0
	switch( result_select )
	{
	case 0:
		//cocos2d::CCLog("receive select out time");
		break;
	case 1:
		{
			//if( FD_ISSET(m_iDescriptor, &fds ) )
			{
				int iCurrentReceLen = recv(m_iDescriptor, pTempBuffer, RECV_BUFFER_SIZE, 0 );
				if( iCurrentReceLen > 0 )
				{
					string tempbuffer(pTempBuffer, iCurrentReceLen );
					m_strReceHeap.clear();
					m_strReceHeap.append( tempbuffer );

					cocos2d::CCLog("receive data ok");
				}
				else if( iCurrentReceLen <= 0 )
				{
					if( errno != EINTR )
					{
						m_bIsConnected = false;
						this->CloseSocket();
						ResetData();

						cocos2d::CCLog("receive connect cut");
					}
				}
			}
		}
		break;
	case NET_SOCKET_ERROR:
		{
			m_bIsConnected = false;
			this->CloseSocket();
			ResetData();

			cocos2d::CCLog("receive select error");
		}
		break;
	}

	if( m_strReceHeap.empty() )
		return;
		
	if( m_bRevePageageHead == false )
	{
		string strHead;
		strHead.assign( m_strReceHeap, 0, 4 );
		m_strReceHeap.erase( 0,4 );
		
		swap_4( strHead );
		int iHeadLen = *((int*)(strHead.c_str()));
		m_u32RecePageageLen = iHeadLen;

		m_bRevePageageHead = true;
	}
	if( m_bRevePageageHead == true && m_iReceivedLen < (int)m_u32RecePageageLen )
	{
		int iLeavingLen = m_u32RecePageageLen - m_iReceivedLen;
		if( (int)m_strReceHeap.length() >= iLeavingLen )
		{
			m_strReceivePackage.append( m_strReceHeap, 0, iLeavingLen );
			m_strReceHeap.erase( 0, iLeavingLen );
			m_iReceivedLen += iLeavingLen;
		}
		else
		{
			m_strReceivePackage.append( m_strReceHeap, 0, m_strReceHeap.length() );
			m_strReceHeap.clear();
			m_iReceivedLen += m_strReceHeap.length();
		}
	}

	if( m_iReceivedLen == m_u32RecePageageLen )
	{
		Recv_struct stRec;
		stRec.ieffectiveLength = m_u32RecePageageLen;
		memset(stRec.data, 0, RECV_BUFFER_SIZE );
		memcpy(stRec.data, m_strReceivePackage.c_str(), m_u32RecePageageLen );
		m_qReceiveData->push( stRec );
		ResetReveData();

		CCLog("received page finish!");
	}
}
Exemplo n.º 4
0
static bool render_font_save_cached(render_font &font, const char *filename, UINT32 hash)
{
	// attempt to open the file
	core_file *file;
	file_error filerr = core_fopen(filename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file);
	if (filerr != FILERR_NONE)
		return true;

	try
	{
		// determine the number of characters
		int numchars = 0;
		for (int chnum = 0; chnum < 65536; chnum++)
			if (font.chars[chnum].width > 0)
				numchars++;

		// write the header
		dynamic_buffer tempbuffer(65536);
		UINT8 *dest = &tempbuffer[0];
		*dest++ = 'f';
		*dest++ = 'o';
		*dest++ = 'n';
		*dest++ = 't';
		*dest++ = hash >> 24;
		*dest++ = hash >> 16;
		*dest++ = hash >> 8;
		*dest++ = hash & 0xff;
		*dest++ = font.height >> 8;
		*dest++ = font.height & 0xff;
		*dest++ = font.yoffs >> 8;
		*dest++ = font.yoffs & 0xff;
		*dest++ = numchars >> 24;
		*dest++ = numchars >> 16;
		*dest++ = numchars >> 8;
		*dest++ = numchars & 0xff;
		write_data(*file, tempbuffer, dest);

		// write the empty table to the beginning of the file
		dynamic_buffer chartable(numchars * CACHED_CHAR_SIZE + 1, 0);
		write_data(*file, &chartable[0], &chartable[numchars * CACHED_CHAR_SIZE]);

		// loop over all characters
		int tableindex = 0;
		for (int chnum = 0; chnum < 65536; chnum++)
		{
			render_font_char &ch = font.chars[chnum];
			if (ch.width > 0)
			{
				// write out a bit-compressed bitmap if we have one
				if (ch.bitmap != NULL)
				{
					// write the data to the tempbuffer
					dest = tempbuffer;
					UINT8 accum = 0;
					UINT8 accbit = 7;

					// bit-encode the character data
					for (int y = 0; y < ch.bmheight; y++)
					{
						int desty = y + font.height + font.yoffs - ch.yoffs - ch.bmheight;
						const UINT32 *src = (desty >= 0 && desty < font.height) ? &ch.bitmap->pix32(desty) : NULL;
						for (int x = 0; x < ch.bmwidth; x++)
						{
							if (src != NULL && src[x] != 0)
								accum |= 1 << accbit;
							if (accbit-- == 0)
							{
								*dest++ = accum;
								accum = 0;
								accbit = 7;
							}
						}
					}

					// flush any extra
					if (accbit != 7)
						*dest++ = accum;

					// write the data
					write_data(*file, tempbuffer, dest);

					// free the bitmap and texture
					global_free(ch.bitmap);
					ch.bitmap = NULL;
				}

				// compute the table entry
				dest = &chartable[tableindex++ * CACHED_CHAR_SIZE];
				*dest++ = chnum >> 8;
				*dest++ = chnum & 0xff;
				*dest++ = ch.width >> 8;
				*dest++ = ch.width & 0xff;
				*dest++ = ch.xoffs >> 8;
				*dest++ = ch.xoffs & 0xff;
				*dest++ = ch.yoffs >> 8;
				*dest++ = ch.yoffs & 0xff;
				*dest++ = ch.bmwidth >> 8;
				*dest++ = ch.bmwidth & 0xff;
				*dest++ = ch.bmheight >> 8;
				*dest++ = ch.bmheight & 0xff;
			}
		}

		// seek back to the beginning and rewrite the table
		core_fseek(file, CACHED_HEADER_SIZE, SEEK_SET);
		write_data(*file, &chartable[0], &chartable[numchars * CACHED_CHAR_SIZE]);

		// all done
		core_fclose(file);
		return false;
	}
	catch (...)
	{
		core_fclose(file);
		osd_rmfile(filename);
		return true;
	}
}
Exemplo n.º 5
0
static int
transfer(			/* transfer a Radiance picture */
	char	*ospec
)
{
	char	oname[PATH_MAX];
	FILE	*fp;
	int	order;
	int	xmax, ymax;
	COLR	*scanin;
	int	y;
					/* get header info. */
	if (!(y = loadheader(stdin)))
		return(0);
	if (y < 0 || (order = fgetresolu(&xmax, &ymax, stdin)) < 0) {
		fprintf(stderr, "%s: bad input format\n", progname);
		exit(1);
	}
					/* did we pass the target frame? */
	if (findframe && findframe < frameno)
		return(0);
					/* allocate scanline */
	scanin = (COLR *)tempbuffer(xmax*sizeof(COLR));
	if (scanin == NULL) {
		perror(progname);
		exit(1);
	}
					/* skip frame? */
	if (findframe > frameno) {
		for (y = ymax; y--; )
			if (freadcolrs(scanin, xmax, stdin) < 0) {
				fprintf(stderr,
					"%s: error reading input picture\n",
						progname);
				exit(1);
			}
		return(1);
	}
					/* open output file/command */
	if (ospec == NULL) {
		strcpy(oname, "<stdout>");
		fp = stdout;
	} else {
		sprintf(oname, ospec, frameno);
		if (oname[0] == '!') {
			if ((fp = popen(oname+1, "w")) == NULL) {
				fprintf(stderr, "%s: cannot start \"%s\"\n",
						progname, oname);
				exit(1);
			}
		} else {
			if (!force && access(oname, 0) >= 0) {
				fprintf(stderr,
					"%s: output file \"%s\" exists\n",
						progname, oname);
				exit(1);
			}
			if ((fp = fopen(oname, "w")) == NULL) {
				fprintf(stderr, "%s: ", progname);
				perror(oname);
				exit(1);
			}
		}
	}
	SET_FILE_BINARY(fp);
	dumpheader(fp);			/* put out header */
	fputs(progname, fp);
	if (bradj)
		fprintf(fp, " -e %+d", bradj);
	if (!doflat)
		fputs(" -r", fp);
	fputc('\n', fp);
	if (bradj)
		fputexpos(pow(2.0, (double)bradj), fp);
	fputc('\n', fp);
	fputresolu(order, xmax, ymax, fp);
					/* transfer picture */
	for (y = ymax; y--; ) {
		if (freadcolrs(scanin, xmax, stdin) < 0) {
			fprintf(stderr, "%s: error reading input picture\n",
					progname);
			exit(1);
		}
		if (bradj)
			shiftcolrs(scanin, xmax, bradj);
		if (doflat)
			putbinary((char *)scanin, sizeof(COLR), xmax, fp);
		else
			fwritecolrs(scanin, xmax, fp);
		if (ferror(fp)) {
			fprintf(stderr, "%s: error writing output to \"%s\"\n",
					progname, oname);
			exit(1);
		}
	}
					/* clean up */
	if (oname[0] == '!')
		pclose(fp);
	else if (ospec != NULL)
		fclose(fp);
	return(1);
}