y_bitmap -
Crayder - 17.05.2015
y_bitmap
Introduction
This is a sneak-peak at something I've been working on today, but I'm going away for the weekend so I thought I would put it out there for people to at least look at.This script, quite simply, draws bitmaps and saves them.Currently there are only 4 functions, but I intend to add more for things like drawing boxes and circles etc.It does, however, support alpha blending so drawing a pixel "0xFF000080" over another pixel will be slightly transparent to the colour underneath.
As I say, this is a VERY early beta so currently it does every pixel entirely individually and has no optimisations for doing large blocks faster than otherwise possible.
Use
Given the lack of functions, this is really quite simple at this point:
Code:
Код:
main()
{
// Create the bitmap we are going to write to (default all white).
new Bitmap:ctx = Bitmap_Create(64, 64);
// Draw a solid red pixel at (10, 10).
Bitmap_WritePixel(ctx, 10, 10, Y_RED | 0xFF);
// Draw a nearly transparent green pixel at (10, 11).
Bitmap_WritePixel(ctx, 10, 11, Y_GREEN | 0x20);
// Save the image to a file.
Bitmap_Write(ctx, "y_bitmap_Example.bmp");
// Destroy the bitmap object to save memory.
Bitmap_Destroy(ctx);
}
Note that the orientation of the image is (0,0) is the top-left corner, so that example will draw the green pixel under the red pixel.
Examples
Because there are only pixel functions so far (though I have some code for blocks and basic text), these example just play about with blending alpha channels:
Generate an image fading from white to red over the whole image.
Code:
Код:
y_bitmap_Fade1()
{
new Bitmap:ctx = Bitmap_Create(256, 256);
for (new y = 0; y != 256; ++y) for (new x = 0; x != 256; ++x)
Bitmap_WritePixel(ctx, x, y, Y_RED | (x * y / 256));
Bitmap_Write(ctx, "y_bitmap_Fade1.bmp");
Bitmap_Destroy(ctx);
}
Generate an image fading from white to red vertically, and white to green horizontally.
Code:
Код:
y_bitmap_Fade2()
{
new Bitmap:ctx = Bitmap_Create(256, 256);
for (new y = 0; y != 256; ++y) for (new x = 0; x != 256; ++x)
{
Bitmap_WritePixel(ctx, x, y, Y_RED | y);
Bitmap_WritePixel(ctx, x, y, Y_GREEN | x);
}
Bitmap_Write(ctx, "y_bitmap_Fade2.bmp");
Bitmap_Destroy(ctx);
}
I should note that I converted these images to .png myself for display here.The script can ONLY generate .bmp files!
Colours
This include uses y_colours with some new names.By default the X11 colours (X11_RED) etc have an alpha already set at 0xAA.This is fine for use in-game but not here, so instead there are "Y" versions of all the colours which are exactly the same but with NO alpha.Doing this:
Code:
Код:
Bitmap_WritePixel(ctx, x, y, Y_ALICE_BLUE);
Will not do anything because that is an invisible blue.
Download
This is part of YSI:
https://sampforum.blast.hk/showthread.php?tid=570884
Credits
I am reposting this include (made by ******) with the thought of what he said to several members of the community. Everything that could help someone should not be deleted from the forums, which is something I agree with since I learned a lot by reading the tutorials on here. He made a lot of things that are used by lots of servers and that knowledge should not be lost for present and future developers.
Note
I found this include to be very useful. Many may think it's useless,
but it has it's uses.
Re: y_bitmap -
PT - 17.05.2015
Thanks Crayder to bring this back.