Beispiel #1
0
        public MappedPoint MapPoint(int x, int y, double val)
        {
            int mappedX;
            double orgX;
            double orgY;
            int mappedY;
            double mappedVal;
            if (!reverse)
            {
                orgX = (a * x + k);
                orgY = (d * y + l);
                mappedX = (int)(orgX);
                mappedY = (int)(orgY);

                mappedVal = (int)(e * x + g * y + h * x * y + s * val + m);
            }
            else
            {
                orgX = (x * (1 / a) - k);
                orgY = (y * (1 / d) - l);
                mappedX = (int)orgX;
                mappedY = (int)orgY;
                mappedVal = (int)(val - (e * x + g * y + h * x * y + m)) / s;
            }
              //  Console.Out.WriteLine(x + " " + y +" "+ val+"--->" + mappedX + " " + mappedY+" "+mappedVal);
            MappedPoint mapPoint = new MappedPoint(mappedX, mappedY, mappedVal);
            mapPoint.OriginalX = orgX;
            mapPoint.OriginalY = orgY;
            return mapPoint;
        }
 public Bitmap DecompressImage(out Bitmap bitmapWithGrid)
 {
     int steps = (int)Math.Truncate(Math.Log(smallDelta, 2) / Math.Log(a, 2));
     Bitmap bit = new Bitmap(width, height,
         System.Drawing.Imaging.PixelFormat.Format32bppArgb);
     foreach (MappedPoint p in interpolationPoints)
     {
         bit.SetPixel(p.X, p.Y,
                 Color.FromArgb((int)p.Val,
                 (int)p.Val,
                 (int)p.Val));
         interPixel++;
     }
     for (int t = 0; t < steps; t++)
     {
         for (int i = 0; i < Math.Min(steps, dMax); i++)
         {
             for (int j = 0; j < this.interpolationPoints.Count; j += 4)
             {
                 int coresspondingDomain = addresses[j / 4];
                 if (coresspondingDomain != -1)
                 {
                     double contractivityFactor = contractivityFactors[j / 4];
                     //contractivityFactor = 0;
                     MyDomain md = FindDomainByAddress(coresspondingDomain);
                     Mapper mapper = new Mapper(contractivityFactor,
                         md.Domain.Vertices[1], interpolationPoints[j + 1],
                         this.smallDelta, this.bigDelta,
                          md.Vals[0], md.Vals[1], md.Vals[2], md.Vals[3],
                         (int)interpolationPoints[j].Val,
                          (int)interpolationPoints[j + 1].Val,
                         (int)interpolationPoints[j + 2].Val,
                         (int)interpolationPoints[j + 3].Val,
                          false);
                     Point[] prevPoint = md.Domain.Vertices;
                     int[] prevVal = md.Vals;
                     for (int k = 0; k < md.Domain.Size * md.Domain.Size; k++)
                     {
                         MappedPoint[] newPoint = new MappedPoint[prevPoint.Length];
                         for (int pp = 1; pp <= 1; pp++)
                         {
                             newPoint[pp] = mapper.MapPoint(prevPoint[pp].X,
                                  prevPoint[pp].Y, (double)prevVal[pp]);
                             Structure.Region tempRegion = FindRegion(newPoint[pp]);
                             if (tempAdd != -1 && tempS != -1)
                             {
                                 md = FindDomainByAddress(tempAdd);
                                 mapper = new Mapper(tempS, md.Domain.Vertices[1], tempRegion.Vertices[1],
                                      this.smallDelta, this.bigDelta,
                                      md.Vals[0], md.Vals[1], md.Vals[2], md.Vals[3],
                                     (int)tempRegion[0, tempRegion.Size],
                                     (int)tempRegion[0, 0],
                                     (int)tempRegion[tempRegion.Size, 0],
                                     (int)tempRegion[tempRegion.Size, tempRegion.Size],
                                     true);
                                 Console.Out.WriteLine(md.Domain.Vertices[1].X + " " + md.Domain.Vertices[1].Y
                                 + " " + md.Domain.Vertices[2].X + " " + md.Domain.Vertices[2].Y
                                 + " " + md.Domain.Vertices[3].X + " " + md.Domain.Vertices[3].Y
                                 + " " + md.Domain.Vertices[0].X + " " + md.Domain.Vertices[0].Y);
                             }
                             SafePutPixel(newPoint[pp].X, newPoint[pp].Y, (int)newPoint[pp].Val
                                          , bit);
                             prevPoint[pp] = newPoint[pp];
                             prevVal[pp] = (int)newPoint[pp].Val;
                         }
                     }
                 }
             }
         }
     }
     Console.Out.WriteLine(goodPixel + " " + badPixel);
     bitmapWithGrid = (Bitmap)bit.Clone();
     for (int i = 0; i < interpolationPoints.Count; i += 4)
     {
         for (int k = interpolationPoints[i + 1].Y; k < interpolationPoints[i].Y; k++)
         {
             bitmapWithGrid.SetPixel(interpolationPoints[i + 1].X, k, Color.Red);
             bitmapWithGrid.SetPixel(interpolationPoints[i + 2].X, k, Color.Red);
         }
         for (int k = interpolationPoints[i + 1].X; k < interpolationPoints[i + 2].X; k++)
         {
             bitmapWithGrid.SetPixel(k, interpolationPoints[i + 1].Y, Color.Red);
             bitmapWithGrid.SetPixel(k, interpolationPoints[i].Y, Color.Red);
         }
     }
     return bit;
 }
 private Structure.Region FindRegion(MappedPoint point)
 {
     for (int i = 0; i < interpolationPoints.Count; i += 4)
     {
         if (point.X >= interpolationPoints[i].X && point.X <= interpolationPoints[i + 2].X &&
             point.Y >= interpolationPoints[i + 1].Y && point.Y <= interpolationPoints[i].Y)
         {
             this.tempAdd = addresses[i / 4];
             this.tempS = contractivityFactors[i / 4];
             MappedPoint[] points = new MappedPoint[]{ interpolationPoints[i],
                 interpolationPoints[i+1],interpolationPoints[i+2], interpolationPoints[i+3]};
             Structure.Region region = new FractalCompression.Structure.Region(points);
             region[0, region.Size] = interpolationPoints[0].Val;
             region[0, 0] = interpolationPoints[1].Val;
             region[region.Size, 0] = interpolationPoints[2].Val;
             region[region.Size, region.Size] = interpolationPoints[3].Val;
             return region;
         }
     }
     tempS = -1;
     tempAdd = -1;
     return null;
 }
 private MappedPoint[] ConvertMappedPoint(MappedPoint mapPoint)
 {
     MappedPoint[] mappedPoints = new MappedPoint[4];
     mappedPoints[0] = new MappedPoint((int)mapPoint.X, (int)mapPoint.Y, mapPoint.Val);
     mappedPoints[1] = new MappedPoint((int)mapPoint.X + 1, (int)mapPoint.Y, mapPoint.Val);
     mappedPoints[2] = new MappedPoint((int)mapPoint.X, (int)mapPoint.Y + 1, mapPoint.Val);
     mappedPoints[3] = new MappedPoint((int)mapPoint.X + 1, (int)mapPoint.Y + 1, mapPoint.Val);
     return mappedPoints;
 }
