Ejemplo n.º 1
0
        private static void RandomSwitch(byte[] pixelValues, int imageWidth, int imageHeight, int level)
        {
            int index = 0;

            for (int i = 0; i < imageHeight; i++)
            {
                for (int j = 0; j < imageWidth; j++)
                {
                    int yoff = i + MathTool.GetRandom(level * 3);
                    if (yoff >= imageHeight)
                    {
                        yoff = imageHeight - 1;
                    }
                    int xoff = j + MathTool.GetRandom(level * 3);
                    if (xoff >= imageWidth)
                    {
                        xoff = imageWidth - 1;
                    }
                    int tindex = (yoff * imageWidth + xoff) * 4;

                    pixelValues[index] = pixelValues[tindex];
                    index++;
                    pixelValues[index] = pixelValues[tindex + 1];
                    index++;
                    pixelValues[index] = pixelValues[tindex + 2];
                    index++;
                    pixelValues[index] = pixelValues[tindex + 3];
                    index++; //A
                }
            }
        }
Ejemplo n.º 2
0
 private static void RandomColumnMove(byte[] pixelValues, int imageWidth, int imageHeight, int level)
 {
     for (int i = 0; i < imageWidth; i++)
     {
         int direct = MathTool.GetRandom(2);
         int len    = MathTool.GetRandom(level * 3);
         if (direct == 0)
         {
             for (int j = imageHeight - 1; j >= 0; j--)
             {
                 int yoff = j - len;
                 if (yoff < 0)
                 {
                     yoff = 0;
                 }
                 int index  = (j * imageWidth + i) * 4;
                 int tindex = (yoff * imageWidth + i) * 4;
                 pixelValues[index]     = pixelValues[tindex];
                 pixelValues[index + 1] = pixelValues[tindex + 1];
                 pixelValues[index + 2] = pixelValues[tindex + 2];
                 pixelValues[index + 3] = pixelValues[tindex + 3];
             }
         }
         else
         {
             for (int j = 0; j < imageHeight; j++)
             {
                 int yoff = j + len;
                 if (yoff >= imageHeight)
                 {
                     yoff = imageHeight - 1;
                 }
                 int index  = (j * imageWidth + i) * 4;
                 int tindex = (yoff * imageWidth + i) * 4;
                 pixelValues[index]     = pixelValues[tindex];
                 pixelValues[index + 1] = pixelValues[tindex + 1];
                 pixelValues[index + 2] = pixelValues[tindex + 2];
                 pixelValues[index + 3] = pixelValues[tindex + 3];
             }
         }
     }
 }
Ejemplo n.º 3
0
 private static void RandomRowMove(byte[] pixelValues, int imageWidth, int imageHeight, int level)
 {
     for (int i = 0; i < imageHeight; i++)
     {
         int direct = MathTool.GetRandom(2);
         int len    = MathTool.GetRandom(level * 3);
         if (direct == 0) //右移
         {
             for (int j = imageWidth - 1; j >= 0; j--)
             {
                 int xoff = j - len;
                 if (xoff < 0)
                 {
                     xoff = 0;
                 }
                 int index  = (i * imageWidth + j) * 4;
                 int tindex = (i * imageWidth + xoff) * 4;
                 pixelValues[index]     = pixelValues[tindex];
                 pixelValues[index + 1] = pixelValues[tindex + 1];
                 pixelValues[index + 2] = pixelValues[tindex + 2];
                 pixelValues[index + 3] = pixelValues[tindex + 3];
             }
         }
         else
         {
             for (int j = 0; j < imageWidth; j++)
             {
                 int xoff = j + len;
                 if (xoff >= imageWidth)
                 {
                     xoff = imageWidth - 1;
                 }
                 int index  = (i * imageWidth + j) * 4;
                 int tindex = (i * imageWidth + xoff) * 4;
                 pixelValues[index]     = pixelValues[tindex];
                 pixelValues[index + 1] = pixelValues[tindex + 1];
                 pixelValues[index + 2] = pixelValues[tindex + 2];
                 pixelValues[index + 3] = pixelValues[tindex + 3];
             }
         }
     }
 }
Ejemplo n.º 4
0
        private static void RandomPoint(byte[] pixelValues, int imageWidth, int imageHeight, int level)
        {
            int index = 0;

            for (int i = 0; i < imageHeight; i++)
            {
                for (int j = 0; j < imageWidth; j++)
                {
                    if (MathTool.GetRandom(100) > level * 10)
                    {
                        index += 4;
                        continue;
                    }
                    int pv = MathTool.GetRandom(255);
                    pixelValues[index] = (byte)pv; //B
                    index++;
                    pixelValues[index] = (byte)pv; //G
                    index++;
                    pixelValues[index] = (byte)pv; //R
                    index++;
                    index++;                       //A
                }
            }
        }