Comments (7)
Sidenote: bmploader.bmx contains Import BRL.StbImageLoader
but seems not to use anything from it.
from brl.mod.
Hiya,
I just had a quick look at this issue ( having a break at work ) and I can see a couple of candidates for the problem.
- It looks like the 16bit and 32bit images are using compression mode 3. It looks like stb_image won't load those as the algo is quoted as being undocumented? [stbimage.mod/stb/stb_mage.h line 5108]
- Using the brl.bmploader it doesn't support 16bit images at all.
- brl.bmploader doesn't do anything related to the compression parameter at all.
The 24bit image isn't using compression.
I'd suspect, if you can, to remove compression on those bmp images that have it?
There are still more issues to investigate as the 24bit image doesn't load cleanly either.
from brl.mod.
It looks like the 16bit and 32bit images are using compression mode 3. It looks like stb_image won't load those as the algo is quoted as being undocumented? [stbimage.mod/stb/stb_mage.h line 5108]
Saying that I had a quick look via wikipedia https://en.wikipedia.org/wiki/BMP_file_format#Compression and found a link at the bottom to this page http://www.kalytta.com/bitmap.h and it looks to accept compression mode 3 ( bitfields ).
Maybe that would be worth implementing in the brl.bmploader?
from brl.mod.
It looks as though the bmp format loader could be a complete little project on its own
https://msdn.microsoft.com/en-us/library/windows/desktop/dd183386(v=vs.85).aspx
from brl.mod.
Yeah, that looks like fun.
I wonder if its worth adding RLE support to stbimage...
from brl.mod.
Certainly does looks 'interesting' eh.
I dont mind having a go at implementing it in to the brl.bmploader if you wanted to look at the modifying the stb implementation... to see which works out for the better?
from brl.mod.
I don't think i've seen RLE output from a paint program?
This is a little fixup to allow (sRGB) images - the ones failing in the OP.
@GWRon
Maybe you could also try with various other bmp formats that your paint app outputs before Brucey decides whether or not to include this code?
SuperStrict
Rem
bbdoc: Graphics/BMP loader
about:
The BMP loader module provides the ability to load BMP format #pixmaps.
End Rem
Module BRL.BMPLoader
ModuleInfo "Version: 1.07"
ModuleInfo "Author: Simon Armstrong"
ModuleInfo "License: zlib/libpng"
ModuleInfo "Copyright: Blitz Research Ltd"
ModuleInfo "Modserver: BRL"
ModuleInfo "History: 1.07 Release"
ModuleInfo "History: Added 32 bit alpha support"
ModuleInfo "History: 1.06 Release"
ModuleInfo "History: Fixed inverted 1 bit bitmaps"
ModuleInfo "History: 1.05 Release"
ModuleInfo "History: Fixed palettized bitmaps failing when biClrUsed=0"
Import BRL.Pixmap
Import BRL.EndianStream
Type TPixmapLoaderBMP Extends TPixmapLoader
Method LoadPixmap:TPixmap( stream:TStream )
stream=LittleEndianStream( stream )
Local line:Int[],palette:Int[],pix:Byte[],buf:Byte[64]
Local pixmap:TPixmap
Local hsize:Int,hoffset:Int,pad:Int
Local size:Int,width:Int,height:Int
Local planes:Int,bits:Int,compression:Int,isize:Int,xpels:Int,ypels:Int,COLS:Int,inuse:Int
Local w:Int,x:Int,y:Int,c0:Int,c1:Int,p:Int
Local maskr:Int, maskg:Int, maskb:Int, maska:Int
If stream.ReadBytes( buf,2 )=2
If buf[0]=Asc("B") And buf[1]=Asc("M")
hsize=ReadInt(stream)
pad=ReadInt(stream)
hoffset=ReadInt(stream)
size=ReadInt(stream)
width=ReadInt(stream)
height=ReadInt(stream)
planes=ReadShort(stream)
bits=ReadShort(stream)
compression=ReadInt(stream)
isize=ReadInt(stream)
xpels=ReadInt(stream)
ypels=ReadInt(stream)
COLS=ReadInt(stream)
inuse=ReadInt(stream)
maskr=ReadInt(stream)
maskg=ReadInt(stream)
maskb=ReadInt(stream)
maska=ReadInt(stream)
' set the stream to the data area
SeekStream(stream, hoffset)
If Not COLS COLS=1 Shl bits
If bits=32
pixmap=TPixmap.Create( width,height,PF_BGRA8888 )
Else
pixmap=TPixmap.Create( width,height,PF_BGR888 )
EndIf
Select bits
Case 1
c0=ReadInt(stream)
c1=ReadInt(stream)
w=(width+7)/8
w=(w+3)&$fffc
pix=New Byte[w]
For y=height-1 To 0 Step -1
stream.ReadBytes(pix,w)
For x=0 Until width
If pix[x Shr 3]&(128 Shr (x&7))
ConvertPixels(Varptr c1,PF_BGR888,pixmap.pixelptr(x,y),pixmap.format,1)
Else
ConvertPixels(Varptr c0,PF_BGR888,pixmap.pixelptr(x,y),pixmap.format,1)
EndIf
Next
Next
Case 4
palette=New Int[16]
line=New Int[width]
stream.ReadBytes(palette,COLS*4)
w=(width+1)/2
w=(w+3)&$fffc
pix=New Byte[w]
For y=height-1 To 0 Step -1
stream.ReadBytes(pix,w)
For x=0 Until width
p=(pix[x Shr 1]Shr((1-x&1)*4))&15
line[x]=palette[p]
Next
ConvertPixels(line,PF_BGRA8888,pixmap.pixelptr(0,y),pixmap.format,width)
Next
Case 8
palette=New Int[256]
line=New Int[width]
stream.ReadBytes(palette,COLS*4)
w=(width+3)&$fffc
pix=New Byte[w]
For y=height-1 To 0 Step -1
stream.ReadBytes(pix,w)
For x=0 Until width
line[x]=palette[pix[x]&255]
Next
ConvertPixels(line,PF_BGRA8888,pixmap.pixelptr(0,y),pixmap.format,width)
Next
Case 16
' convert to 24bit
If compression = 3 ' sRGB
' calculate maskshift
Local maskrshift:Int, maskgshift:Int, maskbshift:Int
Local rbScale:Float
Local gScale:Float
' 5 - 5 - 5
If (maskr & $7c00 = $7c00) And (maskg & $03e0 = $03e0) And (maskb & $001f = $001f)
maskrshift = 10
maskgshift = 5
maskbshift = 0
' scale back up to range 0 to 255
rbScale = 255.0 / 31.0
gScale = rbScale
EndIf
' 5 - 6 - 5
If (maskr & $f800 = $f800) And (maskg & $07e0 = $07e0) And (maskb & $001f = $001f)
maskrshift = 11
maskgshift = 5
maskbshift = 0
' scale to range 0 to 255
rbScale = 255.0 / 31.0
gScale = 255.0 / 63.0
EndIf
w=width*3
w=(w+3)&$fffc
For y=height-1 To 0 Step -1
Local pixwidth:Int = ((width*2)+4) & $fffc
pix=New Byte[w]
Local pixin:Short[pixwidth/2]
stream.ReadBytes(pixin, pixwidth)
For x=0 Until width
pix[x * 3 + 0] = ((pixin[x] & maskr) Shr maskrshift) * rbScale
pix[x * 3 + 1] = ((pixin[x] & maskg) Shr maskgshift) * gScale
pix[x * 3 + 2] = (pixin[x] & maskb Shr maskbshift) * rbScale
Next
ConvertPixels(pix,PF_RGB888,pixmap.pixelptr(0,y),pixmap.format,width)
Next
EndIf
Case 24
w=width*3
w=(w+3)&$fffc
pix=New Byte[w]
For y=height-1 To 0 Step -1
stream.ReadBytes(pix,w)
ConvertPixels(pix,PF_BGR888,pixmap.pixelptr(0,y),pixmap.format,width)
Next
Case 32
w=width*4
pix=New Byte[w]
For y=height-1 To 0 Step -1
stream.ReadBytes(pix,w)
ConvertPixels(pix,PF_BGRA8888,pixmap.pixelptr(0,y),pixmap.format,width)
If compression = 3
If maskr = $ff000000 And..
maskg = $00ff0000 And..
maskb = $0000ff00 And..
maska = $000000ff
' quick code to move alpha channel to other end.
' could have 10bits for RGB and 2 bit spare
' gpus support 10bits per channel but that means
' adding in full support across blitzmax drivers
Local ppixel:Int Ptr = pixmap.pixelptr(0,y)
For x = 0 Until width
Local b:Int = ppixel[x] & $ff000000
Local g:Int = ppixel[x] & $00ff0000
Local r:Int = ppixel[x] & $0000ff00
Local a:Int = ppixel[x] & $000000ff
ppixel[x] = a Shl 24
ppixel[x] :| (r Shr 8)
ppixel[x] :| (g Shr 8)
ppixel[x] :| (b Shr 8)
Next
EndIf
EndIf
Next
Default
pixmap=Null
End Select
Return pixmap
EndIf
EndIf
End Method
End Type
New TPixmapLoaderBMP
from brl.mod.
Related Issues (20)
- [brl.graphics] Duplicate use of Graphics() flag IDs
- [Brl.Socket] AF_UNSPEC_ usage in docs is wrong
- Some undefined behavior found in bbMilliSecs()
- brl.TStringbuilder; extended startsWith() HOT 1
- [graphics.mod] TGraphics.Resize() and .Position() only stubs HOT 2
- [blitz.mod] Expose MemSet() or extend MemClear() to allow specific values
- [gnet.mod] Handle invalid peer events and disconnect timeout
- io.mod/common.bmx identifier FromEpoch not found HOT 2
- Unhandled Exception:GNet error, ENET_EVENT_TYPE_RECEIVE with invalid peer HOT 6
- [glGraphics.mod] MacOS: Carbon API deprecated / not supported
- Issues with 'library callbacks' with a potential solution HOT 2
- [platform.mod] PhysicalProcessorCount() not working properly on Win32 HOT 3
- StackTrace path issue HOT 1
- add FileExists function or use FileSize =-1? also, one other thing HOT 2
- Memory leaks (bbMemAlloc & bbMemFree) HOT 10
- [brl.pixmap] Handling "noDebug" - with still catching "null objects"
- [blitz.mod] Debug builds: GCSuspend/GCResume for each "local block"
- [blitz.mod] Debug builds secretly reactivate the GC even once GCSuspend()-ed HOT 7
- [random.mod] Add Rand() overloads to support "float/double" too? HOT 2
- [map.mod] Single method to retrieve value and existence of passed key HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from brl.mod.