public static ColorRGB[] MakePalette(byte[] table) { ColorRGB[] tab = new ColorRGB[table.Length / 3]; int i = 0; int j = 0; while (i < table.Length) { byte r = table[i++]; byte g = table[i++]; byte b = table[i++]; ColorRGB c = new ColorRGB(r, g, b); tab[j++] = c; } return(tab); }
void DoReturn(IGifValue returnValue) { if (stack.Count == 0) { halted = true; return; } else { GifStackFrame returnFrame = stack.Pop(); runningRegister = returnFrame.runningRegister; switch (returnFrame.RHSInstruction) { case 0xCCC: // Assign bool failure; returnValue.Write(returnFrame.LHSValue.Read(), out failure); if (failure) { DoReturn(returnValue); } break; case 0xC8C: // Call stack.Push(new GifStackFrame(returnFrame.runningRegister)); current = returnFrame.LHSValue; runningRegister = returnValue.Read(); break; case 0xCC4: // Retarget ColorRGB lhsColor = returnFrame.LHSValue.Read(); ColorRGB rhsColor = returnValue.Read(); registerTargets[rhsColor.R16, rhsColor.G16, rhsColor.B16] = registerTargets[lhsColor.R16, lhsColor.G16, lhsColor.B16]; current = new GifCursor(rhsColor, GetRegisterPosition(rhsColor), GetRegisterTarget(rhsColor)); break; default: break; } } }
public ColorRGB this[ColorRGB index] { get { if (slices[index.B16] != null) { return(slices[index.B16][index]); } else { return(ColorRGB.Black); } } set { if (slices[index.B16] == null) { AddFrame(index.B16, new GifCubeSlice()); } slices[index.B16][index] = value; } }
string GetRegisterName(ColorRGB registerId) { return("" + GetHexChar(registerId.R16) + GetHexChar(registerId.R16) + GetHexChar(registerId.G16) + GetHexChar(registerId.G16) + GetHexChar(registerId.B16) + GetHexChar(registerId.B16)); }
public void Tick() { if (halted) { return; } ColorRGB programPosition = registerPositions[runningRegister]; GifCube program = GetRegisterTarget(runningRegister); ColorRGB instruction = program[programPosition]; ColorRGB currentColor = current.Read(); // point to the next instruction bool overflow; registerPositions[runningRegister] = registerPositions[runningRegister].Increment(out overflow); if (overflow) { halted = true; return; } switch (instruction.hexSignature) { case 0x000: // Return DoReturn(current); break; case 0xCCC: // Assign stack.Push(new GifStackFrame(current, 0xCCC, runningRegister)); break; case 0xC8C: // Call stack.Push(new GifStackFrame(current, 0xC8C, runningRegister)); break; case 0xC04: // Load GIF break; case 0xC84: // Save GIF //registerTargets[currentColor.R16, currentColor.G16, currentColor.B16].Save(GetRegisterName(currentColor) + ".gif"); break; case 0xCC4: // Retarget stack.Push(new GifStackFrame(current, 0xCC4, runningRegister)); break; case 0x00C: // RegisterPos current = new GifCursor(currentColor, currentColor, registerPositions); break; case 0x08C: // RegisterVal current = new GifCursor(currentColor, registerPositions[currentColor], registerTargets[currentColor.R16, currentColor.G16, currentColor.B16]); break; case 0x0CC: // Data current = new GifCursor(ColorRGB.White, currentColor, registerTargets[15, 15, 15]); break; case 0xC0C: // Modify bool failed; registerPositions[runningRegister] = registerPositions[runningRegister] + new ColorRGB(48, 0, 0); current = Modify(currentColor, new ColorRGB[] { program[programPosition + new ColorRGB(16, 0, 0)], program[programPosition + new ColorRGB(32, 0, 0)], program[programPosition + new ColorRGB(48, 0, 0)] }, out failed ); if (failed) { DoReturn(current); } break; default: current = new GifCursor(runningRegister, programPosition, program); break; } }
public ColorRGB GetRegisterPosition(ColorRGB register) { return(registerPositions[register]); }
public GifCube GetRegisterTarget(ColorRGB register) { return(registerTargets[register.R16, register.G16, register.B16]); }
public GifStackFrame(IGifValue LHSValue, int RHSInstruction, ColorRGB runningRegister) { this.LHSValue = LHSValue.Copy(); this.RHSInstruction = RHSInstruction; this.runningRegister = runningRegister; }
public bool Equals(ColorRGB other) { return(this == other); }
public GifStackFrame(ColorRGB runningRegister) { this.runningRegister = runningRegister; this.RHSInstruction = 0; }
public void Write(ColorRGB color, out bool error) { error = true; }
public GifValue_Readonly(ColorRGB value) { this.value = value; }
public virtual void Write(ColorRGB color, out bool error) { error = false; cube[position] = color; }
public GifCursor(ColorRGB register, ColorRGB position, GifCube cube) { this.register = register; this.position = position; this.cube = cube; }
public ColorRGB this[ColorRGB index] { get { return(pixels[index.R16, index.G16]); } set { pixels[index.R16, index.G16] = value; } }
public int GetOffsetTo(ColorRGB next) { return((next.R - R) + (next.G - G) * 255 + (next.B - B) * 255 * 255); }