Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bmp to extra formats and as option for zip file. #1146

Open
Jolexer opened this issue Dec 7, 2024 · 0 comments
Open

Add bmp to extra formats and as option for zip file. #1146

Jolexer opened this issue Dec 7, 2024 · 0 comments

Comments

@Jolexer
Copy link

Jolexer commented Dec 7, 2024

Add bmp to extra formats and as option for zip file.
most game engines and libraries all support bmp and it is more performant.

you could reuse most code from the C style export.
according to wikipedia, using the OS/2 1.x BITMAPCOREHEADER format,
you could use the following c-pseudocode:

typedef struct {
	// header
	uint16 Signature,
	uint32 Filesize,
	uint32 Reserved,
	uint32 DataOffset,

	// spec says i should make this two structs, but i'm lazy
	// we use OS/2 BITMAPCOREHEADER because otherwise no transparent

	// OS/2 BITMAPCOREHEADER (not 2)
	uint32 BitmapheaderSize,
	int32 Width,
	int32 Height,
	uint32 Planes,
	// we could do palletised, but i'm lazy (plus the code is already there)
	uint16 BitCount,
	uint32 Compression,
	uint32 ImageSize,
	// these specify the DPI but in a metric kind of way
	int32 XpixelsPerM,
	int32 YpixelsPerM,
	uint32 ColorsUsed,
	uint32 ColorsImportant
} header_t;

// i don't know if users can specify their DPI, but pass it through anyway
int makeBMP(int32 Width, int32 Height, int32 pixelsPerM, char* imagedata, int outfile) {
	#define fullheadersize
	#define datasize (Width * Height * 4)

	header_t header;

	header.Signature = 'BM'; // spec says so
	header.Filesize = datasize + fullheadersize;
	header.Reserved = 0;
	header.dataOffset = fullheadersize + 1;
	header.BitmapheaderSize = 16; // spec says so
	header.Width = Width;
	header.Height = Height;
	header.Planes = 1; // spec says so
	header.BitCount = 32; // no palet, transparent
	header.Compression = 0; // no compression
	header.ImageSize = datasize; // could set this to 0, but we're kind
	header.XpixelsPerM = pixelsPerM;
	header.YpixelsPerM = pixelsPerM;
	header.ColorsUsed = 0; // default
	header.ColorsUsed = 0; // default

	write(header, fullheadersize, outfile);
	/////////////////////////////////////////////////////////////////
	// WARNING:                                                    //
	// i am assuming that the ABRG that piskel uses is compatible. //
	// you may need to do some byte swapping.                      //
	/////////////////////////////////////////////////////////////////
	write(imagedata, datasize, outfile);

	return 0;
}

Please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant