Created
October 10, 2015 22:49
-
-
Save udf/57967a3c2717606e93da to your computer and use it in GitHub Desktop.
Lego colour thing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <GDIPlus.au3> | |
#include <Color.au3> | |
_GDIPlus_Startup() | |
Global $hBaseTile = _GDIPlus_ImageLoadFromFile("t.png") | |
Global Const $TILE_SIZE = _GDIPlus_ImageGetWidth($hBaseTile) | |
Global $hInput = _GDIPlus_ImageLoadFromFile("in.png") | |
Global Const $iW = _GDIPlus_ImageGetWidth($hInput), $iH = _GDIPlus_ImageGetHeight($hInput) | |
Global $hOutput = _GDIPlus_BitmapCreateFromScan0($iW*$TILE_SIZE, $iH*$TILE_SIZE) | |
Global $hGraphics = _GDIPlus_ImageGetGraphicsContext($hOutput) | |
For $iX = 0 To $iW-1 | |
For $iY = 0 To $iH-1 | |
$iColour = _GDIPlus_BitmapGetPixel($hInput, $iX, $iY) | |
$hNew = _GetTile(_ColorGetRed($iColour), _ColorGetGreen($iColour), _ColorGetBlue($iColour)) | |
_GDIPlus_GraphicsDrawImage($hGraphics, $hNew, $iX*$TILE_SIZE, $iY*$TILE_SIZE) | |
_GDIPlus_BitmapDispose($hNew) | |
Next | |
Next | |
_GDIPlus_ImageDispose($hInput) | |
_GDIPlus_GraphicsDispose($hGraphics) | |
_GDIPlus_ImageSaveToFile($hOutput, "out.png") | |
_GDIPlus_ImageDispose($hOutput) | |
Func _GetTile($nR, $nG, $nB) | |
$hEffect = _GDIPlus_EffectCreateColorBalance(_CMap($nR), _CMap($nG), _CMap($nB)) | |
Local $hNew = _GDIPlus_BitmapCreateApplyEffect($hBaseTile, $hEffect) | |
_GDIPlus_EffectDispose($hEffect) | |
Return $hNew | |
EndFunc | |
Func _CMap($n) | |
Return _Map($n, 0, 255, -75, 100) | |
EndFunc | |
Func _Map($nVar, $nMin1, $nMax1, $nMin2, $nMax2) | |
Return $nMin2 + ($nMax2 - $nMin2) * (($nVar - $nMin1) / ($nMax1 - $nMin1)) | |
EndFunc ;==>_Map | |
Func C($s) | |
Return ConsoleWrite($s & @CRLF) | |
EndFunc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment