Read() public method

public Read ( ) : byte
return byte
Exemplo n.º 1
0
        static void DecompressMaskImgOr(PixelNavigator dst, Stream src, int height)
        {
            byte b, c;

            while (height != 0)
            {
                b = (byte)src.ReadByte();

                if ((b & 0x80) != 0)
                {
                    b &= 0x7F;
                    c  = (byte)src.ReadByte();

                    do
                    {
                        dst.Write((byte)(dst.Read() | c));
                        dst.OffsetY(1);
                        --height;
                    } while ((--b != 0) && (height != 0));
                }
                else
                {
                    do
                    {
                        dst.Write((byte)(dst.Read() | src.ReadByte()));
                        dst.OffsetY(1);
                        --height;
                    } while ((--b != 0) && (height != 0));
                }
            }
        }
Exemplo n.º 2
0
 static void Copy8Col(PixelNavigator navDst, PixelNavigator navSource, int height)
 {
     do
     {
         for (int i = 0; i < 8; i++)
         {
             navDst.Write(navSource.Read());
             navDst.OffsetX(1);
             navSource.OffsetX(1);
         }
         navDst.Offset(-8, 1);
         navSource.Offset(-8, 1);
     } while ((--height) != 0);
 }
Exemplo n.º 3
0
 public static void Blit(PixelNavigator dst, PixelNavigator src, int width, int height)
 {
     for (var h = 0; h < height; h++)
     {
         for (int w = 0; w < width; w++)
         {
             dst.Write(src.Read());
             src.OffsetX(1);
             dst.OffsetX(1);
         }
         src.Offset(-width, 1);
         dst.Offset(-width, 1);
     }
 }
Exemplo n.º 4
0
 static void BompApplyShadow3(byte[] shadowPalette, byte[] lineBuffer, int linePos, PixelNavigator dst, int size, byte transparency)
 {
     while (size-- > 0)
     {
         byte tmp = lineBuffer[linePos++];
         if (tmp != transparency)
         {
             if (tmp < 8)
             {
                 tmp = shadowPalette[dst.Read() + (tmp << 8)];
             }
             dst.Write(tmp);
         }
         dst.OffsetX(1);
     }
 }
Exemplo n.º 5
0
 public static void BompApplyMask(byte[] line_buffer, int linePos, PixelNavigator mask, byte maskbit, int size, byte transparency)
 {
     while (true)
     {
         do
         {
             if (size-- == 0)
             {
                 return;
             }
             if ((mask.Read() & maskbit) != 0)
             {
                 line_buffer[linePos] = transparency;
             }
             linePos++;
             maskbit >>= 1;
         } while (maskbit != 0);
         mask.OffsetX(1);
         maskbit = 128;
     }
 }
Exemplo n.º 6
0
        void Proc3Amiga(Codec1 v1)
        {
            byte len;
            int color;
            bool masked;

            var mask = new PixelNavigator(v1.MaskPtr);
            mask.OffsetX(v1.X / 8);
            var dst = new PixelNavigator(v1.DestPtr);
            byte height = (byte)_height;
            byte width = (byte)_width;
            _loaded.CostumeReader.BaseStream.Seek(_srcptr, System.IO.SeekOrigin.Begin);
            var maskbit = (byte)ScummHelper.RevBitMask(v1.X & 7);
            var y = v1.Y;
            var oldXpos = v1.X;
            var oldScaleIndexX = _scaleIndexX;

            // Indy4 Amiga always uses the room map to match colors to the currently
            // setup palette in the actor code in the original, thus we need to do this
            // mapping over here too.
            var amigaMap = 
                (_vm.Game.Platform == Platform.Amiga && _vm.Game.GameId == GameId.Indy4) ? _vm.Gdi.RoomPalette : null;

            do
            {
                len = _loaded.CostumeReader.ReadByte();
                color = len >> v1.Shr;
                len &= v1.Mask;
                if (len == 0)
                    len = _loaded.CostumeReader.ReadByte();
                do
                {
                    if (ScaleY == 255 || v1.Scaletable[_scaleIndexY] < ScaleY)
                    {
                        masked = (y < 0 || y >= _h) || (v1.X < 0 || v1.X >= _w) || ((mask.Read() & maskbit) != 0);

                        if (color != 0 && !masked)
                        {
                            byte pcolor;
                            if (amigaMap != null)
                                pcolor = amigaMap[_palette[color]];
                            else
                                pcolor = (byte)_palette[color];
                            dst.Write(pcolor);
                        }

                        if (ScaleX == 255 || v1.Scaletable[_scaleIndexX] < ScaleX)
                        {
                            v1.X += v1.ScaleXStep;
                            dst.OffsetX(v1.ScaleXStep);
                            maskbit = (byte)ScummHelper.RevBitMask(v1.X & 7);
                        }
                        _scaleIndexX += (byte)v1.ScaleXStep;
                        mask = new PixelNavigator(v1.MaskPtr);
                        mask.OffsetX(v1.X / 8);
                    }
                    if (--width == 0)
                    {
                        if (--height == 0)
                            return;

                        if (y >= _h)
                            return;

                        if (v1.X != oldXpos)
                        {
                            dst.Offset(-(v1.X - oldXpos), 1);
                            mask = new PixelNavigator(v1.MaskPtr);
                            mask.OffsetY(1);
                            v1.MaskPtr = mask;
                            mask.OffsetX(oldXpos / 8);
                            maskbit = (byte)ScummHelper.RevBitMask(oldXpos & 7);
                            y++;
                        }
                        width = (byte)_width;
                        v1.X = oldXpos;
                        _scaleIndexX = oldScaleIndexX;
                        _scaleIndexY++;
                    }
                } while (--len != 0);
            } while (true);
        }
