[bb] 16-bit Image Correction by Myke-P [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:43

Previous topic - Next topic

BlitzBot

Title : 16-bit Image Correction
Author : Myke-P
Posted : 1+ years ago

Description : Y'know the score. You've got a lovely gradient background that looks crap and blotchy all of a sudden when Blitz chooses 16-bit mode. Here's a technique to overcome that in many circumstances:

First of all, you've got a bit of manual work to do. Nothing *too* complex though:

1. Load your image into PSP or equivalent.
2. Reduce colours to 64K (*with dither* for smoothness)
3. Save your image as a new .BMP
4. Finally, process the new BMP with the following code:

Use the output image in Blitz and - fingers crossed - it looks much better! :)


Code :
Code (blitzbasic) Select
Graphics 640,480,32,2
Const sourcefile$ = "C:processinputimage.bmp"
Const outputfile$ = "C:processoutputimage.bmp"

starttime = MilliSecs()
Image_16bitCorrect(sourcefile$,outputfile$)
SetBuffer FrontBuffer()
endtime = MilliSecs()
Text 0,0,"That took " + (endtime-starttime)
WaitKey()
End

Function Image_16bitCorrect(filein$,fileout$)
source = LoadImage(filein$)
SetBuffer ImageBuffer(source)
LockBuffer()
For j = 0 To ImageWidth(source)-1
For k = 0 To ImageHeight(source)-1
col = ReadPixelFast(j,k) And $FFFFFF
redlevel# = (col Shr 16) And $FF
greenlevel# = (col Shr 8) And $FF
bluelevel# = col And $FF
redlevel# = Int(redlevel#/8)*8
If Int(redlevel#) = 256 Then
redlevel# = 248
End If
greenlevel# = Int(greenlevel#/8)*8
If Int(greenlevel#) = 256 Then
greenlevel# = 248
End If
bluelevel# = Int(bluelevel#/8)*8
If Int(bluelevel#) = 256 Then
bluelevel# = 248
End If
argb = (Int(bluelevel) Or (Int(greenlevel) Shl 8) Or (Int(redlevel) Shl 16) Or (255 Shl 24))
WritePixelFast j,k,argb
Next
Next
UnlockBuffer()
SaveBuffer(ImageBuffer(source),fileout$)
FreeImage source
End Function


Comments : none...