public void CopyFrom(SymbImageCanvas img, int ox, int oy) { for (int y = 0; y < img.size1; y++) { for (int x = 0; x < img.size0; x++) { dat[y + oy][x + ox] = img.dat[y][x]; } } }
public SymbImage[] ResolveExtendBool(ref int image_width, ref int image_height) { image_width = ((maxSymbWidth) < image_width) ? image_width : maxSymbWidth; int count = items.Length; int averW = sumWidth / count; int averH = sumHeight / count; int averRowCount = (int)Mathf.Sqrt(count); int averRowWidth = averRowCount * averW; image_width = (averRowWidth > image_width) ? averRowWidth : image_width; image_width = GetP2Size(image_width); SymbImageCanvas masq = new SymbImageCanvas(image_width, image_height); int maxY = 0; Array.Sort(items); SymbImage sImage; int idx, idy, tty, ttx, tty1, ttx1, imwIDX, itemsLength; bool found, valid; int minHeight = (minH < 2) ? 2 : minH; int minWidth = (minW < 2) ? 2 : minW; itemsLength = items.Length; bool[][] canvas = masq.dat; for (int i = 0; i < itemsLength; i++) { sImage = items[i]; idx = sImage.size0; idy = sImage.size1; tty = 0; imwIDX = image_width - idx + 1; found = false; for (int ty = 0; ((ty < 8192) && !found); ty += 4) // 8192 - max resolved size; ty+=4 speed x4 { tty = ty + idy; tty1 = tty - 1; if (tty > masq.size1) { masq.Resize(image_width, tty); } for (int tx = 0; ((tx < imwIDX) && !found);) { ttx = tx + idx; ttx1 = ttx - 1; valid = !canvas[ty][tx] && !canvas[tty1][tx] && !canvas[ty][ttx1] && !canvas[tty1][ttx1]; if (valid) // check full quad space for validating { for (int ity = ty; ity < tty; ity += minHeight) { for (int itx = tx; itx < ttx; itx += minWidth) { if (canvas[ity][itx]) { valid = false; break; } } if (!valid) { break; } } } if (valid) { masq.Fill(tx, ty, ttx, tty, true); sImage.d.sx = tx; sImage.d.sy = ty; sImage.d.ex = ttx; sImage.d.ey = tty; found = true; maxY = tty; tx = ttx; } else { tx += 2; // 2x faster but low packing } } } } image_height = (maxY % 2 == 0) ? maxY + 2 : maxY + 3; image_height = GetP2Size(image_height); image_width = masq.size0; return(items); }
public SymbImage[] ResolveExtendBool(ref int image_width, ref int image_height, int ext) { int ext2 = ext + ext; image_width = ((maxSymbWidth + ext2) < image_width) ? image_width : maxSymbWidth + ext2; int count = items.Length; int averW = sumWidth / count + ext2; int averH = sumHeight / count + ext2; int averRowCount = (int)Mathf.Sqrt(count); int averRowWidth = averRowCount * averW; image_width = (averRowWidth > image_width) ? averRowWidth : image_width; image_width = GetP2Size(image_width); SymbImageCanvas masq = new SymbImageCanvas(image_width, image_height); int maxY = 0; Array.Sort(items); for (int i = 0; i < items.Length; i++) { int idx = items[i].size0 + ext2; int idy = items[i].size1 + ext2; int tty = 0; bool found = false; for (int ty = 0; ((ty < 8192) && !found); ty += 4) // 8192 - max resolved size; ty+=4 speed x4 { tty = ty + idy; if (tty > masq.size1) { masq.Resize(image_width, ty + idy); } for (int tx = 0; ((tx <= (image_width - idx)) && !found); tx++) { bool valid = !masq.dat[ty][tx] && !masq.dat[tty - 1][tx] && !masq.dat[ty][tx + idx - 1] && !masq.dat[tty - 1][tx + idx - 1]; if (valid) // check full quad space for validating { int py; for (int ity = 0; ity < idy; ity += 2) { py = ty + ity; for (int itx = 0; itx < idx; itx += 2) { if (masq.dat[py][tx + itx]) { valid = false; break; } } if (!valid) { break; } } } /* */ if (valid) { masq.Fill(tx, ty, tx + idx, tty, true); items[i].d.sx = tx + ext; items[i].d.sy = ty + ext; items[i].d.ex = tx + idx - ext; items[i].d.ey = tty - ext; found = true; maxY = tty; } } } } image_height = (maxY % 2 == 0) ? maxY + 2 : maxY + 3; image_height = GetP2Size(image_height); image_width = masq.size0; return(items); }