[Nexus 9 Themes and Apps] makers_mark:
@echo off&setlocal enabledelayedexpansion&set "vers=1.6"&title Nexus 9 Splash Tool v!vers!&color 0b&mode con cols=78 lines=45&cls&call :drawhead
set "videofilter="
set "showbeforeflashing=yesure"
set "showbeforerotating="
set "rotatesquares="
set "usedefaultviewer="
if exist "%~dp0sys\log\imageres" del /q "%~dp0sys\log\imageres"
set /a "expected_filesize=6291456"
set /a "aspectmultiplier=100000"
set /a "expected_pixels=%expected_filesize%/2"
set "loglevel=-loglevel debug"
set "hidebanner=-hide_banner"
set "ffmlog=>>"%~dp0sys\log\ffmpeg_log.txt" 2>&1"
if "%~1"=="stock" set "image_file=%~dp0sys\stock_binary\sp1.nb0"&set "base_name=Stock Google Splash Screen"&call :stock
set "image_file=%~1"
if not exist "%image_file%"	call :nofile
if not exist "%~dp0sys\log\" mkdir "%~dp0sys\log"
set "irony="
cd /d "%~dp0"
for %%? in ("%image_file%") do set "base_name=%%~n?"&set "ext=%%~x?"&set "osize=%%~z?"
if /i "%ext%"==".bmp" goto :checkres
if /i "%ext%"==".jpg" goto :checkres
if /i "%ext%"==".jpeg" goto :checkres
if /i "%ext%"==".png" goto :checkres
if /i "%ext%"==".raw" if "%osize%"=="%expected_filesize%" call :fla**** "%image_file%"
if /i "%ext%"==".rgb565" if "%osize%"=="%expected_filesize%" call :fla**** "%image_file%"
if /i "%ext%"==".nb0" if "%osize%"=="%expected_filesize%" call :fla**** "%image_file%"
if not defined irony if "%osize%"=="%expected_filesize%" call :fla**** "%image_file%"
goto :checkres

:checkres
for /f "tokens=1-8* delims=," %%a in ('sys\bin\ffmpeg -i "%image_file%" 2^>^&1^|findstr /rxic:".*stream #0:0.*[0-9][0-9]x[0-9][0-9].*"') do (
echo.%%a >"%~dp0sys\log\imageres"
echo.%%b >>"%~dp0sys\log\imageres"
echo.%%c >>"%~dp0sys\log\imageres"
echo.%%d >>"%~dp0sys\log\imageres"
echo.%%e >>"%~dp0sys\log\imageres"
echo.%%f >>"%~dp0sys\log\imageres"
echo.%%g >>"%~dp0sys\log\imageres"
echo.%%h >>"%~dp0sys\log\imageres"
)
for /f "tokens=1-3 delims=x " %%d in ('type "%~dp0sys\log\imageres"^|findstr /rxic:".*[0-9][0-9]x[0-9][0-9].*"') do (set /a "width=%%d"&set /a "width=!width: =!"&set /a "height=%%e"&set /a "height=!height: =!")
if %width% gtr %height% goto :rotate
if defined rotatesquares if %width% equ %height% goto :rotate
set /a requiredaspect=%aspectmultiplier%*1536/2048
set /a aspectratio=%aspectmultiplier%*%width%/%height%
set /a pixels=%width%*%height%
if %aspectratio% neq %requiredaspect% goto :badresolution
if %pixels% neq %expected_pixels% goto :badresolution
goto :convertit

:badresolution
if "%aspectratio%"=="%requiredaspect%" echo.Auto resizing image.&set "videofilters=-vf "scale=1536:2048""&goto :resize
cls&call :drawhead&echo.&echo. Your image doesn't meet the required resolution of 1536x2048&echo.
:changeaspect
echo. Your image aspect ratio is different from the required 3:4 aspect ratio.&echo.
if %pixels% lss %expected_pixels% echo. Keep in mind that I can make your image bigger, but I can't add detail....
echo. ____________________________________________________________________________&echo. Please choose 1 or 2 and press ENTER&echo.&echo. 1 - Resize it by stretching or shrinking image ^(aspect ratio will change^)&echo. 2 - Keep aspect, but resize and crop ^(aspect ratio will stay the same^)&echo.
set /p ihatexp=?
if "%ihatexp%"=="1" set "videofilters=-vf "scale=1536:2048""&goto :resize
if "%ihatexp%"=="2" (
if %requiredaspect% gtr %aspectratio% set "videofilters=-vf "scale=1536:-1, crop=1536:2048""
if %requiredaspect% lss %aspectratio% set "videofilters=-vf "scale=-1:2048, crop=1536:2048""
goto :resize)
goto :badresolution
:resize
set "out_path=sys\temp"
if not exist "%~dp0%out_path%\" mkdir "%~dp0%out_path%"
%ffmlog%"%~dp0sys\bin\ffmpeg.exe" %hidebanner% %loglevel% -i "%image_file%" %videofilters% -y "%~dp0%out_path%\%base_name%.png"
call "%~dpnx0" "%~dp0%out_path%\%base_name%.png"
goto :convertit

