Exemple #1
0
        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;
                }
            }
        }
Exemple #3
0
        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;
            }
        }
Exemple #4
0
 string GetRegisterName(ColorRGB registerId)
 {
     return("" + GetHexChar(registerId.R16) + GetHexChar(registerId.R16) + GetHexChar(registerId.G16) + GetHexChar(registerId.G16) + GetHexChar(registerId.B16) + GetHexChar(registerId.B16));
 }
Exemple #5
0
        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;
            }
        }
Exemple #6
0
 public ColorRGB GetRegisterPosition(ColorRGB register)
 {
     return(registerPositions[register]);
 }
Exemple #7
0
 public GifCube GetRegisterTarget(ColorRGB register)
 {
     return(registerTargets[register.R16, register.G16, register.B16]);
 }
Exemple #8
0
 public GifStackFrame(IGifValue LHSValue, int RHSInstruction, ColorRGB runningRegister)
 {
     this.LHSValue        = LHSValue.Copy();
     this.RHSInstruction  = RHSInstruction;
     this.runningRegister = runningRegister;
 }
Exemple #9
0
 public bool Equals(ColorRGB other)
 {
     return(this == other);
 }
Exemple #10
0
 public GifStackFrame(ColorRGB runningRegister)
 {
     this.runningRegister = runningRegister;
     this.RHSInstruction  = 0;
 }
Exemple #11
0
 public void Write(ColorRGB color, out bool error)
 {
     error = true;
 }
Exemple #12
0
 public GifValue_Readonly(ColorRGB value)
 {
     this.value = value;
 }
Exemple #13
0
 public virtual void Write(ColorRGB color, out bool error)
 {
     error          = false;
     cube[position] = color;
 }
Exemple #14
0
 public GifCursor(ColorRGB register, ColorRGB position, GifCube cube)
 {
     this.register = register;
     this.position = position;
     this.cube     = cube;
 }
Exemple #15
0
 public ColorRGB this[ColorRGB index]
 {
     get { return(pixels[index.R16, index.G16]); }
     set { pixels[index.R16, index.G16] = value; }
 }
Exemple #16
0
 public int GetOffsetTo(ColorRGB next)
 {
     return((next.R - R) + (next.G - G) * 255 + (next.B - B) * 255 * 255);
 }