Loading
#openttdcoop - Paste
Archives
Trending
Docs
Login
ABAP
ActionScript
ActionScript 3
Ada
AIMMS3
ALGOL 68
Apache configuration
AppleScript
Apt sources
ARM ASSEMBLER
ASM
ASP
asymptote
Autoconf
Autohotkey
AutoIt
AviSynth
awk
BASCOM AVR
Bash
Basic4GL
BibTeX
BlitzBasic
bnf
Boo
Brainfuck
C
C#
C (LoadRunner)
C (Mac)
C (WinAPI)
C++
C++ (Qt)
C++ (WinAPI)
CAD DCL
CAD Lisp
CFDG
ChaiScript
Chapel
CIL
Clojure
CMake
COBOL
CoffeeScript
ColdFusion
CSS
Cuesheet
D
Dart
DCL
DCPU-16 Assembly
DCS
Delphi
Diff
DIV
DOS
dot
E
ECMAScript
Eiffel
eMail (mbox)
EPC
Erlang
Euphoria
EZT
F#
Falcon
FO (abas-ERP)
Formula One
Fortran
FreeBasic
FreeSWITCH
GADV 4CS
GAMBAS
GDB
genero
Genie
glSlang
GML
GNU/Octave
GNU Gettext
GNU make
Gnuplot
Go
Groovy
GwBasic
Haskell
Haxe
HicEst
HQ9+
HTML
HTML5
Icon
INI
Inno
INTERCAL
Io
ISPF Panel
J
Java
Java(TM) 2 Platform Standard Edition 5.0
Javascript
JCL
jQuery
KiXtart
KLone C
KLone C++
LaTeX
LDIF
Liberty BASIC
Lisp
LLVM Intermediate Representation
Locomotive Basic
Logtalk
LOLcode
Lotus Notes @Formulas
LotusScript
LScript
LSL2
Lua
MagikSF
MapBasic
Matlab M
Microchip Assembler
Microsoft Registry
mIRC Scripting
MMIX
Modula-2
Modula-3
MOS 6502 (6510) ACME Cross Assembler format
MOS 6502 (6510) Kick Assembler format
MOS 6502 (6510) TASM/64TASS 1.46 Assembler format
Motorola 68000 - HiSoft Devpac ST 2 Assembler format
Motorola 68000 Assembler
MXML
MySQL
Nagios
NetRexx
newlisp
nginx
Nimrod
NML NewGRF Meta Language
NSIS
Oberon-2
Objeck Programming Language
Objective-C
OCaml
OCaml (brief)
ooRexx
OpenBSD Packet Filter
OpenOffice.org Basic
Oracle 8 SQL
Oracle 11 SQL
Oxygene
OZ
ParaSail
PARI/GP
Pascal
PCRE
per
Perl
Perl 6
PHP
PHP (brief)
PIC16
Pike
Pixel Bender 1.0
PL/I
PL/SQL
PostgreSQL
PostScript
POVRAY
PowerBuilder
PowerShell
ProFTPd configuration
Progress
Prolog
PROPERTIES
ProvideX
Puppet
PureBasic
Python
Python for S60
q/kdb+
QBasic/QuickBASIC
QML
R / S+
Racket
Rails
RBScript
REBOL
rexx
robots.txt
RPM Specification File
Ruby
Rust
SAS
Scala
Scheme
SciLab
SCL
sdlBasic
Smalltalk
Smarty
SPARK
SPARQL
SQL
Squirrel Script
Squirrel Script with OpenTTD AI/GS
StandardML
StoneScript
SystemVerilog
T-SQL
TCL
Tera Term Macro
Text
thinBasic
TypoScript
Unicon (Unified Extended Dialect of Icon)
Uno Idl
Unreal Script
UPC
Urbi
Vala
vb.net
VBScript
Vedit macro language
Verilog
VHDL
Vim Script
Visual Basic
Visual Fox Pro
Visual Prolog
Whitespace
Whois (RPSL format)
Winbatch
X++
XBasic
XML
Xorg configuration
YAML
ZiLOG Z80 Assembler
ZXBasic
import math import os from os import remove from PIL import Image #starting message print("-"*79) print("Starting...") #path definition diskPath = "E:/_BRIX/_BRIX-repository/scripts/"#"C:/Users/Pavel/Downloads/scripts/" inputFolder = diskPath + "input/" outputFolder = diskPath + "output/" #printing path just to check print("inputFolder is " + inputFolder) print("outputFolder is " + outputFolder) #open palette image palette = Image.open(inputFolder + "openttd-palette-dos.png") print("Opening: " + "openttd-palette-dos.png") p=[] for b in range(0,palette.height): for a in range(0, palette.width): p.append(palette.getpixel((a,b))) #print(p) def rgb2palette(inputImage, frameNumber): #open input image i = Image.open(inputFolder + inputImage + frameNumber + ".png") print("Opening: " + inputImage + frameNumber + ".png") #create new empty image for output imageOutput = Image.new("RGBA", (i.width,i.height), color=(0,0,0,0)) for y in range (0, i.height): for x in range (0, i.width): #defining winner variables winnerDistance = 100000000 winnerID = 0 #loading pixel from image and separating RGBA pixelNumber = x + (y * i.width) pix = i.getpixel((x,y)) pixRed = pix[0] pixGreen = pix[1] pixBlue = pix[2] pixAlpha = pix[3] #check Alpha in pixel, and output alpha/color offset if pixAlpha < 128: finalAlpha = 0 colorOffset = 0 if pixAlpha >= 128 and pixAlpha < 178: finalAlpha = 255 colorOffset = 1 if pixAlpha >= 178 and pixAlpha < 230: finalAlpha = 255 colorOffset = 2 if pixAlpha >= 230: finalAlpha = 255 colorOffset = 0 #if alpha above 50%, do colour comparing to palette if pixAlpha >= 128: for z in range(0, 255): #taking a palette colour colorArray = p[z] paletteR = colorArray[0] paletteG = colorArray[1] paletteB = colorArray[2] #calculating distance between palette colour and input colour distance = math.sqrt( ((pixRed-paletteR)*(pixRed-paletteR)) + ((pixGreen-paletteG)*(pixGreen-paletteG)) + ((pixBlue-paletteB)*(pixBlue-paletteB) )) #print("Pixel " + str(pixelNumber) + ": " + str(distance) + " ,Alpha: " + str(pixAlpha) ) #taking the distance and comparing it to previous "round" temporaryDistance = distance temporaryID = z #print("temporaryID is ..." + str(temporaryID) ) #declare new winner if it's shorter distance if temporaryDistance < winnerDistance: winnerDistance = temporaryDistance winnerID = temporaryID #print("new winner is ..." + str(winnerID) + "!!!") #compare input RGB channels and output highest value if pixRed >= pixGreen and pixRed >= pixBlue: highestValue = pixRed if pixGreen >= pixRed and pixGreen >= pixBlue: highestValue = pixGreen if pixBlue >= pixRed and pixBlue >= pixGreen: highestValue = pixBlue # set color offset +/- based on colour value if highestValue < 128: negation = -1 colorOffset = colorOffset * negation #print("colorOffset is ... " + str(colorOffset) ) #final color changed by colorOffset finalColor = p[winnerID - colorOffset] finalR = finalColor[0] finalG = finalColor[1] finalB = finalColor[2] #finalAlpha taken from the if output above palette colour comparing #put the final pixel into the output picture imageOutput.putpixel((x,y),(finalR,finalG,finalB,finalAlpha)) #print("Pixel " + str(pixelNumber) + ": R= " + str(finalR) + ", G= " + str(finalG) + ", B= " + str(finalB) + ", A= " + str(finalAlpha) ) os.makedirs(outputFolder, exist_ok = True) imageOutput.save(outputFolder + inputImage + "_8bpp.png") def run(): rgb2palette("BRIDGES_", "0000") import traceback try: run() except Exception as e: traceback.print_exc() input("Press enter to continue...")
Mark as private
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
forever