Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- namespace ModdingUtils {
- namespace GFX {
- public class Palette256Colours {
- Color [] colours = new Color [256];
- /// <summary>
- ///
- /// </summary>
- /// <param name="newColours">The array of colours to set the palette to</param>
- public Palette256Colours (Color [] newColours) {
- for (int i = 0; i < 256; i++) {
- if (i > newColours.Length - 1)
- colours [i] = Color.Black;
- else
- colours [i] = Color.FromArgb (255, newColours [i].R, newColours [i].G, newColours [i].B);
- }
- }
- public Color this [int index] {
- get {
- return colours [index];
- }
- set {
- colours [index] = value;
- }
- }
- }
- public class IMG256Colours : IEnumerable, IEnumerator {
- int position = -1;
- private int _width;
- private int _height;
- private Palette256Colours _palette;
- private byte [] _colours;
- //IEnumerator and IEnumerable require these methods.
- public IEnumerator GetEnumerator () {
- return (IEnumerator) this;
- }
- //IEnumerator
- public bool MoveNext () {
- position++;
- return (position < _colours.Length);
- }
- //IEnumerable
- public void Reset () { position = 0; }
- //IEnumerable
- public object Current {
- get { return _colours [position]; }
- }
- /// <summary>
- /// Gets the image's width
- /// </summary>
- public int width {
- get {
- return _width;
- } set {
- _width = value;
- _colours = new byte [_width * _height];
- }
- }
- /// <summary>
- /// Gets the image's height
- /// </summary>
- public int height {
- get {
- return _height;
- } set {
- _height = value;
- _colours = new byte [_width * _height];
- }
- }
- /// <summary>
- /// Erases the contents of the picture. (Sets all pixels to 0)
- /// </summary>
- public void Erase () {
- for (int i = 0; i < _colours.Length; i++)
- _colours [i] = 0;
- }
- /// <summary>
- /// Gets or sets the image's palette
- /// </summary>
- public Palette256Colours palette {
- get {
- return _palette;
- } set {
- _palette = value;
- }
- }
- public IMG256Colours (int newWidth, int newHeight, Palette256Colours newPalette) {
- _width = newWidth;
- _height = newHeight;
- _palette = newPalette;
- _colours = new byte [newWidth * newHeight];
- }
- ~IMG256Colours () {
- _width = 0;
- _height = 0;
- }
- public byte this [int index] {
- get {
- return _colours [index];
- } set {
- _colours [index] = value;
- }
- }
- public Bitmap ToBitmap () {
- Random randomizer = new Random ();
- Bitmap bitmap = new Bitmap (_width, _height);
- for (int i = 0; i < _width * _height; i++) {
- bitmap.SetPixel (i % _width, i / _width, _palette [_colours [i]]);
- }
- return bitmap;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement