Пример #1
0
        private static ColorRGB[,] convertirMatriz32(List <UInt64> red, List <UInt64> green, List <UInt64> blue, int n)
        {
            ColorRGB[,] matriz = new ColorRGB[n, n];
            int count = 0;

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    matriz[i, j] = new ColorRGB((UInt32)red[count], (UInt32)green[count], (UInt32)blue[count]);
                    count++;
                }
            }
            return(matriz);
        }
        private static ColorRGB[,] GetValuesWithLockBits16(Bitmap bitmap)
        {
            ColorRGB[,] rgb = new ColorRGB[bitmap.Height, bitmap.Width];
            BitmapData bitmapData = bitmap.LockBits(bitmap.Size.ToRect(), ImageLockMode.ReadOnly, bitmap.PixelFormat);

            try
            {
                unsafe
                {
                    byte *ppixelRow = (byte *)bitmapData.Scan0;

                    for (int y = 0; y < bitmap.Height; y++)
                    {
                        byte *ppixelData = (byte *)ppixelRow;


                        for (int x = 0; x < bitmap.Width; x++)
                        {
                            // components are stored in BGR order, i.e. red component last
                            ColorRGB color = new ColorRGB();

                            color.Red   = ppixelData[2];
                            color.Green = ppixelData[1];
                            color.Blue  = ppixelData[0];
                            rgb[y, x]   = color;

                            ppixelData += 1;
                        }

                        ppixelRow += bitmapData.Stride;
                    }
                }

                return(rgb);
            }
            finally
            {
                bitmap.UnlockBits(bitmapData);
            }
        }
Пример #3
0
        static void version5(String ubicacion, PixelFormat depth, int size, int prof)
        {
            Bitmap original = new Bitmap(ubicacion);

            Bitmap a = (Bitmap)original.Clone(new Rectangle(0, 0, original.Width, original.Height), depth);

            original.Dispose();

            ColorRGB[,] c = new ColorRGB[size, size];
            //Stopwatch
            long      tiempo = 0;
            Stopwatch timeA  = new Stopwatch();

            List <UInt64> red   = GetRedValuesWithLockBits(a);
            List <UInt64> green = GetGreenValuesWithLockBits(a);
            List <UInt64> blue  = GetBlueValuesWithLockBits(a);
            ushort        n8    = 0;
            UInt32        n     = 0;

            if (prof == 16)
            {
                n8 = 65535;
                c  = convertirMatrizShort(red, green, blue, size);
            }
            if (prof == 24)
            {
                n = 16777215;
                c = convertirMatriz32(red, green, blue, size);
            }
            if (prof == 32)
            {
                n = 4294967295;
                c = convertirMatriz32(red, green, blue, size);
            }
            if (prof == 16)
            {
                timeA.Restart();
                timeA.Start();
                for (int i = 0; i < a.Height - 1; i += 2)
                {
                    for (int j = 0; j < a.Width - 1; j += 2)
                    {
                        c[i, j].Red8   = (ushort)(n8 - c[i, j].Red8);
                        c[i, j].Green8 = (ushort)(n8 - c[i, j].Green8);
                        c[i, j].Blue8  = (ushort)(n8 - c[i, j].Blue8);

                        c[i, j + 1].Red8   = (ushort)(n8 - c[i, j + 1].Red8);
                        c[i, j + 1].Green8 = (ushort)(n8 - c[i, j + 1].Green8);
                        c[i, j + 1].Blue8  = (ushort)(n8 - c[i, j + 1].Blue8);

                        c[i + 1, j].Red8   = (ushort)(n8 - c[i + 1, j].Red8);
                        c[i + 1, j].Green8 = (ushort)(n8 - c[i + 1, j].Green8);
                        c[i + 1, j].Blue8  = (ushort)(n8 - c[i + 1, j].Blue8);

                        c[i + 1, j + 1].Red8   = (ushort)(n8 - c[i + 1, j + 1].Red8);
                        c[i + 1, j + 1].Green8 = (ushort)(n8 - c[i + 1, j + 1].Green8);
                        c[i + 1, j + 1].Blue8  = (ushort)(n8 - c[i + 1, j + 1].Blue8);
                    }
                }
                timeA.Stop();
            }
            else
            {
                timeA.Restart();
                timeA.Start();
                for (int i = 0; i < a.Height - 1; i += 2)
                {
                    for (int j = 0; j < a.Width - 1; j += 2)
                    {
                        c[i, j].Red   = (UInt32)(n - c[i, j].Red);
                        c[i, j].Green = (UInt32)(n - c[i, j].Green);
                        c[i, j].Blue  = (UInt32)(n - c[i, j].Blue);

                        c[i, j + 1].Red   = (UInt32)(n - c[i, j + 1].Red);
                        c[i, j + 1].Green = (UInt32)(n - c[i, j + 1].Green);
                        c[i, j + 1].Blue  = (UInt32)(n - c[i, j + 1].Blue);

                        c[i + 1, j].Red   = (UInt32)(n - c[i + 1, j].Red);
                        c[i + 1, j].Green = (UInt32)(n - c[i + 1, j].Green);
                        c[i + 1, j].Blue  = (UInt32)(n - c[i + 1, j].Blue);

                        c[i + 1, j + 1].Red   = (UInt32)(n - c[i + 1, j + 1].Red);
                        c[i + 1, j + 1].Green = (UInt32)(n - c[i + 1, j + 1].Green);
                        c[i + 1, j + 1].Blue  = (UInt32)(n - c[i + 1, j + 1].Blue);
                    }
                }
                timeA.Stop();
            }


            tiempo = (long)(timeA.Elapsed.TotalMilliseconds * 1000000); //*1000000 ns; *1000 us
            Console.WriteLine("Version 5: " + tiempo);
            //sw.WriteLine("Version 5; " + a.Height + "x" + a.Width + "; " + tiempo);
            //sw.Close();
            //a.Save("./inv/version5/" + depth + "/" + size + ".bmp");
        }
Пример #4
0
        static void version1(String ubicacion, PixelFormat depth, int size, int prof)
        {
            //StreamWriter sw = new StreamWriter(@"C:\Users\juanm\OneDrive\Documentos\ICESI\7mo\Arquitectura de Computadores\Proyecto\time\Tiempo1.txt");
            Bitmap original = new Bitmap(ubicacion);

            Bitmap a = (Bitmap)original.Clone(new Rectangle(0, 0, original.Width, original.Height), depth);

            original.Dispose();

            ColorRGB[,] c = new ColorRGB[size, size];
            //Stopwatch
            long      tiempo = 0;
            Stopwatch timeA  = new Stopwatch();

            List <UInt64> red   = GetRedValuesWithLockBits(a);
            List <UInt64> green = GetGreenValuesWithLockBits(a);
            List <UInt64> blue  = GetBlueValuesWithLockBits(a);
            ushort        n8    = 0;
            UInt32        n     = 0;

            if (prof == 16)
            {
                n8 = 65535;
                c  = convertirMatrizShort(red, green, blue, size);
            }
            if (prof == 24)
            {
                n = 16777215;
                c = convertirMatriz32(red, green, blue, size);
            }
            if (prof == 32)
            {
                n = 4294967295;
                c = convertirMatriz32(red, green, blue, size);
            }
            if (prof == 16)
            {
                timeA.Restart();
                timeA.Start();
                for (int i = 0; i < a.Height; i++)
                {
                    for (int j = 0; j < a.Width; j++)
                    {
                        Console.WriteLine(c[i, j].Red8 + " " + c[i, j].Green8 + " " + c[i, j].Blue8);
                        c[i, j].Red8   = (ushort)(n8 - c[i, j].Red8);
                        c[i, j].Green8 = (ushort)(n8 - c[i, j].Green8);
                        c[i, j].Blue8  = (ushort)(n8 - c[i, j].Blue8);
                        Console.WriteLine(c[i, j].Red8 + " " + c[i, j].Green8 + " " + c[i, j].Blue8);
                    }
                }
                timeA.Stop();
            }
            else
            {
                timeA.Restart();
                timeA.Start();
                for (int i = 0; i < a.Height; i++)
                {
                    for (int j = 0; j < a.Width; j++)
                    {
                        c[i, j].Red   = (UInt32)(n - c[i, j].Red);//Eso no se guarda
                        c[i, j].Green = (UInt32)(n - c[i, j].Green);
                        c[i, j].Blue  = (UInt32)(n - c[i, j].Blue);
                    }
                }
                timeA.Stop();
            }


            tiempo = (long)(timeA.Elapsed.TotalMilliseconds * 1000000); //*1000000 ns; *1000 us
            Console.WriteLine("Version 1: " + tiempo);

            //a.Save("./inv/version1/" + prof + "/" + size + ".bmp");
        }