Exemplo n.º 7
0
        void Proc3(Codec1 v1)
        {
            int y = v1.Y;
            _loaded.CostumeReader.BaseStream.Seek(_srcptr, System.IO.SeekOrigin.Begin);
            var dst = new PixelNavigator(v1.DestPtr);
            var len = v1.RepLen;
            uint color = v1.RepColor;
            var height = (uint)_height;

            var scaleIndexY = _scaleIndexY;
            var maskbit = (byte)ScummHelper.RevBitMask(v1.X & 7);
            var mask = new PixelNavigator(v1.MaskPtr);
            mask.OffsetX(v1.X / 8);

            bool ehmerde = (len != 0);

            do
            {
                if (!ehmerde)
                {
                    len = _loaded.CostumeReader.ReadByte();
                    color = (uint)(len >> v1.Shr);
                    len &= v1.Mask;
                    if (len == 0)
                        len = _loaded.CostumeReader.ReadByte();
                }

                do
                {
                    if (!ehmerde)
                    {
                        if (ScaleY == 255 || v1.Scaletable[scaleIndexY++] < ScaleY)
                        {
                            var masked = (y < 0 || y >= _h) || (v1.X < 0 || v1.X >= _w) || ((mask.Read() & maskbit) != 0);

                            if (color != 0 && !masked)
                            {
                                byte pcolor;
                                if ((ShadowMode & 0x20) != 0)
                                {
                                    pcolor = ShadowTable[dst.Read()];
                                }
                                else
                                {
                                    pcolor = (byte)_palette[color];
                                    if (pcolor == 13 && ShadowTable != null)
                                        pcolor = ShadowTable[dst.Read()];
                                }
                                dst.Write(pcolor);
                            }
                            dst.OffsetY(1);
                            mask.OffsetY(1);
                            y++;
                        }
                        if ((--height) == 0)
                        {
                            if ((--v1.SkipWidth) == 0)
                                return;
                            height = (uint)_height;
                            y = v1.Y;

                            scaleIndexY = _scaleIndexY;

                            if (ScaleX == 255 || v1.Scaletable[_scaleIndexX] < ScaleX)
                            {
                                v1.X += v1.ScaleXStep;
                                if (v1.X < 0 || v1.X >= _w)
                                    return;
                                maskbit = (byte)ScummHelper.RevBitMask(v1.X & 7);
                                v1.DestPtr.OffsetX(v1.ScaleXStep);
                            }
                            _scaleIndexX = (byte)(_scaleIndexX + v1.ScaleXStep);
                            dst = new PixelNavigator(v1.DestPtr);
                            mask = new PixelNavigator(v1.MaskPtr);
                            mask.OffsetX(v1.X / 8);
                        }
                    }
                    ehmerde = false;
                } while ((--len) != 0);
            } while (true);
        }
Exemplo n.º 8
0
        protected virtual void KernelGetFunctions()
        {
            var vs = MainVirtScreen;

            var args = GetStackList(30);

            switch (args[0])
            {
                case 113:
                    // WORKAROUND for bug #899249: The scripts used for screen savers
                    // in Sam & Max use hard coded values for the maximum height and width.
                    // This causes problems in rooms (ie. Credits) where their values are
                    // lower, so we set result to zero if out of bounds.
                    if (args[1] >= 0 && args[1] <= vs.Width && args[2] >= 0 && args[2] <= vs.Height)
                    {
                        var nav = new PixelNavigator(vs.Surfaces[0]);
                        nav.GoTo(args[1], args[2]);
                        var pixel = nav.Read();
                        Push(pixel);
                    }
                    else
                    {
                        Push(0);
                    }
                    break;
                case 115:
                    Push(GetSpecialBox(new Point((short)args[1], (short)args[2])));
                    break;
                case 116:
                    Push(CheckXYInBoxBounds(args[3], new Point((short)args[1], (short)args[2])));
                    break;
                case 206:
                    Push(RemapPaletteColor(args[1], args[2], args[3], -1));
                    break;
                case 207:
                    {
                        var i = GetObjectIndex(args[1]);
                        Debug.Assert(i != 0);
                        Push(_objs[i].Position.X);
                    }
                    break;
                case 208:
                    {
                        var i = GetObjectIndex(args[1]);
                        Debug.Assert(i != 0);
                        Push(_objs[i].Position.Y);
                    }
                    break;
                case 209:
                    {
                        var i = GetObjectIndex(args[1]);
                        Debug.Assert(i != 0);
                        Push(_objs[i].Width);
                    }
                    break;
                case 210:
                    {
                        var i = GetObjectIndex(args[1]);
                        Debug.Assert(i != 0);
                        Push(_objs[i].Height);
                    }
                    break;
                case 211:
                    /*
                   13 = thrust
                   336 = thrust
                   328 = thrust
                   27 = abort
                   97 = left
                   331 = left
                   115 = right
                   333 = right
                 */

                    Push(GetKeyState(args[1]));
                    break;
                case 212:
                    {
                        var a = Actors[args[1]];
                        // This is used by walk scripts
                        Push(a.Frame);
                    }
                    break;
                case 213:
                    {
                        var slot = GetVerbSlot(args[1], 0);
                        Push(Verbs[slot].CurRect.Left);
                    }
                    break;
                case 214:
                    {
                        var slot = GetVerbSlot(args[1], 0);
                        Push(Verbs[slot].CurRect.Top);
                    }
                    break;
                case 215:
                    if ((_extraBoxFlags[args[1]] & 0x00FF) == 0x00C0)
                    {
                        Push(_extraBoxFlags[args[1]]);
                    }
                    else
                    {
                        Push((int)GetBoxFlags((byte)args[1]));
                    }
                    break;
                default:
                    throw new NotSupportedException(string.Format("KernelGetFunctions: default case {0}", args[0]));
            }
        }
