Example #1
0
        public ByteImage ReplicationScale(int newWidth, int newHeight)
        {
            ScaleInfo si = new ScaleInfo(width, height, newWidth, newHeight);

            byte?[][] newImage = Distribute(si);
            if (si.IsZooming)
            {
                byte?curr = null;
                int  rWidth = newImage.Length;
                int  rHeight = newImage[0].Length;
                int  i = 0, j = 0;
                for (j = 0; j < rHeight; j++)
                {
                    curr = null;
                    for (i = 0; i < rWidth; i++)
                    {
                        if (newImage[i][j] != null)
                        {
                            //set that as the new color
                            curr = newImage[i][j];
                        }
                        else
                        {
                            newImage[i][j] = curr;
                        }
                    }
                }
                for (i = 0; i < rWidth; i++)
                {
                    curr = null;
                    for (j = 0; j < rHeight; j++)
                    {
                        if (newImage[i][j] != null)
                        {
                            //set that as the new color
                            curr = newImage[i][j];
                        }
                        else
                        {
                            newImage[i][j] = curr;
                        }
                    }
                }
                return(new ByteImage(Convert(newImage)));
            }
            else if (si.IsShrinking)
            {
                return(new ByteImage(Convert(newImage)));
            }
            else
            {
                return(this);
            }
        }
Example #2
0
        ///<summary>
        /// Creates a new image that is of a new resolution.
        /// If the resolution is smaller than the current resolution
        /// then shrink the image
        ///<summary/>
        public byte?[][] Distribute(ScaleInfo si)
        {
            float wFac = si.WidthScalingFactor;
            float hFac = si.HeightScalingFactor;

            byte?[][] result = new byte?[si.ResultWidth][];
            for (int i = 0; i < si.ResultWidth; i++)
            {
                result[i] = new byte?[si.ResultHeight];
            }
            if (si.IsZooming)
            {
                Console.WriteLine("Scaling Up!");
                float iFactor = 0.0f;
                for (int i = 0; i < width; i++)
                {
                    float jFactor = 0.0f;
                    for (int j = 0; j < height; j++)
                    {
                        result[(int)Math.Round(iFactor)][(int)Math.Round(jFactor)] = image[i][j];
                        jFactor += hFac;
                    }
                    iFactor += wFac;
                }
                return(result);
            }
            if (si.IsShrinking)
            {
                for (int i = 0; i < si.ResultWidth; i++)
                {
                    for (int j = 0; j < si.ResultHeight; j++)
                    {
                        //overlay...its an interesting idea
                        int r1 = Math.Min(width - 1,
                                          Math.Max(0, (int)Math.Floor(i / wFac)));
                        int r2 = Math.Min(height - 1,
                                          Math.Max(0, (int)Math.Floor(j / hFac)));
                        result[i][j] = image[r1][r2];
                    }
                }
                return(result);
            }
            else
            {
                return(Convert(image));
            }
        }
Example #3
0
 public ByteImage ReplicationScale(int newWidth, int newHeight)
 {
     ScaleInfo si = new ScaleInfo(width, height, newWidth, newHeight);
       byte?[][] newImage = Distribute(si);
       if(si.IsZooming)
       {
     byte? curr = null;
     int rWidth = newImage.Length;
     int rHeight = newImage[0].Length;
     int i = 0, j = 0;
     for(j = 0; j < rHeight; j++)
     {
       curr = null;
       for(i = 0; i < rWidth; i++)
       {
     if(newImage[i][j] != null)
       //set that as the new color
       curr = newImage[i][j];
     else
       newImage[i][j] = curr;
       }
     }
     for(i = 0; i < rWidth; i++)
     {
       curr = null;
       for(j = 0; j < rHeight; j++)
       {
     if(newImage[i][j] != null)
       //set that as the new color
       curr = newImage[i][j];
     else
       newImage[i][j] = curr;
       }
     }
     return new ByteImage(Convert(newImage));
       }
       else if(si.IsShrinking)
     return new ByteImage(Convert(newImage));
       else
     return this;
 }
Example #4
0
 ///<summary>
 /// Creates a new image that is of a new resolution.
 /// If the resolution is smaller than the current resolution
 /// then shrink the image
 ///<summary/>
 public byte?[][] Distribute(ScaleInfo si)
 {
     float wFac = si.WidthScalingFactor;
       float hFac = si.HeightScalingFactor;
       byte?[][] result = new byte?[si.ResultWidth][];
       for(int i = 0; i < si.ResultWidth; i++)
     result[i] = new byte?[si.ResultHeight];
       if(si.IsZooming)
       {
     Console.WriteLine("Scaling Up!");
     float iFactor = 0.0f;
     for(int i = 0; i < width; i++)
     {
       float jFactor = 0.0f;
       for(int j = 0; j < height; j++)
       {
     result[(int)Math.Round(iFactor)][(int)Math.Round(jFactor)] = image[i][j];
     jFactor += hFac;
       }
       iFactor += wFac;
     }
     return result;
       }
       if(si.IsShrinking)
       {
     for(int i = 0; i < si.ResultWidth; i++)
     {
       for(int j = 0; j < si.ResultHeight; j++)
       {
     //overlay...its an interesting idea
     int r1 = Math.Min(width - 1,
         Math.Max(0, (int)Math.Floor(i / wFac)));
     int r2 = Math.Min(height - 1,
         Math.Max(0, (int)Math.Floor(j / hFac)));
     result[i][j] = image[r1][r2];
       }
     }
     return result;
       }
       else
     return Convert(image);
 }