Ejemplo n.º 1
0
        /// <include file='doc\BufferedGraphicsContext.uex' path='docs/doc[@for="BufferedGraphicsContext.bFillColorTable"]/*' />
        /// <devdoc>
        // bFillColorTable
        //
        // Initialize the color table of the BITMAPINFO pointed to by pbmi.  Colors
        // are set to the current system palette.
        //
        // Note: call only valid for displays of 8bpp or less.
        //
        // Returns:
        //   TRUE if successful, FALSE otherwise.
        //
        // History:
        //  23-Jan-1996 -by- Gilman Wong [Microsoft]
        // Wrote it.
        //
        //  15-Nov-2000 -by- Chris Anderson [Microsoft]
        // Ported it to C#
        //
        /// </devdoc>
        private unsafe bool bFillColorTable(IntPtr hdc, IntPtr hpal, ref NativeMethods.BITMAPINFO_FLAT pbmi)
        {
            bool bRet = false;

            byte[] aj = new byte[sizeof(NativeMethods.PALETTEENTRY) * 256];
            int    i, cColors;

            fixed(byte *pcolors = pbmi.bmiColors)
            {
                fixed(byte *ppal = aj)
                {
                    NativeMethods.RGBQUAD *     prgb = (NativeMethods.RGBQUAD *)pcolors;
                    NativeMethods.PALETTEENTRY *lppe = (NativeMethods.PALETTEENTRY *)ppal;

                    cColors = 1 << pbmi.bmiHeader_biBitCount;
                    if (cColors <= 256)
                    {
                        Debug.WriteLineIf(DoubleBuffering.TraceVerbose, "8 bit or less...");

                        // NOTE : Didn't port "MyGetPaletteEntries" as it is only
                        //      : for 4bpp displays, which we don't work on anyway.
                        uint   palRet;
                        IntPtr palHalftone = IntPtr.Zero;
                        if (hpal == IntPtr.Zero)
                        {
                            Debug.WriteLineIf(DoubleBuffering.TraceVerbose, "using halftone palette...");
                            palHalftone = Graphics.GetHalftonePalette();
                            palRet      = SafeNativeMethods.GetPaletteEntries(new HandleRef(null, palHalftone), 0, cColors, aj);
                        }
                        else
                        {
                            Debug.WriteLineIf(DoubleBuffering.TraceVerbose, "using custom palette...");
                            palRet = SafeNativeMethods.GetPaletteEntries(new HandleRef(null, hpal), 0, cColors, aj);
                        }
                        if (palRet != 0)
                        {
                            for (i = 0; i < cColors; i++)
                            {
                                prgb[i].rgbRed      = lppe[i].peRed;
                                prgb[i].rgbGreen    = lppe[i].peGreen;
                                prgb[i].rgbBlue     = lppe[i].peBlue;
                                prgb[i].rgbReserved = 0;
                            }
                            bRet = true;
                        }
                        else
                        {
                            Debug.WriteLineIf(DoubleBuffering.TraceWarning, "bFillColorTable: MyGetSystemPaletteEntries failed\n");
                        }
                    }
                }
            }

            return(bRet);
        }
        /// <summary>
        /// Initialize the color table of the BITMAPINFO pointed to by pbmi. Colors
        /// are set to the current system palette.
        ///
        /// Note: call only valid for displays of 8bpp or less.
        /// </summary>
        /// <returns>True is successful, false otherwise.</returns>
        private unsafe bool FillColorTable(IntPtr hdc, IntPtr hpal, ref NativeMethods.BITMAPINFO_FLAT pbmi)
        {
            byte[] aj = new byte[sizeof(NativeMethods.PALETTEENTRY) * 256];

            fixed(byte *pcolors = pbmi.bmiColors)
            {
                fixed(byte *ppal = aj)
                {
                    NativeMethods.RGBQUAD *     prgb = (NativeMethods.RGBQUAD *)pcolors;
                    NativeMethods.PALETTEENTRY *lppe = (NativeMethods.PALETTEENTRY *)ppal;

                    int cColors = 1 << pbmi.bmiHeader_biBitCount;

                    if (cColors <= 256)
                    {
                        // Note: we don't support 4bpp displays.
                        uint   palRet;
                        IntPtr palHalftone = IntPtr.Zero;
                        if (hpal == IntPtr.Zero)
                        {
                            palHalftone = Graphics.GetHalftonePalette();
                            palRet      = SafeNativeMethods.GetPaletteEntries(new HandleRef(null, palHalftone), 0, cColors, aj);
                        }
                        else
                        {
                            palRet = SafeNativeMethods.GetPaletteEntries(new HandleRef(null, hpal), 0, cColors, aj);
                        }

                        if (palRet != 0)
                        {
                            for (int i = 0; i < cColors; i++)
                            {
                                prgb[i].rgbRed      = lppe[i].peRed;
                                prgb[i].rgbGreen    = lppe[i].peGreen;
                                prgb[i].rgbBlue     = lppe[i].peBlue;
                                prgb[i].rgbReserved = 0;
                            }

                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
        private unsafe bool bFillColorTable(IntPtr hdc, IntPtr hpal, ref System.Drawing.NativeMethods.BITMAPINFO_FLAT pbmi)
        {
            bool flag = false;

            byte[] lppe = new byte[sizeof(System.Drawing.NativeMethods.PALETTEENTRY) * 0x100];
            fixed(byte *numRef = pbmi.bmiColors)
            {
                fixed(byte *numRef2 = lppe)
                {
                    System.Drawing.NativeMethods.RGBQUAD *     rgbquadPtr      = (System.Drawing.NativeMethods.RGBQUAD *)numRef;
                    System.Drawing.NativeMethods.PALETTEENTRY *paletteentryPtr = (System.Drawing.NativeMethods.PALETTEENTRY *)numRef2;
                    int nEntries = ((int)1) << pbmi.bmiHeader_biBitCount;

                    if (nEntries <= 0x100)
                    {
                        uint   num3;
                        IntPtr zero = IntPtr.Zero;
                        if (hpal == IntPtr.Zero)
                        {
                            zero = Graphics.GetHalftonePalette();
                            num3 = SafeNativeMethods.GetPaletteEntries(new HandleRef(null, zero), 0, nEntries, lppe);
                        }
                        else
                        {
                            num3 = SafeNativeMethods.GetPaletteEntries(new HandleRef(null, hpal), 0, nEntries, lppe);
                        }
                        if (num3 != 0)
                        {
                            for (int i = 0; i < nEntries; i++)
                            {
                                rgbquadPtr[i].rgbRed      = paletteentryPtr[i].peRed;
                                rgbquadPtr[i].rgbGreen    = paletteentryPtr[i].peGreen;
                                rgbquadPtr[i].rgbBlue     = paletteentryPtr[i].peBlue;
                                rgbquadPtr[i].rgbReserved = 0;
                            }
                            flag = true;
                        }
                    }
                }
            }

            return(flag);
        }