Exemplo n.º 9
0
        protected void GetPixel(int x, int y)
        {
            var vs = FindVirtScreen(y);
            if (vs == null || x > ScreenWidth - 1 || x < 0)
            {
                Push(-1);
                return;
            }

            var nav = new PixelNavigator(vs.Surfaces[0]);
            nav.GoTo(x, y - vs.TopLine);
            var pixel = nav.Read();
            Push(pixel);
        }
Exemplo n.º 10
0
        protected override void DrawBitsN(Surface s, PixelNavigator dst, IList <byte> src, int srcPos, byte bpp, int drawTop, int width, int height)
        {
//            if (_sjisCurChar)
//            {
//                assert(Vm._cjkFont);
//                Vm._cjkFont.drawChar(Vm._textSurface, _sjisCurChar, _left * Vm._textSurfaceMultiplier, (_top - Vm._screenTop) * Vm._textSurfaceMultiplier, Vm._townsCharsetColorMap[1], _shadowColor);
//                return;
//            }

            bool scale2x = (Vm.TextSurfaceMultiplier == 2);

            dst = new PixelNavigator(Vm.TextSurface);
            dst.GoTo(Left * Vm.TextSurfaceMultiplier, (Top - Vm.ScreenTop) * Vm.TextSurfaceMultiplier);

            int  y, x;
            int  color;
            byte numbits, bits;

            int pitch = Vm.TextSurface.Pitch - width;

            Debug.Assert(bpp == 1 || bpp == 2 || bpp == 4 || bpp == 8);
            bits    = src[srcPos++];
            numbits = 8;
            var cmap = Vm.CharsetColorMap;
            var dst2 = new PixelNavigator(dst);

            if (Vm.Game.Platform == Platform.FMTowns)
            {
                cmap = Vm.TownsCharsetColorMap;
            }
            if (scale2x)
            {
                dst2.OffsetY(1);
                pitch <<= 1;
            }

            for (y = 0; y < height && y + drawTop < Vm.TextSurface.Height; y++)
            {
                for (x = 0; x < width; x++)
                {
                    color = (bits >> (8 - bpp)) & 0xFF;
                    if (color != 0 && y + drawTop >= 0)
                    {
                        dst.Write(cmap[color]);
                        if (scale2x)
                        {
                            dst.Write(1, dst.Read());
                            dst2.Write(dst.Read());
                            dst2.Write(1, dst.Read());
                        }
                    }
                    dst.OffsetX(1);

                    if (scale2x)
                    {
                        dst.OffsetX(1);
                        dst2.OffsetX(2);
                    }

                    bits   <<= bpp;
                    numbits -= bpp;
                    if (numbits == 0)
                    {
                        bits    = src[srcPos++];
                        numbits = 8;
                    }
                }
                dst.OffsetX(pitch / dst.BytesByPixel);
                dst2.OffsetX(pitch / dst2.BytesByPixel);
            }
        }
Exemplo n.º 11
0
 bool MASK_AT(int xoff, PixelNavigator mask, int destX)
 {
     mask.OffsetX((destX + xoff) / 8);
     return((mask.Read() & ScummHelper.RevBitMask((destX + xoff) & 7)) != 0);
 }
Exemplo n.º 12
0
 static byte[] Capture(VirtScreen screen, int x, int y, int w, int h)
 {
     var pixels = new byte[w * h];
     var nav = new PixelNavigator(screen.Surfaces[0]);
     nav.GoTo(x, y);
     for (int height = 0; height < h; height++)
     {
         for (int width = 0; width < w; width++)
         {
             pixels[height * w + width] = nav.Read();
             nav.OffsetX(1);
         }
         nav.Offset(-w, 1);
     }
     return pixels;
 }
Exemplo n.º 13
0
 public static void BompApplyMask(byte[] line_buffer, int linePos, PixelNavigator mask, byte maskbit, int size, byte transparency)
 {
     while (true)
     {
         do
         {
             if (size-- == 0)
                 return;
             if ((mask.Read() & maskbit) != 0)
             {
                 line_buffer[linePos] = transparency;
             }
             linePos++;
             maskbit >>= 1;
         } while (maskbit != 0);
         mask.OffsetX(1);
         maskbit = 128;
     }
 }