Beispiel #5
0
        // a - regionsInDomainRow
        private static FractalCompression.Structure.Region[,] PrepareRegions(Bitmap bitmap, int bigDelta, int a, out FractalCompression.Structure.Region[,] regions, out List<MappedPoint> interpolPoints)
        {
            int smallDelta = bigDelta / a;
            int regionsInColumn = bitmap.Height / smallDelta;
            int domainsInRow = bitmap.Width / bigDelta;
            int regionsInRow = domainsInRow * a;

            regions = new FractalCompression.Structure.Region[regionsInColumn, regionsInRow];
            interpolPoints = new List<MappedPoint>();

            int eastX, northY = 0;
            MappedPoint[] mp = new MappedPoint[4];
            for (int i = 0; i < regionsInColumn; ++i)
            {
                eastX = 0;
                for (int j = 0; j < regionsInRow; ++j)
                {
                    mp[0] = CreateMappedPoint(bitmap, eastX, northY + smallDelta - 1);
                    mp[1] = CreateMappedPoint(bitmap, eastX, northY);
                    mp[2] = CreateMappedPoint(bitmap, eastX + smallDelta - 1, northY);
                    mp[3] = CreateMappedPoint(bitmap, eastX + smallDelta - 1, northY + smallDelta - 1);
                    for (int k = 0; k < mp.Length; ++k)
                        interpolPoints.Add(mp[k]);

                    /*interpolPoints.Add(mp[1]);
                    if (j == regionsInRow - 1)
                        interpolPoints.Add(mp[2]);
                    if (i == regionsInColumn - 1)
                    {
                        interpolPoints.Add(mp[0]);
                        if (j == regionsInRow - 1)
                            interpolPoints.Add(mp[3]);
                    }*/

                    regions[i, j] = new FractalCompression.Structure.Region(mp);
                    eastX += smallDelta;
                }
                northY += smallDelta;
            }

            Console.WriteLine(interpolPoints.Count +" interpolation points prepared");
            return regions;
        }
Beispiel #6
0
        private static MappedPoint CreateMappedPoint(Bitmap bitmap, int x, int y)
        {
            double val;
            if (x == bitmap.Width)
                x = bitmap.Width - 1;
            if (y == bitmap.Height)
                y = bitmap.Height - 1;

            val = MNTools.GetBitmapValue(x, y, bitmap);
            MappedPoint mp = new MappedPoint(x, y, val);
            return mp;
        }