コード例 #1
0
        public void LoadPPMFile(string path)
        {
            FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read);

            byte[] buffer = new byte[BUFFER_SIZE], chunk;

            int bytesToRead = (int)stream.Length;
            int bytesRead   = 0;
            int n;

            LoadedPixelColor unfinishedColor = null;

            cursorX = cursorY = 0;

            n     = stream.Read(buffer, 0, BUFFER_SIZE);
            chunk = initializePPM(buffer);

            try
            {
                if (fileFormat == Format.P3)
                {
                    unfinishedColor = processP3Data(chunk, (P3PixelColor)unfinishedColor);
                }
                else
                {
                    unfinishedColor = processP6Data(chunk, (P6PixelColor)unfinishedColor);
                }
            }
            catch (FinishedException) { }

            do
            {
                bytesRead   += n;
                bytesToRead -= n;

                n = stream.Read(buffer, 0, BUFFER_SIZE);
                if (n == 0)
                {
                    break;
                }

                try
                {
                    if (fileFormat == Format.P3)
                    {
                        unfinishedColor = processP3Data(buffer, (P3PixelColor)unfinishedColor);
                    }
                    else
                    {
                        unfinishedColor = processP6Data(buffer, (P6PixelColor)unfinishedColor);
                    }
                }
                catch (FinishedException) { break; }
            } while (bytesToRead > 0);
            stream.Close();
            CreateImage();
        }
コード例 #2
0
        public void DrawPixel(LoadedPixelColor color)
        {
            Int32Rect rectangle = new Int32Rect(cursorX, cursorY, 1, 1);

            unsafe
            {
                int    colorValue = color.CalculateColor();
                IntPtr backBuffer = outBitmap.BackBuffer;
                backBuffer          += cursorY * outBitmap.BackBufferStride;
                backBuffer          += cursorX * 4;
                *((int *)backBuffer) = colorValue;
            }
            outBitmap.AddDirtyRect(rectangle);
            updateCursor();
        }