Exemplo n.º 14
0
        protected override void DrawBitsN(Surface s, PixelNavigator dst, IList<byte> src, int srcPos, byte bpp, int drawTop, int width, int height)
        {
//            if (_sjisCurChar)
//            {
//                assert(Vm._cjkFont);
//                Vm._cjkFont.drawChar(Vm._textSurface, _sjisCurChar, _left * Vm._textSurfaceMultiplier, (_top - Vm._screenTop) * Vm._textSurfaceMultiplier, Vm._townsCharsetColorMap[1], _shadowColor);
//                return;
//            }

            bool scale2x = (Vm.TextSurfaceMultiplier == 2);
            dst = new PixelNavigator(Vm.TextSurface);
            dst.GoTo(Left * Vm.TextSurfaceMultiplier, (Top - Vm.ScreenTop) * Vm.TextSurfaceMultiplier);

            int y, x;
            int color;
            byte numbits, bits;

            int pitch = Vm.TextSurface.Pitch - width;

            Debug.Assert(bpp == 1 || bpp == 2 || bpp == 4 || bpp == 8);
            bits = src[srcPos++];
            numbits = 8;
            var cmap = Vm.CharsetColorMap;
            var dst2 = new PixelNavigator(dst);

            if (Vm.Game.Platform == Platform.FMTowns)
                cmap = Vm.TownsCharsetColorMap;
            if (scale2x)
            {
                dst2.OffsetY(1);
                pitch <<= 1;
            }

            for (y = 0; y < height && y + drawTop < Vm.TextSurface.Height; y++)
            {
                for (x = 0; x < width; x++)
                {
                    color = (bits >> (8 - bpp)) & 0xFF;
                    if (color != 0 && y + drawTop >= 0)
                    {
                        dst.Write(cmap[color]);
                        if (scale2x)
                        {
                            dst.Write(1, dst.Read());
                            dst2.Write(dst.Read());
                            dst2.Write(1, dst.Read());
                        }
                    }
                    dst.OffsetX(1);

                    if (scale2x)
                    {
                        dst.OffsetX(1);
                        dst2.OffsetX(2);
                    }

                    bits <<= bpp;
                    numbits -= bpp;
                    if (numbits == 0)
                    {
                        bits = src[srcPos++];
                        numbits = 8;
                    }
                }
                dst.OffsetX(pitch / dst.BytesByPixel);
                dst2.OffsetX(pitch / dst2.BytesByPixel);
            }
        }
Exemplo n.º 15
0
        void DrawStripEGA(PixelNavigator navDst, BinaryReader src, int height)
        {
            byte color;
            int run;
            int x = 0, y = 0;
            int z;

            navDst = new PixelNavigator(navDst);

            while (x < 8)
            {
                color = src.ReadByte();

                if ((color & 0x80) != 0)
                {
                    run = color & 0x3f;

                    if ((color & 0x40) != 0)
                    {
                        color = src.ReadByte();

                        if (run == 0)
                        {
                            run = src.ReadByte();
                        }
                        for (z = 0; z < run; z++)
                        {
                            navDst.GoTo(x, y);
                            navDst.Write((z & 1) != 0 ? RoomPalette[(color & 0xf) + paletteMod] : RoomPalette[(color >> 4) + paletteMod]);

                            y++;
                            if (y >= height)
                            {
                                y = 0;
                                x++;
                            }
                        }
                    }
                    else
                    {
                        if (run == 0)
                        {
                            run = src.ReadByte();
                        }

                        for (z = 0; z < run; z++)
                        {
                            navDst.GoTo(x - 1, y);
                            var col = navDst.Read();
                            navDst.GoTo(x, y);
                            navDst.Write(col);

                            y++;
                            if (y >= height)
                            {
                                y = 0;
                                x++;
                            }
                        }
                    }
                }
                else
                {
                    run = color >> 4;
                    if (run == 0)
                    {
                        run = src.ReadByte();
                    }

                    for (z = 0; z < run; z++)
                    {
                        navDst.GoTo(x, y);
                        navDst.Write(RoomPalette[(color & 0xf) + paletteMod]);

                        y++;
                        if (y >= height)
                        {
                            y = 0;
                            x++;
                        }
                    }
                }
            }
        }
Exemplo n.º 16
0
 public static void Blit(PixelNavigator dst, PixelNavigator src, int width, int height)
 {
     for (var h = 0; h < height; h++)
     {
         for (int w = 0; w < width; w++)
         {
             dst.Write(src.Read());
             src.OffsetX(1);
             dst.OffsetX(1);
         }
         src.Offset(-width, 1);
         dst.Offset(-width, 1);
     }
 }
