Пример #1
0
        public Image ScaleImage(int NewWidth, int NewHeight)
        {
            Pointer temp = GC.AllocateObject((uint)(NewWidth * NewHeight * Bpp));               // HACK - FIX ME! This is not an object. Use new byte[] instead

            int w1 = Width, h1 = Height;
            int x_ratio = ((w1 << 16) / NewWidth) + 1, y_ratio = ((h1 << 16) / NewHeight) + 1, x2, y2;

            for (int i = 0; i < NewHeight; i++)
            {
                for (int j = 0; j < NewWidth; j++)
                {
                    x2 = ((j * x_ratio) >> 16);
                    y2 = ((i * y_ratio) >> 16);
                    temp.Store32((uint)((i * NewWidth) + j), RawData.Load32((uint)((y2 * w1) + x2)));
                }
            }

            Internal.MemoryClear(RawData, Size);                // HACK - FIX ME! MemoryClear is for low level internal use only.

            return(new Image()
            {
                Width = NewWidth,
                Height = NewHeight,
                Bpp = Bpp,
                RawData = temp
            });
        }
Пример #2
0
        public Image(int width, int height, int depth)
        {
            Width  = width;
            Height = height;
            Bpp    = depth / 8;

            Size    = (uint)(width * height * Bpp);
            RawData = GC.AllocateObject(Size);              // HACK - FIX ME! This is not an object. Use new byte[] instead
        }
Пример #3
0
        /// <summary>Initializes a new instance of the <see cref="FrameBuffer16bpp"/> class.</summary>
        /// <param name="buffer">The memory.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="depth">The depth.</param>
        public FrameBuffer16bpp(ConstrainedPointer buffer, uint width, uint height, uint offset, uint bytesPerLine, bool doubleBuffering = true)
        {
            this.firstBuffer     = buffer;
            this.width           = width;
            this.height          = height;
            this.offset          = offset;
            this.bytesPerPixel   = 2;               // = 16 bits per pixel
            this.bytesPerLine    = bytesPerLine;
            this.doubleBuffering = doubleBuffering;

            if (doubleBuffering)
            {
                secondBuffer = new ConstrainedPointer(GC.AllocateObject(buffer.Size), buffer.Size);                  // HACK - FIX ME! This is not an object.
            }
        }
Пример #4
0
            internal unsafe void ScanHook(Object obj)
            {
                UIntPtr page = PageTable.Page(Magic.addressOf(obj));

                if (PageTable.Type(page) != SegregatedFreeList.SMALL_OBJ_PAGE)
                {
                    //VTable.DebugPrint("   not tagging because this isn't a small object page");
                    return;
                }
                SegregatedFreeList.PageHeader *ph =
                    (SegregatedFreeList.PageHeader *)PageTable.PageAddr(page);
                if (!new CoCoPageUserValue(ph->userValue).Marked)
                {
                    //VTable.DebugPrint("   not tagging because the page isn't marked\n");
                    return;
                }
                if (obj is EMU ||
                    obj is Monitor ||
                    obj is Thread ||
                    obj is ThreadHeaderQueue)
                {
                    CoCoBarrier.NotifyPin(Magic.addressOf(obj));
                    if (fVerbose)
                    {
                        VTable.DebugPrint("      $$ not tagging object because it's a monitor or EMU\n");
                    }
                    return;
                }
                if (doingCoCo)
                {
                    //VTable.DebugPrint("   not tagging object because doingCoCo\n");
                    return;
                }
                if (!CoCoBarrier.instance.ObjectIsNotCopied(obj))
                {
                    if (fVerbose)
                    {
                        VTable.DebugPrint("   not tagging object because object is already in the process of being copied.\n");
                    }
                    return;
                }

                if (fVerbose && obj.GetType() != typeof(Object))
                {
                    VTable.DebugPrint("    $$ tagging a non-System.Object; type is ");
                    VTable.DebugPrint(obj.GetType().Name);
                    VTable.DebugPrint("\n");
                }

                // REVIEW: I wish that there was an easier way of
                // doing this.
                Object copy;

                if (obj is Array)
                {
                    Array a = (Array)obj;
                    if (a.IsVector)
                    {
                        copy = GC.AllocateVector(a.vtable, a.Length);
                    }
                    else
                    {
                        copy = GC.AllocateArray(a.vtable, a.Rank, a.Length);
                    }
                }
                else if (obj is String)
                {
                    String s = (String)obj;
                    // REVIEW: this is not nice.
                    copy = GC.AllocateString(s.ArrayLength - 1);
                }
                else
                {
                    copy = GC.AllocateObject(obj.vtable);
                }

                VTable.Assert(ObjectLayout.Sizeof(copy)
                              == ObjectLayout.Sizeof(obj),
                              "Copy is not same size as original");

                spaceOverhead += ObjectLayout.Sizeof(copy);

                bool    first = !CoCoBarrier.instance.AnyTaggedForCopying;
                UIntPtr thisSpaceOverhead;

                if (CoCoBarrier.instance.TagObjectForCopy(obj, copy,
                                                          out thisSpaceOverhead))
                {
                    cnt++;
                    if (first)
                    {
                        lock (interlock) {
                            if (!wantCoCo && !doingCoCo)
                            {
                                wantCoCo = true;
                            }
                        }
                    }
                }

                spaceOverhead += thisSpaceOverhead;
            }