:rotate
:again
cls&call :drawhead&echo.&echo.
echo. The image has to be rotated either left or right.
if defined showbeforerotating if not defined usedefaultviewer echo. CLOSE the image when you are done to continue
echo. Please choose 1 or 2 and press ENTER&echo.
echo. ____________________________________________________________________________
echo. 1 - Rotate Image Left&echo. 2 - Rotate Image Right&echo.
if defined showbeforerotating (
ping -n 3 127.0.0.1> nul
if defined usedefaultviewer start "" "%image_file%"
if not defined usedefaultviewer rundll32 "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen %image_file%
)
set /p "ihatexp= ?"
if "%ihatexp%"=="2" set "videofilters=-vf "transpose=1""&goto :ready
if "%ihatexp%"=="1" set "videofilters=-vf "transpose=2""&goto :ready
goto :again
:ready
set "out_path=sys\temp"
if not exist "%~dp0%out_path%\" mkdir "%~dp0%out_path%"
%ffmlog%"%~dp0sys\bin\ffmpeg.exe" %hidebanner% %loglevel% -i "%image_file%" %videofilters% -y "%~dp0%out_path%\%base_name%.png"
call "%~dpnx0" "%~dp0%out_path%\%base_name%.png"
exit

:convertit
cls&call :drawhead
set "out_path=sys\raw images"
if not exist "%~dp0%out_path%\" mkdir "%~dp0%out_path%"
if exist "%~dp0%out_path%\!base_name!.raw" del /q "%~dp0%out_path%\!base_name!.raw"
echo.&echo. Converting file into a raw 2 byte per pixel rgb565 image..
%ffmlog%"%~dp0sys\bin\ffmpeg.exe" %hidebanner% %loglevel% -i "%image_file%" -f rawvideo -vcodec rawvideo -pix_fmt rgb565 -y "%~dp0%out_path%\!base_name!.raw"
for %%? in ("%~dp0%out_path%\!base_name!.raw") do set /a "out_filesize=%%~z?"
if not "!out_filesize!" == "%expected_filesize%" goto :badsize
call :fla**** "%~dp0%out_path%\%base_name%.raw"
exit

:stock
for %%? in ("%~dp0sys\stock binary\sp1.nb0") do set "out_filesize=%%~z?"
cls&call :drawhead
if exist "%~dp0sys\stock binary\sp1.nb0" echo.&echo. Preparing to flash a binary copy of the stock flash screen.&call :fla**** "%~dp0sys\stock binary\sp1.nb0"
cls&call :drawhead&echo. The stock binary image is missing, please re-download program.
ping -n 4 127.0.0.1> nul
start "" http://xdaforums.com/nexus-9/themes-apps/tool-splash-screen-flasher-v1-0-t2931575/post56561564#post56561564&pause>nul&exit
exit

:fla****
if not "%base_name%"=="Stock Google Splash Screen" if defined showbeforeflashing call :regen "%~1"
cls&call :drawhead&echo. ____________________________________________________________________________&echo.
"%~dp0sys\bin\adb.exe" kill-server&&echo.
echo. Your image is ready to be flashed^!
echo. Press any key to reboot to the bootloader.&&pause>nul&&echo.______________________________________________________________________________&&"%~dp0sys\bin\adb.exe" reboot bootloader&&echo.&&echo.After your bootloader screen shows up, please verify that&&echo.you are in ^"FASTBOOT USB^" mode and press enter to flash the splash image.&&pause>nul
if exist "%~1" (
for %%? in ("%~1") do set /a "out_filesize=%%~z?"
if not "!out_filesize!"=="%expected_filesize%" (goto :badsize
) else ("%~dp0sys\bin\fastboot.exe" flash splash1 "%~1"&&echo.______________________________________________________________________________&&echo.&&echo.&&echo. Done..Press any key to reboot to your new splash screen..&&pause>nul&&"%~dp0sys\bin\fastboot.exe" reboot&&"%~dp0sys\bin\adb.exe" kill-server)
) else (goto :nofile)
rd /s /q "%~dp0\sys\temp"
exit

:regen
set "out_path=sys\temp"
if not exist "%~dp0%out_path%\" mkdir "%~dp0%out_path%"
%ffmlog%"%~dp0sys\bin\ffmpeg.exe" %hidebanner% %loglevel% -f rawvideo -vcodec rawvideo -pix_fmt rgb565 -s 1536x2048 -i "%~1" -y "%~dp0%out_path%\%base_name%_test.png"
echo.&echo. This is what it looks like when it is converted back into a viewable image.
echo. Close the image when you are done to continue&ping -n 4 127.0.0.1> nul
if defined usedefaultviewer start "" "%~dp0%out_path%\%base_name%_test.png"
if not defined usedefaultviewer rundll32 "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen %~dp0%out_path%\%base_name%_test.png

goto :eof

:badsize
cls&call :drawhead&echo.
echo. The image you flash has to be 1536x2048..
echo. The filesize of the raw image in turn would
echo. be %expected_filesize%.&echo.&echo.Your raw image size is !out_filesize!&echo.&echo.&echo. Press Enter to delete file and exit.&pause>nul
del /q "%~dp0%out_path%\!base_name!.raw"&"%~dp0sys\bin\adb.exe" kill-server
exit

:drawhead
echo. __________________________________________________________________________-_-
echo. ____________________________________________________________________________
echo.
echo. Nexus 9 Splash Tool: v%vers% by makers_mark
echo. ____________________________________________________________________________&echo.
if not defined image_file (echo. Loading..............) else (echo. File: "%base_name%%ext%")
if defined width if defined height echo. Resolution: %width%x%height%
if defined out_filesize (echo. Size: %out_filesize%) else (echo. Size: %osize% ^(image hasn't been converted^))
echo. Target Size: %expected_filesize%
echo. ____________________________________________________________________________
echo.
goto :eof

:nofile
cls&call :drawhead&echo.&echo. You have to drag and drop your png, bmp, or jpg file onto&echo.the %~nx0 batch file&echo.&pause>nul&"%~dp0sys\bin\adb.exe" kill-server
exit