Exemplo n.º 17
0
        void DrawStripEGA(PixelNavigator navDst, BinaryReader src, int height)
        {
            byte color;
            int  run;
            int  x = 0, y = 0;
            int  z;

            navDst = new PixelNavigator(navDst);

            while (x < 8)
            {
                color = src.ReadByte();

                if ((color & 0x80) != 0)
                {
                    run = color & 0x3f;

                    if ((color & 0x40) != 0)
                    {
                        color = src.ReadByte();

                        if (run == 0)
                        {
                            run = src.ReadByte();
                        }
                        for (z = 0; z < run; z++)
                        {
                            navDst.GoTo(x, y);
                            navDst.Write((z & 1) != 0 ? RoomPalette[(color & 0xf) + paletteMod] : RoomPalette[(color >> 4) + paletteMod]);

                            y++;
                            if (y >= height)
                            {
                                y = 0;
                                x++;
                            }
                        }
                    }
                    else
                    {
                        if (run == 0)
                        {
                            run = src.ReadByte();
                        }

                        for (z = 0; z < run; z++)
                        {
                            navDst.GoTo(x - 1, y);
                            var col = navDst.Read();
                            navDst.GoTo(x, y);
                            navDst.Write(col);

                            y++;
                            if (y >= height)
                            {
                                y = 0;
                                x++;
                            }
                        }
                    }
                }
                else
                {
                    run = color >> 4;
                    if (run == 0)
                    {
                        run = src.ReadByte();
                    }

                    for (z = 0; z < run; z++)
                    {
                        navDst.GoTo(x, y);
                        navDst.Write(RoomPalette[(color & 0xf) + paletteMod]);

                        y++;
                        if (y >= height)
                        {
                            y = 0;
                            x++;
                        }
                    }
                }
            }
        }
Exemplo n.º 18
0
        static void DecompressMaskImgOr(PixelNavigator dst, Stream src, int height)
        {
            byte b, c;

            while (height != 0)
            {
                b = (byte)src.ReadByte();

                if ((b & 0x80) != 0)
                {
                    b &= 0x7F;
                    c = (byte)src.ReadByte();

                    do
                    {
                        dst.Write((byte)(dst.Read() | c));
                        dst.OffsetY(1);
                        --height;
                    } while ((--b != 0) && (height != 0));
                }
                else
                {
                    do
                    {
                        dst.Write((byte)(dst.Read() | src.ReadByte()));
                        dst.OffsetY(1);
                        --height;
                    } while ((--b != 0) && (height != 0));
                }
            }
        }
Exemplo n.º 19
0
 static void Copy8Col(PixelNavigator navDst, PixelNavigator navSource, int height)
 {
     do
     {
         for (int i = 0; i < 8; i++)
         {
             navDst.Write(navSource.Read());
             navDst.OffsetX(1);
             navSource.OffsetX(1);
         }
         navDst.Offset(-8, 1);
         navSource.Offset(-8, 1);
     } while ((--height) != 0);
 }
Exemplo n.º 20
0
 static void BompApplyShadow3(byte[] shadowPalette, byte[] lineBuffer, int linePos, PixelNavigator dst, int size, byte transparency)
 {
     while (size-- > 0)
     {
         byte tmp = lineBuffer[linePos++];
         if (tmp != transparency)
         {
             if (tmp < 8)
             {
                 tmp = shadowPalette[dst.Read() + (tmp << 8)];
             }
             dst.Write(tmp);
         }
         dst.OffsetX(1);
     }
 }
Exemplo n.º 21
0
        /// <summary>
        /// Blit the specified rectangle from the given virtual screen to the display.
        /// Note: t and b are in *virtual screen* coordinates, while x is relative to
        /// the *real screen*. This is due to the way tdirty/vdirty work: they are
        /// arrays which map 'strips' (sections of the real screen) to dirty areas as
        /// specified by top/bottom coordinate in the virtual screen.
        /// </summary>
        /// <param name="vs"></param>
        /// <param name="x"></param>
        /// <param name="width"></param>
        /// <param name="top"></param>
        /// <param name="bottom"></param>
        void DrawStripToScreen(VirtScreen vs, int x, int width, int top, int bottom)
        {
            // Short-circuit if nothing has to be drawn
            if (bottom <= top || top >= vs.Height)
                return;

            // Perform some clipping
            if (width > vs.Width - x)
                width = vs.Width - x;
            if (top < ScreenTop)
                top = ScreenTop;
            if (bottom > ScreenTop + ScreenHeight)
                bottom = ScreenTop + ScreenHeight;

            // Convert the vertical coordinates to real screen coords
            int y = vs.TopLine + top - ScreenTop;
            int height = bottom - top;

            if (width <= 0 || height <= 0)
                return;

            byte[] src;
            if (Game.Version < 7)
            {
                if (Game.Platform == Platform.FMTowns)
                {
                    TownsDrawStripToScreen(vs, x, y, x, top, width, height);
                    return;
                }

                var srcNav = new PixelNavigator(vs.Surfaces[0]);
                srcNav.GoTo(vs.XStart + x, top);

                var compNav = new PixelNavigator(_composite);
                var txtNav = new PixelNavigator(_textSurface);
                int m = _textSurfaceMultiplier;
                txtNav.GoTo(x * m, y * m);

                var vsPitch = vs.Pitch - width * vs.BytesPerPixel;
                var textPitch = _textSurface.Pitch - width * m;

                for (int h = height * m; h > 0; --h)
                {
                    for (int w = width * m; w > 0; w--)
                    {
                        var temp = txtNav.Read();
                        int mask = temp ^ CharsetMaskTransparency;
                        mask = (((mask & 0x7f) + 0x7f) | mask) & 0x80;
                        mask = ((mask >> 7) + 0x7f) ^ 0x80;

                        var dst = ((temp ^ srcNav.Read()) & mask) ^ temp;
                        compNav.Write((byte)dst);

                        srcNav.OffsetX(1);
                        txtNav.OffsetX(1);
                        compNav.OffsetX(1);
                    }

                    srcNav.OffsetX(vsPitch);
                    txtNav.OffsetX(textPitch);
                }

                src = _composite.Pixels;
            }
            else
            {
                src = new byte[width * height * vs.BytesPerPixel];
                var srcNav = new PixelNavigator(vs.Surfaces[0]);
                srcNav.GoTo(vs.XStart + x, top);
                for (int h = 0; h < height; h++)
                {
                    for (int w = 0; w < width; w++)
                    {
                        src[h * width + w] = srcNav.Read();
                        srcNav.OffsetX(1);
                    }
                    srcNav.Offset(-width, 1);
                }
            }

            // Finally blit the whole thing to the screen
            _gfxManager.CopyRectToScreen(src, width * vs.BytesPerPixel, x, y, width, height);
        }
Exemplo n.º 22
0
        protected void RedefineBuiltinCursorFromChar(int index, int chr)
        {
            // Cursor image in both Loom versions are based on images from charset.
            // This function is *only* supported for Loom!
            if (_game.GameId != Scumm.IO.GameId.Loom)
                throw new NotSupportedException("RedefineBuiltinCursorFromChar is *only* supported for Loom!");
            if (index < 0 || index >= 4)
                throw new ArgumentException("index");

            //	const int oldID = _charset->getCurID();

            var ptr = _cursorImages[index];

            if (_game.Version == 3)
            {
                _charset.SetCurID(0);
            }
            else if (_game.Version >= 4)
            {
                _charset.SetCurID(1);
            }

            var s = new Surface(_charset.GetCharWidth(chr), _charset.GetFontHeight(), PixelFormat.Indexed8, false);
            var p = new PixelNavigator(s);
            Gdi.Fill(new PixelNavigator(s), 123, s.Width, s.Height);

            _charset.DrawChar(chr, s, 0, 0);

            Array.Clear(ptr, 0, ptr.Length);
            for (int h = 0; h < s.Height; h++)
            {
                for (int w = 0; w < s.Width; w++)
                {
                    p.GoTo(w, h);
                    if (p.Read() != 123)
                    {
                        ptr[h] |= (ushort)(1 << (15 - w));
                    }
                }
            }

            //	_charset->setCurID(oldID);
        }
Exemplo n.º 23
0
        protected void TownsDrawStripToScreen(VirtScreen vs, int dstX, int dstY, int srcX, int srcY, int width, int height)
        {
            if (width <= 0 || height <= 0)
                return;

            int m = _textSurfaceMultiplier;

            var src1 = new PixelNavigator(vs.Surfaces[0]);
            src1.GoTo(vs.XStart + srcX, srcY);
            var src2 = new PixelNavigator(_textSurface);
            src2.GoTo(srcX * m, (srcY + vs.TopLine - ScreenTop) * m);
            var dst1 = new PixelNavigator(_townsScreen.GetLayerPixels(0, dstX, dstY).Value);
            var dst2 = new PixelNavigator(_townsScreen.GetLayerPixels(1, dstX * m, dstY * m).Value);

            int dp1 = _townsScreen.GetLayerPitch(0) - width * _townsScreen.GetLayerBpp(0);
            int dp2 = _townsScreen.GetLayerPitch(1) - width * m * _townsScreen.GetLayerBpp(1);
            int sp1 = vs.Pitch - (width * Surface.GetBytesPerPixel(vs.PixelFormat));
            int sp2 = _textSurface.Pitch - width * m;

            if (vs == MainVirtScreen || Game.GameId == GameId.Indy3 || Game.GameId == GameId.Zak)
            {
                for (int h = 0; h < height; ++h)
                {
                    if (Surface.GetBytesPerPixel(_gfxManager.PixelFormat) == 2)
                    {
                        for (int w = 0; w < width; ++w)
                        {
                            dst1.WriteUInt16(_16BitPalette[src1.Read()]);
                            src1.OffsetX(1);
                            dst1.OffsetX(1);
                        }

                        src1.OffsetX(sp1 / src1.BytesByPixel);
                        dst1.OffsetX(dp1 / dst1.BytesByPixel);
                    }
                    else
                    {
                        for (int i = 0; i < width; i++)
                        {
                            dst1.Write(src1.Read());
                            dst1.OffsetX(1);
                            src1.OffsetX(1);
                        }
                    }

                    for (int sH = 0; sH < m; ++sH)
                    {
                        for (int i = 0; i < width * m; i++)
                        {
                            dst2.Write(src2.Read());
                            src2.OffsetX(1);
                            dst2.OffsetX(1);
                        }
                        src2.OffsetX(_textSurface.Width - (width * m));
                        dst2.OffsetX(dst2.Width - (width * m));
                    }
                }
            }
            else
            {
                dst1 = new PixelNavigator(dst2);
                for (int h = 0; h < height; ++h)
                {
                    for (int w = 0; w < width; ++w)
                    {
                        var t = (src1.Read()) & 0x0f;
                        src1.OffsetX(1);
                        for (int i = 0; i < m; i++)
                        {
                            dst1.Write((byte)((t << 4) | t));
                            dst1.OffsetX(1);
                        }
                    }

                    dst1 = new PixelNavigator(dst2);
                    var src3 = new PixelNavigator(src2);

                    if (m == 2)
                    {
                        dst2.OffsetY(1);
                        src3.OffsetY(1);
                    }

                    for (int w = 0; w < width * m; ++w)
                    {
                        dst2.Write((byte)(src3.Read() | dst1.Read() & _townsLayer2Mask[src3.Read()]));
                        dst2.OffsetX(1);
                        dst1.Write((byte)(src2.Read() | dst1.Read() & _townsLayer2Mask[src2.Read()]));
                        src2.OffsetX(1);
                        src3.OffsetX(1);
                        dst1.OffsetX(1);
                    }

                    src1.OffsetX(sp1 / src1.BytesByPixel);
                    src2 = new PixelNavigator(src3);
                    src2.OffsetX(sp2 / src2.BytesByPixel);
                    dst1 = new PixelNavigator(dst2);
                    dst1.OffsetX(dp2 / dst1.BytesByPixel);
                    dst2.OffsetX(dp2 / dst2.BytesByPixel);
                }
            }

            _townsScreen.AddDirtyRect(dstX * m, dstY * m, width * m, height * m);
        }
