Ejemplo n.º 1
0
status_t PNGTrans::AddData( const void* pData, size_t nLen, bool bFinal )
{
    if( !m_bWriteMode ) {
        //	dbprintf("PNG-Read: AddData()\n");
        if ( setjmp( m_psPNGStruct->jmpbuf ) ) {
            png_destroy_read_struct( &m_psPNGStruct, &m_psPNGInfo, (png_infopp)NULL );
            return -1;
        }

        png_process_data( m_psPNGStruct, m_psPNGInfo, (png_bytep)pData, nLen );
        return 0;
    } else {
        m_cInBuffer.Write( pData, nLen );
        //	dbprintf("PNG-Write: Data added!\n");
        if( m_eState == STATE_INIT && m_cInBuffer.Size() > (ssize_t)sizeof( BitmapHeader ) ) {
            m_cInBuffer.Read( &m_sBitmapHeader, sizeof( m_sBitmapHeader ) );
            m_eState = STATE_FRAMEHDR;
        }

        if( m_eState == STATE_FRAMEHDR && m_cInBuffer.Size() > (ssize_t)sizeof( BitmapFrameHeader ) ) {
            m_cInBuffer.Read( &m_sCurrentFrame, sizeof( m_sCurrentFrame ) );
            // TODO: Verify depth, convert if not RGB32
            png_set_IHDR( m_psPNGStruct, m_psPNGInfo,
                          m_sCurrentFrame.bf_frame.right - m_sCurrentFrame.bf_frame.left + 1,
                          m_sCurrentFrame.bf_frame.bottom - m_sCurrentFrame.bf_frame.top + 1,
                          8, PNG_COLOR_TYPE_RGB, //_ALPHA,
                          PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE );
            //	png_set_filler( m_psPNGStruct, 0xff, PNG_FILLER_AFTER);
            png_set_bgr( m_psPNGStruct );
            png_write_info( m_psPNGStruct, m_psPNGInfo );
            AllocRowBuffer( m_sCurrentFrame.bf_frame.right - m_sCurrentFrame.bf_frame.left + 1 );
            m_eState = STATE_READING;
        }

        while( m_eState == STATE_READING && m_cInBuffer.Size() ) {
            if( AppendToRowBuffer() ) {
                // Overflow = one row is ready
                //	dbprintf("PNG-Write: Found Row\n");
                png_write_rows( m_psPNGStruct, &m_pRowBuffer, 1);
            }
        }

        if( bFinal ) {
            png_write_end( m_psPNGStruct, m_psPNGInfo);
        }

        return 0;
    }
}
Ejemplo n.º 2
0
ssize_t GIFTrans::Read( void* pData, size_t nLen )
{
    if ( m_bEOF == false ) {
	return( ERR_SUSPENDED );
    }
    DecodeData();
    int nBytesRead = 0;
    if ( m_bTopHeaderValid == false ) {
	return( 0 );
    }
    if (  m_bTopHeaderRead == false ) {
	if ( nLen < sizeof( BitmapHeader ) ) {
	    errno = EINVAL;
	    return( -1 );
	}
	memcpy( pData, &m_sBitmapHeader, sizeof(m_sBitmapHeader) );
	pData = ((char*)pData) + sizeof(m_sBitmapHeader);
	nLen       -= sizeof(m_sBitmapHeader);
	nBytesRead += sizeof(m_sBitmapHeader);
	m_bTopHeaderRead = true;
    }

    int nCurLen = m_cOutBuffer.Read( pData, nLen );
    nBytesRead += nCurLen;
    return( nBytesRead );
}
Ejemplo n.º 3
0
ssize_t PNGTrans::Read( void* pData, size_t nLen )
{
    ssize_t nCurLen = m_cOutBuffer.Read( pData, nLen );
    if ( nCurLen == 0 /*&& m_bDone == false*/ ) {
        return( ERR_SUSPENDED );
    }
    return( nCurLen );
}
Ejemplo n.º 4
0
bool ParsePacket(ClientSession* client_session_, CircularBuffer& recv_buffer )
{
	while ( true )
	{
		char packet_data[MAX_PKT_SIZE];
		/// 패킷 헤더 크기 만큼 읽어와보기
		PacketHeader packet_header = PacketHeader();
		if ( false == recv_buffer.Peek((char*)&packet_header, sizeof(packet_header) ) )
			return true ;


		/// 패킷 완성이 되는가? 
		if ( recv_buffer.GetStoredSize() < (packet_header.size_) )
			return true ;
		recv_buffer.Read((char*)&packet_header, sizeof(packet_header));
		recv_buffer.Read(packet_data, packet_header.size_);

		/// 패킷 핸들링
		switch ( packet_header.type_ )
		{
		case PKT_CS_LOGIN:
			{
				LoginRequest in_packet;
				in_packet.ParseFromArray(packet_data, packet_header.size_);
				LoginRequestHandler(client_session_, in_packet);
			}
			break ;
		case PKT_CS_MOVE_KEY_CHANGE:
			{
				MoveKeyPressRequest in_packet;
				in_packet.ParseFromArray(packet_data, packet_header.size_);
				MoveKeyChangeHandler(client_session_, in_packet);
			}
			break;
		default:
			{
				/// 여기 들어오면 이상한 패킷 보낸거다.
				return false ;
			}
			break ;
		}
	}
	return true;
}
Ejemplo n.º 5
0
bool PNGTrans::AppendToRowBuffer( void )
{
    uint8	buffer[1024];

    // Free space in rowbuffer
    uint32	nSize = m_nRowSize - m_nRowPos;
    // Adjust to available amount of data (so we don't get a deadlock)
    nSize = nSize > (uint32)m_cInBuffer.Size() ? m_cInBuffer.Size() : nSize;
    // Longword alignment, 24 bpp => 32 bpp size conversion
    nSize = ((int)( nSize / 3 )) * 4;
    // Adjust to available buffer size
    nSize = nSize > sizeof( buffer ) ? sizeof(buffer) : nSize;

//	dbprintf("pos: %ld, size: %ld\n", m_nRowPos, m_nRowSize);


    // Read and convert RGB32 => RGB24
//	dbprintf("m_cInBuffer.Read( %p, %ld )...", buffer, nSize);
    m_cInBuffer.Read( buffer, nSize );
//	dbprintf("Done!\n");
    int i, j;
    for( i = 0, j = 0; i < nSize; i+=4, j+=3 ) {
        m_pRowBuffer[ m_nRowPos + j     ] = buffer[ i     ];
        m_pRowBuffer[ m_nRowPos + j + 1 ] = buffer[ i + 1 ];
        m_pRowBuffer[ m_nRowPos + j + 2 ] = buffer[ i + 2 ];
    }

    m_nRowPos += (nSize/4)*3;
    if( m_nRowPos >= m_nRowSize ) {
//		dbprintf("New row\n");
        m_nRowPos = 0;
        return true;
    } else {
        return false;
    }
}
Ejemplo n.º 6
0
int GIFTrans::GetInput( void* pData, int nLen )
{
    return( m_cInBuffer.Read( pData, nLen ) );
}