void DrawCube(GifCube cube, int frame, ColorRGB highlightPos, Vector2 pos, Vector2 size) { for (int x = 0; x < 16; ++x) { DrawString("" + GetHexChar(x), new Vector2(pos.X + 16 + x * size.X, pos.Y - 20), new Color(x * 16, 0, 0)); DrawString("" + GetHexChar(x), new Vector2(pos.X + 16 + x * size.X, pos.Y + 10 + 16 * size.Y), showingPosition.B16 == x? Color.Yellow: new Color(0, 0, x * 16)); } for (int y = 0; y < 16; ++y) { DrawString("" + GetHexChar(y), new Vector2(pos.X - 16, pos.Y + 10 + y * size.Y), new Color(0, y * 16, 0)); } Vector2 size_ = size; DrawRectangle(pos.ToRectangle(size_ * 16), Color.Black); size_ = size; DrawRectangle(new Vector2(pos.X + highlightPos.R16 * size_.X - 1, pos.Y + highlightPos.G16 * size_.Y - 1).ToRectangle(new Vector2(size_.X + 2, size_.Y + 2)), Color.White); for (int x = 0; x < 16; ++x) { for (int y = 0; y < 16; ++y) { DrawCell(cube, x, y, frame, new Vector2(pos.X + x * size.X, pos.Y + y * size.Y), new Vector2(size.X - 1, size.Y - 1)); } } foreach (Breakpoint b in breakpoints) { if (b.cube == showingCube && b.position.B16 == showingPosition.B16) { DrawImage(breakpointTexture, new Vector2(pos.X + b.position.R16 * size.X + 35, pos.Y + b.position.G16 * size.Y + 18)); } } foreach (ColorRGB register in interestingRegisters) { GifCube registerCube = gifScriptState.GetRegisterTarget(register); if (cube == registerCube) { ColorRGB registerPos = gifScriptState.GetRegisterPosition(register); if (registerPos.B16 == frame) { DrawPointer(register, new Vector2(pos.X + registerPos.R16 * size.X, pos.Y + registerPos.G16 * size.Y), size); } } } }
bool HitBreakpoint() { GifCube cube = gifScriptState.GetRegisterTarget(gifScriptState.runningRegister); ColorRGB position = gifScriptState.GetRegisterPosition(gifScriptState.runningRegister); foreach (Breakpoint b in breakpoints) { if (b.cube != cube) { continue; } if (b.position != position) { continue; } return(true); } return(false); }
void ShowRegister(ColorRGB register) { showingCube = gifScriptState.GetRegisterTarget(register); showingPosition = gifScriptState.GetRegisterPosition(register); needsRedraw = true; }
public static void AddFrame(GifCube cube, byte sliceT, byte[] pixels, short width, ColorRGB[] palette) { cube.AddFrame(sliceT, new GifCubeSlice(pixels, width, palette)); }
static void Main(string[] args) { GifImage gifImage = GifDecoder.Decode(@"C:\Users\Laurie\Pictures\fillpink.gif"); ColorRGB[] globalPalette = ColorRGB.MakePalette(gifImage.GlobalColorTable); GifCube cube = new GifCube(); byte sliceT = 0; foreach (GifFrame f in gifImage.Frames) { byte[] colorTableBytes = f.LocalColorTable; ColorRGB[] palette; if (colorTableBytes == null) { palette = globalPalette; } else { palette = ColorRGB.MakePalette(colorTableBytes); } AddFrame(cube, sliceT, f.IndexedPixel, gifImage.Width, palette); } GifScriptState scriptState = new GifScriptState(); scriptState.Init(cube); scriptState.Tick(); GifCube output = scriptState.GetOutputCube(); Bitmap bmp = new Bitmap(256, 256, PixelFormat.Format24bppRgb); Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height); BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.ReadWrite, bmp.PixelFormat); // Declare an array to hold the bytes of the bitmap. int numBytes = Math.Abs(bmpData.Stride) * bmp.Height; byte[] rgbValues = new byte[numBytes]; int Idx = 0; for (int X = 0; X < 256; X++) { for (int Y = 0; Y < 256; Y++) { ColorRGB col = output[new ColorRGB((byte)X, (byte)Y, 0)]; rgbValues[Idx++] = col.R; rgbValues[Idx++] = col.G; rgbValues[Idx++] = col.B; } } // Copy the RGB values back to the bitmap System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, bmpData.Scan0, numBytes); // Unlock the bits. bmp.UnlockBits(bmpData); bmp.Save(@"C:\Users\Laurie\Pictures\fillpinkOUT.gif", ImageFormat.Gif); /* * Color32[] pallette = new OcTreeQuantizer(8).Quantizer(bmp); * GifHelper.Quantizer(bmp, pallette); * * GifImage resultImage = new GifImage * { * Frames = new List<GifFrame>() * { * new GifFrame() { * Image = bmp, * ImageDescriptor = new ImageDescriptor * { * LctFlag = false,//true, * LctSize = pallette.Length, * Width = 256, * Height = 256, * } * } * }, * LogicalScreenDescriptor = new LogicalScreenDescriptor * { * Width = 256, * Height = 256, * } * }; * GifEncoder.Encode(resultImage, @"C:\Users\Laurie\Pictures\fillpinkOUT.gif");*/ }