Exemplo n.º 24
0
        void Proc3(Codec1 v1)
        {
            int y = v1.Y;

            _loaded.CostumeReader.BaseStream.Seek(_srcptr, System.IO.SeekOrigin.Begin);
            var  dst    = new PixelNavigator(v1.DestPtr);
            var  len    = v1.RepLen;
            uint color  = v1.RepColor;
            var  height = (uint)_height;

            var scaleIndexY = _scaleIndexY;
            var maskbit     = (byte)ScummHelper.RevBitMask(v1.X & 7);
            var mask        = new PixelNavigator(v1.MaskPtr);

            mask.OffsetX(v1.X / 8);

            bool ehmerde = (len != 0);

            do
            {
                if (!ehmerde)
                {
                    len   = _loaded.CostumeReader.ReadByte();
                    color = (uint)(len >> v1.Shr);
                    len  &= v1.Mask;
                    if (len == 0)
                    {
                        len = _loaded.CostumeReader.ReadByte();
                    }
                }

                do
                {
                    if (!ehmerde)
                    {
                        if (ScaleY == 255 || v1.Scaletable[scaleIndexY++] < ScaleY)
                        {
                            var masked = (y < 0 || y >= _h) || (v1.X < 0 || v1.X >= _w) || ((mask.Read() & maskbit) != 0);

                            if (color != 0 && !masked)
                            {
                                byte pcolor;
                                if ((ShadowMode & 0x20) != 0)
                                {
                                    pcolor = ShadowTable[dst.Read()];
                                }
                                else
                                {
                                    pcolor = (byte)_palette[color];
                                    if (pcolor == 13 && ShadowTable != null)
                                    {
                                        pcolor = ShadowTable[dst.Read()];
                                    }
                                }
                                dst.Write(pcolor);
                            }
                            dst.OffsetY(1);
                            mask.OffsetY(1);
                            y++;
                        }
                        if ((--height) == 0)
                        {
                            if ((--v1.SkipWidth) == 0)
                            {
                                return;
                            }
                            height = (uint)_height;
                            y      = v1.Y;

                            scaleIndexY = _scaleIndexY;

                            if (ScaleX == 255 || v1.Scaletable[_scaleIndexX] < ScaleX)
                            {
                                v1.X += v1.ScaleXStep;
                                if (v1.X < 0 || v1.X >= _w)
                                {
                                    return;
                                }
                                maskbit = (byte)ScummHelper.RevBitMask(v1.X & 7);
                                v1.DestPtr.OffsetX(v1.ScaleXStep);
                            }
                            _scaleIndexX = (byte)(_scaleIndexX + v1.ScaleXStep);
                            dst          = new PixelNavigator(v1.DestPtr);
                            mask         = new PixelNavigator(v1.MaskPtr);
                            mask.OffsetX(v1.X / 8);
                        }
                    }
                    ehmerde = false;
                } while ((--len) != 0);
            } while (true);
        }
