Exemplo n.º 1
0
        private ColorChannel ReduceChannel(ColorChannel channel, int factor)
        {
            int          reducedHeight = channel.GetHeight() / factor;
            int          reducedWidth  = channel.GetWidth() / factor;
            ColorChannel result        = new ColorChannel(reducedWidth, reducedHeight);

            for (int y = 0; y < reducedHeight; y++)
            {
                for (int x = 0; x < reducedWidth; x++)
                {
                    int sum = 0;
                    for (int blockY = y * factor; blockY < y * factor + factor; blockY++)
                    {
                        for (int blockX = x * factor; blockX < x * factor + factor; blockX++)
                        {
                            sum += (int)channel.GetPixel(blockX, blockY);
                        }
                    }

                    result.SetPixel(x, y, (int)Math.Round(sum / (double)(factor * factor)));
                }
            }

            return(result);
        }
Exemplo n.º 2
0
 private void FillPicture()
 {
     for (int y = 0; y < _picture.GetHeight(); y++)
     {
         for (int x = 0; x < _picture.GetWidth(); x++)
         {
             int value;
             value = (x + y * 8) % 256;
             _picture.SetPixel(x, y, value);
         }
     }
 }
Exemplo n.º 3
0
 private RGBImageBuilder(ColorChannel red)
 {
     _imageWidth  = red.GetWidth();
     _imageHeight = red.GetHeight();
     _red         = new ColorChannel(GetRealWidth(), GetRealHeight());
     _green       = new ColorChannel(GetRealWidth(), GetRealHeight());
     _blue        = new ColorChannel(GetRealWidth(), GetRealHeight());
     for (int i = 0; i < red.GetHeight(); i++)
     {
         for (int j = 0; j < red.GetWidth(); j++)
         {
             _red.SetPixel(j, i, red.GetPixel(j, i));
             _green.SetPixel(j, i, red.GetPixel(j, i));
             _blue.SetPixel(j, i, red.GetPixel(j, i));
         }
     }
 }
Exemplo n.º 4
0
            private RGBImageBuilder(Stream inputStream)
            {
                Stopwatch stopwatch = Stopwatch.StartNew();

                BinaryReader binReader = new BinaryReader(inputStream);

                try
                {
                    ExtractMetaInformation(binReader);
                    InitPicture();
                    int x = 0;
                    int y = 0;

                    Console.WriteLine("Finished reading PPM-Header in "
                                      + (stopwatch.ElapsedMilliseconds / 1000d
                                         + " seconds"));
                    stopwatch.Restart();

                    while (binReader.PeekChar() >= 0)
                    {
                        _red.SetPixel(x, y, ReadValue(binReader));
                        _green.SetPixel(x, y, ReadValue(binReader));
                        _blue.SetPixel(x, y, ReadValue(binReader));
                        x++;
                        if (x % _imageWidth != 0)
                        {
                            continue;
                        }
                        x = 0;
                        y++;
                    }
                }
                catch (IOException e)
                {
                    Console.WriteLine(e);
                }


                Console.WriteLine("Finished reading PPM-Body in "
                                  + (stopwatch.ElapsedMilliseconds / 1000d
                                     + " seconds"));
                stopwatch.Stop();
            }