Skip to content

Commit

Permalink
Make it compatible with 1.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
sullerandras committed Aug 22, 2016
1 parent 0a79194 commit 56cb3db
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 14 deletions.
18 changes: 9 additions & 9 deletions execute.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#!/usr/bin/env bash

SOURCE_XNB_FOLDER=Terraria.v1.3.1-read-only/Content/Images
SOURCE_XNB_FOLDER=Terraria.v1.3.2-read-only/Content/Images
EXTRACTED_FOLDER=temp1
DOWNSCALED_FOLDER=temp2
NO_SEPARATORS_FOLDER=temp3
MAGNIFIED_FOLDER=temp4
REFILLED_FOLDER=temp5
RELEASE_FOLDER=temp6-release
TARGET_XNB_FOLDER=Terraria.v1.3.1/Content/Images
TARGET_XNB_FOLDER=Terraria.v1.3.2/Content/Images

function extractPngsFromTerraria() {
echo "calling TExtract $1 => $2"
mkdir -p $2
mkdir -p $2/UI
java -jar "tools/TExtract 1.6.0.jar" --outputDirectory $2.temp $1
mv $2.temp/Images $2
rm -rf $2.temp
}
function downscalePngs() {
echo "downscaling images $1 => $2"
Expand All @@ -38,11 +37,11 @@ function magnifyPngs() {
mkdir -p $2/Items
mv $2/Others/Item_* $2/Items/
if [ "$3" = "blend" ]; then
wine tools/image_filter.exe "XBR" $2/Items $2
wine tools/image_filter.exe "XBR" -wrap $2/Items $2
wine tools/image_filter.exe "XBRz" $2/Others $2
wine tools/image_filter.exe "XBRz" $1/UI $2/UI
else
wine tools/image_filter.exe "XBR-NoBlend" $2/Items $2
wine tools/image_filter.exe "XBR-NoBlend" -wrap $2/Items $2
wine tools/image_filter.exe "XBR-NoBlend" $2/Others $2
wine tools/image_filter.exe "XBR-NoBlend" $1/UI $2/UI
fi
Expand Down Expand Up @@ -72,19 +71,20 @@ function createRelease() {
rm -rf $3/Images/Misc
rm -rf $3/Images/UI/WorldGen
rm -rf $3/Images/UI/Button*
echo "Enhanced version of the textures of Terraria 1.3.0.8" > $3/README.txt
echo "Enhanced version of the textures of Terraria 1.3.2" > $3/README.txt
echo "" >> $3/README.txt
echo "Crated by Andras Suller, `date +%F`, $version." >> $3/README.txt
echo "For more information visit: http://forums.terraria.org/index.php?threads/enhanced-version-of-the-textures-of-terraria-1-3-0-8.39115/" >> $3/README.txt
cd $3
zip -r ../$out_file README.txt Images
cd ..
}
#SOURCE_XNB_FOLDER="/home/andras/Downloads/Terraria_Soft_Pack_1-10-2016"
extractPngsFromTerraria $SOURCE_XNB_FOLDER $EXTRACTED_FOLDER
downscalePngs $EXTRACTED_FOLDER $DOWNSCALED_FOLDER
removeSeparators $DOWNSCALED_FOLDER $NO_SEPARATORS_FOLDER
magnifyPngs $NO_SEPARATORS_FOLDER $MAGNIFIED_FOLDER "blend"
refillMissingPixels $EXTRACTED_FOLDER $MAGNIFIED_FOLDER $REFILLED_FOLDER
pngsToXnbs $REFILLED_FOLDER $TARGET_XNB_FOLDER
createRelease v0.5-1.3.1 $TARGET_XNB_FOLDER $RELEASE_FOLDER
# createRelease v0.5-noblend-1.3.1 $TARGET_XNB_FOLDER $RELEASE_FOLDER
createRelease v0.6-1.3.2 $TARGET_XNB_FOLDER $RELEASE_FOLDER
createRelease v0.6-noblend-1.3.2 $TARGET_XNB_FOLDER $RELEASE_FOLDER
4 changes: 2 additions & 2 deletions tools/config.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Configuration>
<LastSaveDirectory value="" />
<LastLoadDirectory value="Z:\home\andras\projects\terraria-images-magnifier-new\temp3" />
<LastSaveDirectory value="Z:\home\andras\Downloads" />
<LastLoadDirectory value="Z:\home\andras\Downloads" />
<SourceSizeMode value="" />
<TargetSizeMode value="CenterImage" />
</Configuration>
Binary file modified tools/image_filter.exe
Binary file not shown.
Binary file added tools/image_filter.exe.mdb
Binary file not shown.
Binary file modified tools/refill_missing_pixels.exe
Binary file not shown.
9 changes: 6 additions & 3 deletions tools/remove_separators.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def SEP(grid_size):
},
'tiles-72x605': {
'column': SEP9,
'row': lambda x: x % 18 == 8
'row': lambda x: (x < 566 and x % 18 == 8) or (x >= 566 and x - 1 % 18 == 8) # row 567 is the empty row instead of 566
},
'tiles-27x196': {
'column': SEP9,
Expand Down Expand Up @@ -362,6 +362,10 @@ def SEP(grid_size):
'wall-234x180': lambda x: x % 18 >= 16,
'wall-234x126': lambda x: x % 18 >= 16,
'wires-45x36': SEP(9),
'wires-20x20': [],
'wires-16x16': [],
'wires-8x8': [],
'wiresnew-144x144': SEP(9),
'wraitheyes-13x100': [],
'xmas-32x64': [],
'xmas-198x65': { 'column': SEP(33), 'row': [64] },
Expand Down Expand Up @@ -489,7 +493,7 @@ def remove_separators(input_filename, clazz, pixelarray):
if not pixelarray.isTransparent(x, y):
pixels.add(str(pixelarray.getPixelAt(x, y)))
if len(pixels) >= 3:
if ntpath.basename(input_filename) in ['Tiles_17.png', 'Tiles_73.png', 'Tiles_126.png', 'Tiles_203.png', 'Tiles_229.png', 'Tiles_274.png', 'Tiles_32.png', 'Tiles_352.png', 'Tiles_69.png', 'Wall_60.png', 'Wall_73.png']:
if ntpath.basename(input_filename) in ['Tiles_17.png', 'Tiles_73.png', 'Tiles_126.png', 'Tiles_203.png', 'Tiles_229.png', 'Tiles_274.png', 'Tiles_32.png', 'Tiles_352.png', 'Tiles_443.png', 'Tiles_69.png', 'Wall_60.png', 'Wall_73.png']:
# print('Wrong row index in file %s: %s, colors: %s' % (ntpath.basename(input_filename), y, pixels))
pixels = set()
else:
Expand Down Expand Up @@ -671,4 +675,3 @@ def remove_separators_from_images_in_folder(input_dir, output_dir):

# import cProfile
# cProfile.run('remove_separators_from_all_tiles()', sort=1)

78 changes: 78 additions & 0 deletions tools/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from __future__ import print_function
import array
import glob
import ntpath
import pickle
import png
import re
import sys
import traceback

from Array3D import Array3D

TRANSPARENT = (0, 0, 0, 0)

def error(*objs):
print("ERROR: ", *objs, file=sys.stderr)

def read_as_pixelarray(filename):
img = png.Reader(filename = filename)
(width, height, pixels, meta) = img.asRGBA8()
data = [row for row in pixels]
pixelarray = Array3D(data, width, height, depth=4)
return pixelarray

def color_difference(color1, color2):
sum = 0
for i in range(4):
sum += pow(color1[i] - color2[i], 2)
return sum

def nearest_color(color, used_colors):
if color[3] < 120:
return TRANSPARENT
min_difference = color_difference(color, used_colors[0])
nearest = used_colors[0]
for c in used_colors:
diff = color_difference(color, c)
if diff < min_difference:
min_difference = diff
nearest = c
# print('nearest color to %s: %s', (color, nearest))
return nearest

def sharpen(input_filename, original_pixelarray, pixelarray):
used_colors = []
for x in xrange(original_pixelarray.width):
for y in xrange(original_pixelarray.height):
color = original_pixelarray.getPixelAt(x, y)
if not (color in used_colors):
used_colors.append(color)
print('used_colors: %s' % (used_colors,))

for x in xrange(pixelarray.width):
for y in xrange(pixelarray.height):
color = pixelarray.getPixelAt(x, y)
color = nearest_color(color, used_colors)
pixelarray.setPixelAt(x, y, color)



def sharpen_image(original_filename, input_filename, output_filename):
original_pixelarray = read_as_pixelarray(original_filename)
pixelarray = read_as_pixelarray(input_filename)
sharpen(input_filename, original_pixelarray, pixelarray)

writer = png.Writer(width=pixelarray.width, height=pixelarray.height, alpha=True, bitdepth=8, compression=9)
print('writing file %s' % output_filename)
f = open(output_filename, 'wb')
try:
writer.write(f, pixelarray.data)
finally:
f.close()

# sharpen_image(sys.argv[1], sys.argv[2])
sharpen_image('Item_1.png', 'Item_1-smooth.png', 'Item_1-sharpened.png')

# import cProfile
# cProfile.run('remove_separators_from_all_tiles()', sort=1)

0 comments on commit 56cb3db

Please sign in to comment.