Exemplo n.º 25
0
        void Proc3Amiga(Codec1 v1)
        {
            byte len;
            int  color;
            bool masked;

            var mask = new PixelNavigator(v1.MaskPtr);

            mask.OffsetX(v1.X / 8);
            var  dst    = new PixelNavigator(v1.DestPtr);
            byte height = (byte)_height;
            byte width  = (byte)_width;

            _loaded.CostumeReader.BaseStream.Seek(_srcptr, System.IO.SeekOrigin.Begin);
            var maskbit        = (byte)ScummHelper.RevBitMask(v1.X & 7);
            var y              = v1.Y;
            var oldXpos        = v1.X;
            var oldScaleIndexX = _scaleIndexX;

            // Indy4 Amiga always uses the room map to match colors to the currently
            // setup palette in the actor code in the original, thus we need to do this
            // mapping over here too.
            var amigaMap =
                (_vm.Game.Platform == Platform.Amiga && _vm.Game.GameId == GameId.Indy4) ? _vm.Gdi.RoomPalette : null;

            do
            {
                len   = _loaded.CostumeReader.ReadByte();
                color = len >> v1.Shr;
                len  &= v1.Mask;
                if (len == 0)
                {
                    len = _loaded.CostumeReader.ReadByte();
                }
                do
                {
                    if (ScaleY == 255 || v1.Scaletable[_scaleIndexY] < ScaleY)
                    {
                        masked = (y < 0 || y >= _h) || (v1.X < 0 || v1.X >= _w) || ((mask.Read() & maskbit) != 0);

                        if (color != 0 && !masked)
                        {
                            byte pcolor;
                            if (amigaMap != null)
                            {
                                pcolor = amigaMap[_palette[color]];
                            }
                            else
                            {
                                pcolor = (byte)_palette[color];
                            }
                            dst.Write(pcolor);
                        }

                        if (ScaleX == 255 || v1.Scaletable[_scaleIndexX] < ScaleX)
                        {
                            v1.X += v1.ScaleXStep;
                            dst.OffsetX(v1.ScaleXStep);
                            maskbit = (byte)ScummHelper.RevBitMask(v1.X & 7);
                        }
                        _scaleIndexX += (byte)v1.ScaleXStep;
                        mask          = new PixelNavigator(v1.MaskPtr);
                        mask.OffsetX(v1.X / 8);
                    }
                    if (--width == 0)
                    {
                        if (--height == 0)
                        {
                            return;
                        }

                        if (y >= _h)
                        {
                            return;
                        }

                        if (v1.X != oldXpos)
                        {
                            dst.Offset(-(v1.X - oldXpos), 1);
                            mask = new PixelNavigator(v1.MaskPtr);
                            mask.OffsetY(1);
                            v1.MaskPtr = mask;
                            mask.OffsetX(oldXpos / 8);
                            maskbit = (byte)ScummHelper.RevBitMask(oldXpos & 7);
                            y++;
                        }
                        width        = (byte)_width;
                        v1.X         = oldXpos;
                        _scaleIndexX = oldScaleIndexX;
                        _scaleIndexY++;
                    }
                } while (--len != 0);
            } while (true);
        }
Exemplo n.º 26
0
        void CheckV2MouseOver(Point pos)
        {
            var vs = VerbVirtScreen;
            Rect rect;
            int i, x, y, new_box = -1;

            // Don't do anything unless the inventory is active
            if (!_userState.HasFlag(UserStates.IFaceInventory))
            {
                _mouseOverBoxV2 = -1;
                return;
            }

            if (_cursor.State > 0)
            {
                for (i = 0; i < _mouseOverBoxesV2.Length; i++)
                {
                    if (_mouseOverBoxesV2[i].rect.Contains(pos.X, pos.Y - vs.TopLine))
                    {
                        new_box = i;
                        break;
                    }
                }
            }

            if ((new_box != _mouseOverBoxV2) || (Game.Version == 0))
            {
                if (_mouseOverBoxV2 != -1)
                {
                    rect = _mouseOverBoxesV2[_mouseOverBoxV2].rect;

                    var dst = new PixelNavigator(vs.Surfaces[0]);
                    dst.GoTo(rect.Left, rect.Top);

                    // Remove highlight.
                    for (y = rect.Height - 1; y >= 0; y--)
                    {
                        for (x = rect.Width - 1; x >= 0; x--)
                        {
                            if (dst.Read() == _mouseOverBoxesV2[_mouseOverBoxV2].hicolor)
                                dst.Write(_mouseOverBoxesV2[_mouseOverBoxV2].color);
                            dst.OffsetX(1);
                        }
                        dst.Offset(-rect.Width, 1);
                    }

                    MarkRectAsDirty(VerbVirtScreen, rect);
                }

                if (new_box != -1)
                {
                    rect = _mouseOverBoxesV2[new_box].rect;

                    var dst = new PixelNavigator(vs.Surfaces[0]);
                    dst.GoTo(rect.Left, rect.Top);

                    // Apply highlight
                    for (y = rect.Height - 1; y >= 0; y--)
                    {
                        for (x = rect.Width - 1; x >= 0; x--)
                        {
                            if (dst.Read() == _mouseOverBoxesV2[new_box].color)
                                dst.Write(_mouseOverBoxesV2[new_box].hicolor);
                            dst.OffsetX(1);
                        }
                        dst.Offset(-rect.Width, 1);
                    }

                    MarkRectAsDirty(VerbVirtScreen, rect);
                }

                _mouseOverBoxV2 = (sbyte)new_box;
            }
        }
Exemplo n.º 27
0
 bool MASK_AT(int xoff, PixelNavigator mask, int destX)
 {
     mask.OffsetX((destX + xoff) / 8);
     return (mask.Read() & ScummHelper.RevBitMask((destX + xoff) & 7)) != 0;
 }