November 30, 2020, 01:16:46 AM

Author Topic: [bb] 16-bit Image Correction by Myke-P [ 1+ years ago ]  (Read 641 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] 16-bit Image Correction by Myke-P [ 1+ years ago ]
« on: June 29, 2017, 12:28:43 AM »
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
  1. Graphics 640,480,32,2
  2. Const sourcefile$ = "C:processinputimage.bmp"
  3. Const outputfile$ = "C:processoutputimage.bmp"
  4.  
  5. starttime = MilliSecs()
  6. Image_16bitCorrect(sourcefile$,outputfile$)
  7. SetBuffer FrontBuffer()
  8. endtime = MilliSecs()
  9. Text 0,0,"That took " + (endtime-starttime)
  10. WaitKey()
  11. End
  12.  
  13. Function Image_16bitCorrect(filein$,fileout$)
  14.         source = LoadImage(filein$)
  15.         SetBuffer ImageBuffer(source)
  16.         LockBuffer()
  17.         For j = 0 To ImageWidth(source)-1
  18.                 For k = 0 To ImageHeight(source)-1
  19.                         col = ReadPixelFast(j,k) And $FFFFFF
  20.                         redlevel# = (col Shr 16) And $FF
  21.                         greenlevel# = (col Shr 8) And $FF
  22.                         bluelevel# = col And $FF
  23.                         redlevel# = Int(redlevel#/8)*8
  24.                         If Int(redlevel#) = 256 Then
  25.                                 redlevel# = 248
  26.                         End If
  27.                         greenlevel# = Int(greenlevel#/8)*8
  28.                         If Int(greenlevel#) = 256 Then
  29.                                 greenlevel# = 248
  30.                         End If
  31.                         bluelevel# = Int(bluelevel#/8)*8
  32.                         If Int(bluelevel#) = 256 Then
  33.                                 bluelevel# = 248
  34.                         End If
  35.                         argb = (Int(bluelevel) Or (Int(greenlevel) Shl 8) Or (Int(redlevel) Shl 16) Or (255 Shl 24))
  36.                         WritePixelFast j,k,argb
  37.                 Next
  38.         Next
  39.         UnlockBuffer()
  40.         SaveBuffer(ImageBuffer(source),fileout$)
  41.         FreeImage source
  42. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal