static bool AddSubImageIfPossible( InputBitmap ib, OutputBitmap ob, bool allowImageResize ) { if ( ob.SingleImageOutput ) return false; // attempt to fill a small power of 2 texture first, then expand it gradually up to the maximum size // if the sub images don't fit. mVirtualSize is the size of the current rect we are trying to fill if ( ob.AvailableRects.Count == 0 ) { // first time this output bitmap has been used, try using the smallest possible virtual texture size ob.InitVirtualSize( ib.mBitmap.Size ); } if ( allowImageResize ) { while ( !InsertImage( ib, ob ) ) { // no images could be inserted in current image using current virtual size. // increase virtual size and try again if ( !ob.IncreaseVirtualSize() ) return false; // cannot fit anymore images into this output image } return true; } else return InsertImage( ib, ob ); }
static bool InsertImage(InputBitmap inputImage, OutputBitmap ob) { foreach (Rectangle rect in ob.AvailableRects) { bool isRotated = false; if (ImageFitsInRect(rect, inputImage.mBitmap, out isRotated)) { Size paddingSize = new Size(GetPaddingWidth(rect), GetPaddingHeight(rect)); Point locationIncludingPadding = new Point(rect.X + paddingSize.Width, rect.Y + paddingSize.Height); // copy image data ob.CopyImageIntoImage(inputImage.mBitmap, locationIncludingPadding, isRotated); // remove old rect, add 2 new ones // when storing a square inside a larger square, will always leave 2 other rectangles, one on the bottom // and one on the right. These rects are added to a list and then used to see if any future input images can fit ob.AvailableRects.Remove(rect); Size subImageSize = isRotated ? new Size(inputImage.mBitmap.Height, inputImage.mBitmap.Width) : inputImage.mBitmap.Size; SplitRect(ob, rect, subImageSize + paddingSize); ob.SubImages.Add(new SubImage(inputImage.mName, Util.FormatSubImageName(inputImage.mName), new Rectangle(locationIncludingPadding, subImageSize), isRotated)); ob.SortRectList(); return(true); } } return(false); }
static bool AddSubImageIfPossible(InputBitmap ib, OutputBitmap ob, bool allowImageResize) { if (ob.SingleImageOutput) { return(false); } // attempt to fill a small power of 2 texture first, then expand it gradually up to the maximum size // if the sub images don't fit. mVirtualSize is the size of the current rect we are trying to fill if (ob.AvailableRects.Count == 0) { // first time this output bitmap has been used, try using the smallest possible virtual texture size ob.InitVirtualSize(ib.mBitmap.Size); } if (allowImageResize) { while (!InsertImage(ib, ob)) { // no images could be inserted in current image using current virtual size. // increase virtual size and try again if (!ob.IncreaseVirtualSize()) { return(false); // cannot fit anymore images into this output image } } return(true); } else { return(InsertImage(ib, ob)); } }
public override bool Equals(object obj) { if (obj != null && obj is InputBitmap) { InputBitmap ib = (InputBitmap)obj; return(ib.mName.Equals(this.mName)); } return(false); }
static bool AddSubImageIfPossible( InputBitmap inputBitmap, List<OutputBitmap> outputBitmaps ) { // Attempt to fit in to existing rects without resizing image first foreach ( OutputBitmap ob in outputBitmaps ) { if ( AddSubImageIfPossible( inputBitmap, ob, false ) ) return true; } // then try with resizing foreach ( OutputBitmap ob in outputBitmaps ) { if ( AddSubImageIfPossible( inputBitmap, ob, true ) ) return true; } return false; }
static bool AddSubImageIfPossible(InputBitmap inputBitmap, List <OutputBitmap> outputBitmaps) { // Attempt to fit in to existing rects without resizing image first foreach (OutputBitmap ob in outputBitmaps) { if (AddSubImageIfPossible(inputBitmap, ob, false)) { return(true); } } // then try with resizing foreach (OutputBitmap ob in outputBitmaps) { if (AddSubImageIfPossible(inputBitmap, ob, true)) { return(true); } } return(false); }
public static List <OutputBitmap> BreakIntoOutputBitmaps(List <InputBitmap> inputBitmaps, string outputName) { RemoveInvalidInputBitmaps(inputBitmaps); SortBySize(inputBitmaps); List <OutputBitmap> outputBitmaps = new List <OutputBitmap>(); while (inputBitmaps.Count > 0) { InputBitmap inputImage = inputBitmaps[0]; if (OutputBitmap.IsInputImageValidSize(inputBitmaps[0].mBitmap)) { bool imageHasBeenAdded = AddSubImageIfPossible(inputBitmaps[0], outputBitmaps); // add a new output bitmap if an existing space can't be found if (!imageHasBeenAdded) { OutputBitmap newOutput = new OutputBitmap(outputName, outputBitmaps.Count); outputBitmaps.Add(newOutput); } else { inputBitmaps.Remove(inputBitmaps[0]); } } else { // if larger than target atlas size, just copy the input image over and add it to the page list OutputBitmap newOutput = new OutputBitmap(outputName, outputBitmaps.Count, inputBitmaps[0].mBitmap.Width, inputBitmaps[0].mBitmap.Height); newOutput.CopyImageIntoImage(inputBitmaps[0].mBitmap, new Point(0, 0), false); newOutput.SubImages.Add(new SubImage(inputImage.mName, Util.FormatSubImageName(inputImage.mName), new Rectangle(new Point(0, 0), inputImage.mBitmap.Size), false)); outputBitmaps.Add(newOutput); inputBitmaps.Remove(inputBitmaps[0]); } } return(outputBitmaps); }
static bool InsertImage( InputBitmap inputImage, OutputBitmap ob ) { foreach ( Rectangle rect in ob.AvailableRects ) { bool isRotated = false; if ( ImageFitsInRect( rect, inputImage.mBitmap, out isRotated ) ) { Size paddingSize = new Size( GetPaddingWidth( rect ), GetPaddingHeight( rect ) ); Point locationIncludingPadding = new Point( rect.X + paddingSize.Width, rect.Y + paddingSize.Height ); // copy image data ob.CopyImageIntoImage( inputImage.mBitmap, locationIncludingPadding, isRotated ); // remove old rect, add 2 new ones // when storing a square inside a larger square, will always leave 2 other rectangles, one on the bottom // and one on the right. These rects are added to a list and then used to see if any future input images can fit ob.AvailableRects.Remove( rect ); Size subImageSize = isRotated ? new Size( inputImage.mBitmap.Height, inputImage.mBitmap.Width ) : inputImage.mBitmap.Size; SplitRect( ob, rect, subImageSize + paddingSize ); ob.SubImages.Add( new SubImage( inputImage.mName, Util.FormatSubImageName( inputImage.mName ), new Rectangle( locationIncludingPadding, subImageSize ), isRotated ) ); ob.SortRectList(); return true; } } return false; }