Пример #5
0
        public Bitmap(byte[] data)
        {
            Pointer ptr = Intrinsic.GetObjectAddress(data);               // HACK - FIX ME! Unsafe. GetObjectAddress method is only for low level internal use.

            Header           = new BitmapHeader();
            Header.Signature = new char[2] {
                Encoding.ASCII.GetChar(ptr.Load8(0)), Encoding.ASCII.GetChar(ptr.Load8(1))
            };
            Header.Size = ptr.Load32(2);
            Header.DataSectionOffset = ptr.Load32(0xA);
            Header.Width             = ptr.Load32(0x12);
            Header.Height            = ptr.Load32(0x16);
            Header.Depth             = ptr.Load8(0x1C);

            if (Header.Signature != Signature)
            {
                throw new Exception("Given image is not a bitmap (signature recognization failed)");
            }

            Width  = (int)Header.Width;
            Height = (int)Header.Height;
            Bpp    = (int)Header.Depth / 8;

            Size    = (uint)(Width * Height * Bpp);
            RawData = GC.AllocateObject(Size);                          // HACK - FIX ME! This is not an object. Use new byte[] instead

            uint    len = (uint)Width;
            Pointer temp = GC.AllocateObject(len);                      // HACK - FIX ME! This is not an object. Use new byte[] instead
            uint    w = 0, h = (uint)Height - 1;

            for (uint i = 0; i < Size; i += (uint)Bpp)
            {
                if (w == Width)
                {
                    switch (Bpp)
                    {
                    case 1:                             // 8 bit
                        for (uint k = 0; k < len; k++)
                        {
                            RawData.Store8((uint)Width * h + k, temp.Load8(k));
                        }
                        break;

                    case 2:                             // 16 bit
                        for (uint k = 0; k < len; k++)
                        {
                            RawData.Store16((uint)Width * h + k, temp.Load16(k));
                        }
                        break;

                    case 3:                             // 24 bit
                        for (uint k = 0; k < len; k++)
                        {
                            RawData.Store24((uint)Width * h + k, temp.Load24(k));
                        }
                        break;

                    case 4:                             // 32 bit
                        for (uint k = 0; k < len; k++)
                        {
                            RawData.Store32((uint)Width * h + k, temp.Load32(k));
                        }
                        break;
                    }

                    w = 0;
                    h--;
                }

                uint offset = Header.DataSectionOffset + i;
                switch (Bpp)
                {
                case 1:                         // 8 bit
                    temp.Store8(w, ptr.Load8(offset));
                    break;

                case 2:                         // 16 bit
                    temp.Store16(w, ptr.Load16(offset));
                    break;

                case 3:                         // 24 bit
                    temp.Store24(w, ptr.Load24(offset));
                    break;

                case 4:                         // 32 bit
                    temp.Store32(w, ptr.Load32(offset));
                    break;
                }

                w++;
            }

            Internal.MemoryClear(temp, len);                // HACK - FIX ME! MemoryClear is for low level internal use only.

            return;
        }