Module: ReadBMP 1.1, by SSH
Allows to read an uncompressed 24-bit BMP from disk into an array, allows flood fill, etc.
Download ReadBMP as a zip file
Author
Andrew MacCormack (SSH)
Please use the PM function on the AGS forums to contact
me about problems with this module
Abstract
Read BMP files into a datatype to allow manipulation, e.g. fill
Dependencies
AGS 2.71 or later
Functions
Static:
BMP.FromRGB(int r, int g, int b);
Convert RGB value into a single integer
BMP.Red(int data);
Extract Red value from single integer RGB
BMP.Green(int data);
Extract Green value from single integer RGB
BMP.Blue(int data);
Extract Blue value from single integer RGB
Instance:
BMP.Load(String filename);
Load the datatype up with the BMP file
BMP.GetPixel(int x, int y);
Return value of pixel at x,y (-1 if invalid)
BMP.SetPixel(int x, int y, int data);
Set value of pixel at x,y
BMP.SetPixelRGB(int x, int y, int r, int g, int b);
Set value of pixel at x,y with RGB values
BMP.LoadFromDS(DynamicSprite *ds);
Load datatype from a Dynamic Sprite (uses temp file)
BMP.Render(int x, int y);
Draw the datatype out at x,y using RawDraw
BMP.Fill(int x, int y, int r, int g, int b);
Do a flood fill at x,y with the specified colour
BMP.Replace(int x, int y, int r, int g, int b);
Replace all pixels with the same colour as at x,y with specified colour
Example
DynamicSprite *ds=DynamicSprite.CreateFromBackground(0, 20, 10, 60, 100);
BMP mybmp;
mybmp.LoadFromDS(ds);
ds.Delete();
mybmp.Fill(mouse.x-20, mouse.y-10, 255, 0, 255);
mybmp.Render(200, 140);
Wait(1);
Display("%d %d", mybmp.Width, mybmp.Height);
Caveats
Will fall over on all kinds of BMP oddities. AGS-written ones should be OK.
Veeeeeeeeeery slow
Revision History
28 Apr 06: v1.0 First release of ReadBMP module
10 May 06: v1.1 Added colour replace and fixed reading bug if w%4==3
Licence
ReadBMP AGS script module
Copyright (C) 2006 Andrew MacCormack
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
In addition to the licences mentioned in the modules themselves, you may choose to use the following creative commons licence if you prefer for all AGS modules and open source code resources on my site.

This work is licenced under a Creative Commons Licence.