Partial 7.0 merge - API preview
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
sourceSets.main.java.srcDirs = ["src/"]
|
||||
|
||||
import arc.struct.*
|
||||
import arc.graphics.*
|
||||
import arc.packer.*
|
||||
import arc.util.*
|
||||
|
||||
import javax.imageio.*
|
||||
import java.awt.Graphics2D
|
||||
import java.awt.image.*
|
||||
import java.util.concurrent.*
|
||||
|
||||
import arc.files.Fi
|
||||
import arc.graphics.Color
|
||||
import arc.graphics.Pixmap
|
||||
import arc.packer.TexturePacker
|
||||
import arc.struct.IntIntMap
|
||||
import arc.struct.IntMap
|
||||
|
||||
import java.util.concurrent.ExecutorService
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
def genFolder = "../core/assets-raw/sprites_out/generated/"
|
||||
def doAntialias = !project.hasProperty("disableAntialias")
|
||||
@@ -25,16 +28,17 @@ def transformColors = { List<List<String>> list ->
|
||||
}
|
||||
|
||||
newColors.each{ color ->
|
||||
colorMap.put(color.argb8888(), newColors)
|
||||
colorIndexMap.put(color.argb8888(), newColors.indexOf(color))
|
||||
colorMap.put(color.rgba(), newColors)
|
||||
colorIndexMap.put(color.rgba(), newColors.indexOf(color))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//TODO implementing this in gradle is a bad idea
|
||||
//d4816b
|
||||
transformColors([["a387ea", "8a73c6", "5c5e9f"], ["6e7080", "989aa4", "b0bac0"], ["bc5452", "ea8878", "feb380"],
|
||||
["de9458", "f8c266", "ffe18f"], ["feb380", "ea8878", "bc5452"], ["d4816b", "eab678", "ffd37f"], ["ffffff", "dcc6c6", "9d7f7f"]])
|
||||
["de9458", "f8c266", "ffe18f"], ["feb380", "ea8878", "bc5452"], ["d4816b", "eab678", "ffd37f"],
|
||||
["ffffff", "dcc6c6", "9d7f7f"], ["df7646", "b23a4d", "752249"], ["3c3837", "515151", "646567"]])
|
||||
|
||||
def antialias = { File file ->
|
||||
if(!doAntialias) return
|
||||
@@ -44,11 +48,10 @@ def antialias = { File file ->
|
||||
return
|
||||
}
|
||||
|
||||
def image = ImageIO.read(file)
|
||||
def out = ImageIO.read(file)
|
||||
def image = new Pixmap(new Fi(file))
|
||||
def out = image.copy()
|
||||
def getRGB = { int ix, int iy ->
|
||||
//if(ix <= 0 || iy <= 0 || ix >= image.width || iy >= image.height) return 0
|
||||
return image.getRGB(Math.max(Math.min(ix, image.width - 1), 0), Math.max(Math.min(iy, image.height - 1), 0))
|
||||
return image.getRaw(Math.max(Math.min(ix, image.width - 1), 0), Math.max(Math.min(iy, image.height - 1), 0))
|
||||
}
|
||||
|
||||
def color = new Color()
|
||||
@@ -56,8 +59,8 @@ def antialias = { File file ->
|
||||
def suma = new Color()
|
||||
int[] p = new int[9]
|
||||
|
||||
for(int x = 0; x < image.getWidth(); x++){
|
||||
for(int y = 0; y < image.getHeight(); y++){
|
||||
for(int x = 0; x < image.width; x++){
|
||||
for(int y = 0; y < image.height; y++){
|
||||
int A = getRGB(x - 1, y + 1),
|
||||
B = getRGB(x, y + 1),
|
||||
C = getRGB(x + 1, y + 1),
|
||||
@@ -68,7 +71,7 @@ def antialias = { File file ->
|
||||
H = getRGB(x, y - 1),
|
||||
I = getRGB(x + 1, y - 1)
|
||||
|
||||
Arrays.fill(p, E);
|
||||
Arrays.fill(p, E)
|
||||
|
||||
if(D == B && D != H && B != F) p[0] = D
|
||||
if((D == B && D != H && B != F && E != C) || (B == F && B != D && F != H && E != A)) p[1] = B
|
||||
@@ -82,21 +85,21 @@ def antialias = { File file ->
|
||||
suma.set(0)
|
||||
|
||||
for(int val : p){
|
||||
color.argb8888(val)
|
||||
color.rgba8888(val)
|
||||
suma.r += color.r * color.a
|
||||
suma.g += color.g * color.a
|
||||
suma.b += color.b * color.a
|
||||
suma.a += color.a
|
||||
}
|
||||
|
||||
float fm = suma.a <= 0.001f ? 0f : (float) (1f / suma.a)
|
||||
float fm = suma.a <= 0.001f ? 0f : (float)(1f / suma.a)
|
||||
suma.mul(fm, fm, fm, fm)
|
||||
|
||||
float total = 0
|
||||
sum.set(0)
|
||||
|
||||
for(int val : p){
|
||||
color.argb8888(val)
|
||||
color.rgba8888(val)
|
||||
float a = color.a
|
||||
color.lerp(suma, (float) (1f - a))
|
||||
sum.r += color.r
|
||||
@@ -108,92 +111,19 @@ def antialias = { File file ->
|
||||
|
||||
fm = (float)(1f / total)
|
||||
sum.mul(fm, fm, fm, fm)
|
||||
out.setRGB(x, y, sum.argb8888())
|
||||
out.setRaw(x, y, sum.rgba8888())
|
||||
sum.set(0)
|
||||
}
|
||||
}
|
||||
|
||||
ImageIO.write(out, "png", file)
|
||||
}
|
||||
image.dispose()
|
||||
out.dispose()
|
||||
|
||||
def medianBlur = { File file ->
|
||||
def image = ImageIO.read(file)
|
||||
def result = new BufferedImage(image.width, image.height, BufferedImage.TYPE_INT_ARGB)
|
||||
def radius = 4
|
||||
IntSeq array = new IntSeq()
|
||||
|
||||
def getRGB = { int ix, int iy ->
|
||||
return image.getRGB(Math.max(Math.min(ix, image.width - 1), 0), Math.max(Math.min(iy, image.height - 1), 0))
|
||||
}
|
||||
|
||||
for(int x = 0; x < image.width; x++){
|
||||
for(int y = 0; y < image.height; y++){
|
||||
array.clear()
|
||||
|
||||
for(int dx = -radius; dx <= radius; dx ++){
|
||||
for(int dy = -radius; dy <= radius; dy ++){
|
||||
if(dx*dx + dy*dy <= radius*radius){
|
||||
array.add(getRGB(x + dx, y + dy))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
array.sort()
|
||||
|
||||
result.setRGB(x, y, array.get((int)(array.size / 2)))
|
||||
}
|
||||
}
|
||||
|
||||
ImageIO.write(result, "png", file)
|
||||
}
|
||||
|
||||
def scaleImage = { File file ->
|
||||
def image = ImageIO.read(file)
|
||||
for(int iteration in 0..1){
|
||||
def scaled = new BufferedImage(image.width * 2, image.height * 2, BufferedImage.TYPE_INT_ARGB)
|
||||
|
||||
def getRGB = { int ix, int iy ->
|
||||
return image.getRGB(Math.max(Math.min(ix, image.width - 1), 0), Math.max(Math.min(iy, image.height - 1), 0))
|
||||
}
|
||||
|
||||
for(int x = 0; x < image.width; x++){
|
||||
for(int y = 0; y < image.height; y++){
|
||||
int p = image.getRGB(x, y)
|
||||
int p1 = p, p2 = p, p3 = p, p4 = p
|
||||
|
||||
int A = getRGB(x - 1, y + 1),
|
||||
B = getRGB(x, y + 1),
|
||||
C = getRGB(x + 1, y + 1),
|
||||
D = getRGB(x - 1, y),
|
||||
E = getRGB(x, y),
|
||||
F = getRGB(x + 1, y),
|
||||
G = getRGB(x - 1, y - 1),
|
||||
H = getRGB(x, y - 1),
|
||||
I = getRGB(x + 1, y - 1),
|
||||
J = getRGB(x, y + 2),
|
||||
K = getRGB(x - 2, y),
|
||||
L = getRGB(x + 2, y),
|
||||
M = getRGB(x, y - 2)
|
||||
|
||||
if(B == D && B != F && D != H && (E != A || E == C || E == G || A == J || A == K)) p1 = B
|
||||
if(B == F && B != D && F != H && (E != C || E == A || E == I || C == J || C == L)) p2 = F
|
||||
if(D == H && B != D && F != H && (E != G || E == A || E == I || G == K || G == M)) p3 = D
|
||||
if(F == H && B != F && D != H && (E != I || E == C || E == G || I == L || I == M)) p4 = H
|
||||
|
||||
scaled.setRGB(x * 2, y * 2 + 1, p1)
|
||||
scaled.setRGB(x * 2 + 1, y * 2 + 1, p2)
|
||||
scaled.setRGB(x * 2, y * 2, p3)
|
||||
scaled.setRGB(x * 2 + 1, y * 2, p4)
|
||||
}
|
||||
}
|
||||
image = scaled
|
||||
}
|
||||
|
||||
ImageIO.write(image, "png", file)
|
||||
new Fi(file).writePng(out)
|
||||
}
|
||||
|
||||
def tileImage = { File file ->
|
||||
def image = ImageIO.read(file)
|
||||
def image = new Pixmap(new Fi(file))
|
||||
|
||||
for(x in 0..image.width-1){
|
||||
for(y in 0..image.height-1){
|
||||
@@ -201,104 +131,36 @@ def tileImage = { File file ->
|
||||
def rx = image.height - 1 - y
|
||||
def ry = x
|
||||
|
||||
image.setRGB(x, y, image.getRGB(rx, image.height - 1 - ry))
|
||||
image.setRaw(x, y, image.getRaw(rx, image.height - 1 - ry))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def result = new BufferedImage(image.width * 2, image.height * 2, image.getType())
|
||||
Graphics2D graphics = result.createGraphics()
|
||||
graphics.drawImage(image, image.width, 0, -image.width, image.height, null)
|
||||
def result = new Pixmap(image.width * 2, image.height * 2)
|
||||
|
||||
graphics.drawImage(image, image.width, 0, image.width, image.height, null)
|
||||
result.draw(image.flipX(), 0, 0)
|
||||
result.draw(image, image.width, 0)
|
||||
result.draw(image.flipX().flipY(), 0, image.height)
|
||||
result.draw(image.flipY(), image.width, image.height)
|
||||
|
||||
graphics.drawImage(image, image.width, image.height*2, -image.width, -image.height, null)
|
||||
|
||||
graphics.drawImage(image, image.width, image.height*2, image.width, -image.height, null)
|
||||
|
||||
for(int x = 0; x < result.width; x++){
|
||||
for(int y = 0; y < result.height; y++){
|
||||
int p = result.getRGB(x, y)
|
||||
for(x in 0..result.width-1){
|
||||
for(y in 0..result.height-1){
|
||||
int p = result.getRaw(x, y)
|
||||
if(x <= y){
|
||||
List<Color> list = colorMap.get(p)
|
||||
int index = colorIndexMap.get(p, -1)
|
||||
|
||||
if(index != -1){
|
||||
int resultIndex = (x == y ? 1 : index == 2 ? 0 : index == 0 ? 2 : 1);
|
||||
result.setRGB(x, y, list[resultIndex].argb8888())
|
||||
result.setRaw(x, y, list[resultIndex].rgba())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ImageIO.write(result, "png", file)
|
||||
}
|
||||
|
||||
task swapColors(){
|
||||
doLast{
|
||||
if(project.hasProperty("colors")){
|
||||
def carr = new File(getProperty("colors")).text.split("\n")
|
||||
def map = [:]
|
||||
def swaps = 0
|
||||
carr.each{ str -> map[Color.valueOf(str.split("=")[0]).argb8888()] = Color.valueOf(str.split("=")[1]).argb8888() }
|
||||
def tmpc = new Color()
|
||||
|
||||
fileTree(dir: '../core/assets-raw/sprites', include: "**/*.png").visit{ file ->
|
||||
if(file.isDirectory()) return
|
||||
|
||||
boolean found = false
|
||||
|
||||
def img = ImageIO.read(file.file)
|
||||
for(x in (0..img.getWidth() - 1)){
|
||||
for(y in (0..img.getHeight() - 1)){
|
||||
def c = img.getRGB(x, y)
|
||||
tmpc.argb8888(c)
|
||||
if(tmpc.a < 0.1f) continue
|
||||
if(map.containsKey(c)){
|
||||
img.setRGB(x, y, (int)map.get(c))
|
||||
found = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if(found){
|
||||
swaps++
|
||||
ImageIO.write(img, "png", file.file)
|
||||
}
|
||||
}
|
||||
println "Swapped $swaps images."
|
||||
}else{
|
||||
throw new InvalidUserDataException("No replacement colors specified. Use -Pcolors=\"<path to color file>\"")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task genPalette(){
|
||||
doLast{
|
||||
def total = 0
|
||||
def size = 32
|
||||
def outImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB)
|
||||
def colorsUsed = new IntSet()
|
||||
|
||||
fileTree(dir: '../core/assets-raw/sprites/blocks', include: "**/*.png").visit{ file ->
|
||||
if(file.isDirectory()) return
|
||||
|
||||
def img = ImageIO.read(file.file)
|
||||
for(x in (0..img.getWidth() - 1)){
|
||||
for(y in (0..img.getHeight() - 1)){
|
||||
def c = img.getRGB(x, y)
|
||||
|
||||
if(Tmp.c1.argb8888(c).a > 0.999f && colorsUsed.add(c)){
|
||||
outImage.setRGB((int)(total / size), total % size, c)
|
||||
total ++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ImageIO.write(outImage, "png", new File("palette.png"))
|
||||
println "Found $total colors."
|
||||
|
||||
}
|
||||
new Fi(file).writePng(result)
|
||||
result.dispose()
|
||||
image.dispose()
|
||||
}
|
||||
|
||||
task antialiasImages(){
|
||||
@@ -310,15 +172,6 @@ task antialiasImages(){
|
||||
}
|
||||
}
|
||||
|
||||
task scaleImages(){
|
||||
doLast{
|
||||
for(def img : project.getProperty("images").split(",")){
|
||||
println(project.getProperty("startdir") + "/" + img)
|
||||
scaleImage(new File(project.getProperty("startdir") + "/" + img))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task tileImages(){
|
||||
doLast{
|
||||
for(def img : project.getProperty("images").split(",")){
|
||||
@@ -383,7 +236,7 @@ task pack(dependsOn: [classes, configurations.runtimeClasspath]){
|
||||
println("\n\nPacking normal 4096 sprites...\n\n")
|
||||
|
||||
//pack normal sprites
|
||||
TexturePacker.process(new File(rootDir, "core/assets-raw/sprites_out/").absolutePath, new File(rootDir, "core/assets/sprites/").absolutePath, "sprites.atlas")
|
||||
TexturePacker.process(new File(rootDir, "core/assets-raw/sprites_out/").absolutePath, new File(rootDir, "core/assets/sprites/").absolutePath, "sprites.aatls")
|
||||
|
||||
println("\n\nPacking fallback 2048 sprites...\n\n")
|
||||
|
||||
@@ -393,7 +246,7 @@ task pack(dependsOn: [classes, configurations.runtimeClasspath]){
|
||||
}
|
||||
|
||||
//pack fallback 2048x2048 sprites
|
||||
TexturePacker.process(new File(rootDir, "core/assets-raw/sprites_out/").absolutePath, new File(rootDir, "core/assets/sprites/fallback/").absolutePath, "sprites.atlas")
|
||||
TexturePacker.process(new File(rootDir, "core/assets-raw/sprites_out/").absolutePath, new File(rootDir, "core/assets/sprites/fallback/").absolutePath, "sprites.aatls")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -402,7 +255,6 @@ task genSprites(dependsOn: classes, type: JavaExec){
|
||||
|
||||
main = "mindustry.tools.ImagePacker"
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
jvmArgs("-Djava.awt.headless=true")
|
||||
standardInput = System.in
|
||||
workingDir = genFolder
|
||||
}
|
||||
@@ -435,11 +287,4 @@ task updateScripts(dependsOn: classes, type: JavaExec){
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
standardInput = System.in
|
||||
workingDir = "../"
|
||||
}
|
||||
|
||||
task genBindings(dependsOn: classes, type: JavaExec){
|
||||
main = "mindustry.tools.BindingsGenerator"
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
standardInput = System.in
|
||||
workingDir = "../"
|
||||
}
|
||||
Reference in New Issue
Block a user