예제 #1
0
	void Texture::SaveTexture( const OutPutTextureData& saveto )
	{
		unsigned long i;
		png_structp png_ptr;
		png_infop info_ptr;
		png_colorp palette;
		png_byte *image;
		png_bytep *row_pointers;

		IFile* writefile = IOSystem::Instance().FileFactory(saveto.m_Path);
		writefile->OpenFile( IFile::AT_READ );


		png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
		info_ptr = png_create_info_struct(png_ptr);
		png_set_write_fn( png_ptr, writefile, png_rw, png_flush );
		//png_init_io(png_ptr, writefile.BaseFile() );

		int colortype, bitesize;
		switch( saveto.m_Pixel )
		{
		case Device::PF_R8G8B8: colortype = PNG_COLOR_TYPE_RGB; bitesize = 3; break;
		case Device::PF_R8G8B8A8: colortype = PNG_COLOR_TYPE_RGBA; bitesize = 4; break;
		}
		png_set_IHDR(png_ptr, info_ptr, saveto.m_Size.m_x, saveto.m_Size.m_y, 8, colortype,
			PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
		palette = (png_colorp)png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH * sizeof (png_color));
		png_set_PLTE(png_ptr, info_ptr, palette, PNG_MAX_PALETTE_LENGTH);
		png_write_info(png_ptr, info_ptr);
		png_set_packing(png_ptr);
		row_pointers = (png_bytep *)malloc(saveto.m_Size.m_y * sizeof(png_bytep));

		for (i = 0; i < saveto.m_Size.m_y; i++)
		{
			row_pointers[i] = (png_bytep)&saveto.m_Data[i * saveto.m_Size.m_y * bitesize];
		}
		png_write_image(png_ptr, row_pointers);
		png_write_end(png_ptr, info_ptr);
		png_free(png_ptr, palette);
		palette = NULL;
		png_destroy_write_struct(&png_ptr, &info_ptr);
		free(row_pointers);
		row_pointers = NULL;
		writefile->CloseFile( );
		IOSystem::Instance().FileDestroy( writefile );
	}
예제 #2
0
	//---------------------------------------------------------------------------------------------------------
	void Checking::OnRequestResourceList( BohgeEngine::IBaseHandle* h )
	{
		if ( IWebProperty::HS_OK != h->GetStatusCode() )
		{
			DEBUGLOG("Can not connect server!\r\n");
		}
		else
		{
			ResourceList Reslist;
			ASSERT( IWebProperty::JS_FINISH == h->GetState() );
			JsonReader webreader;
			webreader.Parse( static_cast<IPostHandle*>(h)->GetResult() );
			JsonEntryInfo webinfo;
			webreader.Read( webinfo );
			m_LocalPath = string( DefaultResource::RESOURCE_PATH ) + webinfo.m_Bundle + PLANTFORMDELIMITER;
			string infopath = m_LocalPath + DefaultResource::LITE_INFO_FILE;
			if ( webinfo.m_isValid )
			{
				IFile* file = IIOSystem::Instance()->FileFactory( infopath );
				file->OpenFile( IFile::AT_READ );
				if ( !file->isOpen() )//如果没打卡,则从新下载相应资源
				{
					_AllResource( Reslist, webinfo );
				}
				else//如果打开了则对比一下
				{
					eastl::string locallif;
					locallif.resize( file->GetSize() );
					file->ReadFile( &locallif[0], file->GetSize() );
					file->CloseFile();
					IIOSystem::Instance()->RecycleBin( file );
					JsonReader loacalreader;
					if( loacalreader.Parse( locallif ) )//可能本地json被损坏导致无法读取
					{
						loacalreader.Read( m_LocalResourceList );
						_CompareResource( Reslist, webinfo );
					}
					else
					{
						DEBUGLOG("Resource list is invaild");
						_AllResource( Reslist, webinfo );
					}
				}
			}
			else
			{
				ASSERT( false && "Application's version is not valiable!\n" );
			}
			if ( !Reslist.empty() )
			{
				DEBUGLOG("Need download resource\n");
				m_pJsonWriter->Open( DefaultResource::APP_VERSION_INT, infopath );
				_DownloadResources( Reslist );
			}
			else
			{
				m_pMutex->Lock();
				m_isFinish = true;
				m_ReleaseList.push_back( h );
				m_pMutex->Unlock();
			}
		}
	}