Jump to content

TGA Reader


XaskeL

Recommended Posts

Does anyone have any idea how to make a pixel definition in a binary file to change it? That is, calculate its position in the file and then change the color using the function. I am writing a mini-game Pixel Battle to put in open access. And, for the script to work better, I will work with the image on the server and client side, transmit data about the changed pixels (which should positively affect the optimization and the network part). I am currently trying to read files without RLE compression from the server side.
 

function CImageTGA:GetPixel(x,y)
	local Depth = self:GetDepth()
	local GetImageSize = self:GetImageSize();
	local headerSize = self:SkipFirstBlock();
	x = x <= GetImageSize.x and x or GetImageSize.x;
	y = y <= GetImageSize.y and y or GetImageSize.y; 
	-- RGBA (1, 1, 1, 1)
	self.file:setPos(headerSize);
	-- COLOR
	local BytesPerPixel = Depth / 8;
	local BlockInfo = self.reader:ReadUInt8();
	local RLE = bitAnd(BlockInfo, 128);
	local CountPixels = bitAnd(BlockInfo, 127) -- Read RAW First Byte
	self.file:setPos(headerSize + 1);
	-- GET ALL PIXELS. TEST
	local color = {}
	local h1, h2, h3 = debug.gethook()
	debug.sethook()
	for i = 0, (BytesPerPixel * GetImageSize.x * GetImageSize.y), BytesPerPixel do
		table.insert( color, self.reader:ReadUInt8() )
		self.file:setPos(headerSize + i);
	end
	debug.sethook (_, h1, h2, h3)
	return color;
end

 

Link to comment
  • Moderators

@XaskeL

 

29 minutes ago, XaskeL said:

Does anyone have any idea how to make a pixel definition in a binary file to change it?

Unfortunately I can't answer this question.

 

But one thing I noticed is you are making it too complex and putting stress on your MTA application.

If you want to read and write pixels, why not let a secondary application take care of that? You are just blocking your MTA thread after all.

https://www.npmjs.com/package/@rgba-image/pixel

https://www.npmjs.com/package/get-pixels

(Also you might find an answer to your question in the source code of those two node applications)

 

Do with it what you want, best of luck!

Edited by IIYAMA
Link to comment
1 minute ago, IIYAMA said:

@XaskeL

 

Unfortunately I can't answer this question.

 

But one thing I noticed is you are making it too complex and putting stress on your MTA application.

If you want to read and write pixels, why not let a secondary application take care of that? You are just blocking your MTA thread after all.

https://www.npmjs.com/package/@rgba-image/pixel

https://www.npmjs.com/package/get-pixels

 

Do with it what you want, best of luck!

No, I just tried to read the whole file, the colors of the pixels (judging by the result.log, it seems to be successful). But I don’t know yet how the pixel positions inside the binary file go. Thanks for the links.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...