<commit_before>#include "Texture2D.h"

namespace star
{
	//[NOTE]	You're not supposed to make Textures yourself.
	//			Use the TextureManager to load your textures.
	//			This ensures a same texture is not loaded multiple times
#ifdef DESKTOP
	Texture2D::Texture2D(const tstring & pPath):
			mPath(pPath),
			mTextureId(0),
			mFormat(0),
			mWidth(0),
			mHeight(0)
	{
		this->Load();
	}
#else
	Texture2D::Texture2D(const tstring & pPath, android_app* pApplication):
			mResource(pApplication , pPath),
			mPath(pPath),
			mTextureId(0),
			mFormat(0),
			mWidth(0),
			mHeight(0)
	{
		this->Load();
	}

	void Texture2D::CallbackRead(png_structp png, png_bytep data, png_size_t size)
	{
		Resource& lReader = *((Resource*)png_get_io_ptr(png));
		if(!lReader.Read(data,size))
		{
			lReader.Close();
			png_error(png, "Error while reading PNG file");
		}
	}
#endif

	Texture2D::~Texture2D()
	{
		if(mTextureId != 0)
		{
			glDeleteTextures(1, &mTextureId);
			mTextureId = 0;
		}
		mWidth = 0;
		mHeight = 0;
		mFormat = 0;
	}
	
	uint8* Texture2D::ReadPNG()
	{
		png_byte header[8];
		png_structp lPngPtr = NULL;
		png_infop lInfoPtr = NULL;
		png_byte* lImageBuffer = NULL;
		png_bytep* lRowPtrs = NULL;
		png_int_32 lRowSize;
		bool lTransparency;

#ifdef DESKTOP
		FILE *fp;
		tfopen(&fp, mPath.c_str(), _T("rb"));

		if(fp == NULL)
		{ 
			Logger::GetInstance()->Log(LogLevel::Error,
				_T("PNG : png could not be loaded"), STARENGINE_LOG_TAG);
			return NULL;
		}

		fread(header, 8, 1, fp);
#else
		if(!mResource.Open())
		{
			mResource.Close();
			Logger::GetInstance()->Log(LogLevel::Error,
				_T("PNG : Could Not Open Resource"), STARENGINE_LOG_TAG);
			return NULL;
		}
		if(!mResource.Read(header, sizeof(header)))
		{
			mResource.Close();
			Logger::GetInstance()->Log(LogLevel::Error,
				_T("PNG : Could Not Read"),
				STARENGINE_LOG_TAG, STARENGINE_LOG_TAG);
			return NULL;
		}
#endif

		if(png_sig_cmp(header, 0, 8))
		{<commit_msg> HotFix Android.<commit_after>#include "Texture2D.h"

namespace star
{
	//[NOTE]	You're not supposed to make Textures yourself.
	//			Use the TextureManager to load your textures.
	//			This ensures a same texture is not loaded multiple times
#ifdef DESKTOP
	Texture2D::Texture2D(const tstring & pPath):
			mPath(pPath),
			mTextureId(0),
			mFormat(0),
			mWidth(0),
			mHeight(0)
	{
		this->Load();
	}
#else
	Texture2D::Texture2D(const tstring & pPath, android_app* pApplication):
			mResource(pApplication , pPath),
			mPath(pPath),
			mTextureId(0),
			mFormat(0),
			mWidth(0),
			mHeight(0)
	{
		this->Load();
	}

	void Texture2D::CallbackRead(png_structp png, png_bytep data, png_size_t size)
	{
		Resource& lReader = *((Resource*)png_get_io_ptr(png));
		if(!lReader.Read(data,size))
		{
			lReader.Close();
			png_error(png, "Error while reading PNG file");
		}
	}
#endif

	Texture2D::~Texture2D()
	{
		if(mTextureId != 0)
		{
			glDeleteTextures(1, &mTextureId);
			mTextureId = 0;
		}
		mWidth = 0;
		mHeight = 0;
		mFormat = 0;
	}
	
	uint8* Texture2D::ReadPNG()
	{
		png_byte header[8];
		png_structp lPngPtr = NULL;
		png_infop lInfoPtr = NULL;
		png_byte* lImageBuffer = NULL;
		png_bytep* lRowPtrs = NULL;
		png_int_32 lRowSize;
		bool lTransparency;

#ifdef DESKTOP
		FILE *fp;
		tfopen(&fp, mPath.c_str(), _T("rb"));

		if(fp == NULL)
		{ 
			Logger::GetInstance()->Log(LogLevel::Error,
				_T("PNG : png could not be loaded"), STARENGINE_LOG_TAG);
			return NULL;
		}

		fread(header, 8, 1, fp);
#else
		if(!mResource.Open())
		{
			mResource.Close();
			Logger::GetInstance()->Log(LogLevel::Error,
				_T("PNG : Could Not Open Resource"), STARENGINE_LOG_TAG);
			return NULL;
		}
		if(!mResource.Read(header, sizeof(header)))
		{
			mResource.Close();
			Logger::GetInstance()->Log(LogLevel::Error,
				_T("PNG : Could Not Read"),
				STARENGINE_LOG_TAG);
			return NULL;
		}
#endif

		if(png_sig_cmp(header, 0, 8))
		{
{'fraction_non_alphanumeric': 0.1485479311231046, 'fraction_numerical': 0.01593420714469288, 'mean_word_length': 3.8589263420724094, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1865466', 'n_tokens_mistral': 1768, 'n_tokens_neox': 1531, 'n_words': 315}