瀏覽代碼

BMP and TGA image loaders moved to Image namespace.

Brucey 3 年之前
父節點
當前提交
43d0b2490e
共有 4 個文件被更改,包括 10 次插入511 次删除
  1. 5 135
      bmploader.mod/bmploader.bmx
  2. 0 28
      stbimageloader.mod/glue.c
  3. 0 125
      stbimageloader.mod/stbimageloader.bmx
  4. 5 223
      tgaloader.mod/tgaloader.bmx

+ 5 - 135
bmploader.mod/bmploader.bmx

@@ -1,135 +1,5 @@
-
-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.StbImageLoader
-
-Import BRL.Pixmap
-Import BRL.EndianStream
-
-Type TPixmapLoaderBMP Extends TPixmapLoader
-
-	Method LoadPixmap:TPixmap( stream:TStream ) Override
-
-		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
-
-		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)
-				hoffset:-54
-				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 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)
-						Next
-					Default
-						pixmap=Null
-				End Select
-				Return pixmap
-			EndIf
-		EndIf
-	End Method
-
-End Type
-
-New TPixmapLoaderBMP
+SuperStrict
+
+Module BRL.BMPLoader
+
+Import Image.BMP

+ 0 - 28
stbimageloader.mod/glue.c

@@ -1,28 +0,0 @@
-
-#include "pub.mod/stbimage.mod/stb/stb_image.h"
-
-#include "brl.mod/blitz.mod/blitz.h"
-
-#ifdef BMX_NG
-#define CB_PREF(func) func
-#else
-#define CB_PREF(func) _##func
-#endif
-
-
-int CB_PREF(brl_stbimageloader_TStbioCallbacks__Read)(BBObject * cb, char * data,int size);
-void CB_PREF(brl_stbimageloader_TStbioCallbacks__Skip)(BBObject * cb, int n);
-int CB_PREF(brl_stbimageloader_TStbioCallbacks__Eof)(BBObject * cb);
-
-
-
-stbi_uc * bmx_stbi_load_image(BBObject * cb, int * width, int * height, int * channels) {
-
-	stbi_io_callbacks callbacks;
-	callbacks.read = brl_stbimageloader_TStbioCallbacks__Read;
-	callbacks.skip = brl_stbimageloader_TStbioCallbacks__Skip;
-	callbacks.eof = brl_stbimageloader_TStbioCallbacks__Eof;
-
-	return stbi_load_from_callbacks(&callbacks, cb, width, height, channels, 0);
-
-}

+ 0 - 125
stbimageloader.mod/stbimageloader.bmx

@@ -1,125 +0,0 @@
-SuperStrict
-
-Rem
-bbdoc: Graphics/Stb Image loader
-about:
-The stb image loader module provides the ability to load different image format #pixmaps.
-Supported formats include, BMP, PSD, TGA, GIF, HDR, PIC and PNM
-End Rem
-Module BRL.StbImageLoader
-
-ModuleInfo "Version: 1.00"
-ModuleInfo "Author: Bruce A Henderson"
-ModuleInfo "License: zlib/libpng"
-ModuleInfo "Copyright: Bruce A Henderson"
-
-ModuleInfo "History: 1.00"
-ModuleInfo "History: Initial Release."
-
-Import Pub.StbImage
-Import BRL.Pixmap
-
-Import "glue.c"
-
-
-Extern
-
-	Function bmx_stbi_load_image:Byte Ptr(cb:Object, width:Int Ptr, height:Int Ptr, channels:Int Ptr)
-
-End Extern
-
-
-Type TPixmapLoaderSTB Extends TPixmapLoader
-
-	Method LoadPixmap:TPixmap( stream:TStream ) Override
-	
-		Local pixmap:TPixmap
-	
-		Local cb:TStbioCallbacks = New TStbioCallbacks
-		cb.stream = stream
-		
-		Local width:Int, height:Int, channels:Int
-		
-		Local imgPtr:Byte Ptr = bmx_stbi_load_image(cb, Varptr width, Varptr height, Varptr channels)
-		
-		If imgPtr Then
-		
-			Local pf:Int
-		
-			Select channels
-				Case STBI_grey
-					pf = PF_I8
-				Case STBI_rgb
-					pf = PF_RGB888
-				Case STBI_rgb_alpha
-					pf = PF_RGBA8888
-				Case STBI_grey_alpha
-					pixmap = CreatePixmap( width,height,PF_RGBA8888 )
-					
-					Local src:Byte Ptr = imgPtr
-					Local dst:Byte Ptr = pixmap.pixels
-
-					For Local y:Int = 0 Until height
-						For Local x:Int = 0 Until width
-							Local a:Int=src[0]
-							Local i:Int=src[1]
-							dst[0] = i
-							dst[1] = i
-							dst[2] = i
-							dst[3] = a
-							src:+2
-							dst:+4
-						Next
-					Next
-			End Select
-			
-			
-			
-			If pf
-				pixmap = CreatePixmap( width, height, pf )
-
-				MemCopy(pixmap.pixels, imgPtr, Size_T(width * height * BytesPerPixel[pf]))
-			End If
-			
-			stbi_image_free(imgPtr)
-		
-		End If
-	
-		Return pixmap
-		
-	End Method
-
-End Type
-
-
-Type TStbioCallbacks
-
-	Field stream:TStream
-	
-	Method Read:Int(buffer:Byte Ptr, size:Int)
-		Return stream.Read(buffer, size)
-	End Method
-	
-	Method Skip(n:Int)
-		stream.Seek(SEEK_CUR_, n)
-	End Method
-	
-	Method Eof:Int()
-		Return stream.Eof()
-	End Method
-
-	Function _Read:Int(cb:TStbioCallbacks, buffer:Byte Ptr, size:Int) { nomangle }
-		Return cb.Read(buffer, size)
-	End Function
-
-	Function _Skip(cb:TStbioCallbacks, n:Int) { nomangle }
-		cb.Skip(n)
-	End Function
-
-	Function _Eof:Int(cb:TStbioCallbacks) { nomangle }
-		Return cb.Eof()
-	End Function
-	
-End Type
-
-New TPixmapLoaderSTB

+ 5 - 223
tgaloader.mod/tgaloader.bmx

@@ -1,223 +1,5 @@
-
-Strict
-
-Rem
-bbdoc: Graphics/TGA loader
-about:
-The TGA loader module provides the ability to load TGA format #pixmaps.
-End Rem
-Module BRL.TGALoader
-
-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: Fixed memory error due to pointer based array reference"
-ModuleInfo "History: 1.06 Release"
-ModuleInfo "History: Support for Run Length Encoded compression"
-ModuleInfo "History: 1.05 Release"
-ModuleInfo "History: Fixed 24 bit byte ordering"
-
-Import BRL.StbImageLoader
-
-?deprecated
-Import BRL.Pixmap
-Import BRL.EndianStream
-
-Const TGA_NULL=0
-Const TGA_MAP=1
-Const TGA_RGB=2
-Const TGA_MONO=3
-Const TGA_RLEMAP=9
-Const TGA_RLERGB=10
-Const TGA_RLEMONO=11
-Const TGA_COMPMAP=32
-Const TGA_COMPMAP4=33
-
-Type tgahdr
-	Field	idlen:Byte,colourmaptype:Byte,imgtype:Byte,indexlo:Byte,indexhi:Byte,lenlo:Byte,lenhi:Byte,cosize:Byte
-	Field	x0:Short,y0:Short,width:Short,height:Short
-	Field	psize:Byte,attbits:Byte
-End Type
-
-Function makeargb(a,r,g,b)
-'?BigEndian
-'	Return (b Shl 24)|(g Shl 16)|(r Shl 8)|a
-'?
-	Return (a Shl 24)|(r Shl 16)|(g Shl 8)|b
-End Function
-
-Type TPixmapLoaderTGA Extends TPixmapLoader
-
-	Method LoadPixmap:TPixmap( stream:TStream )
-		Local	hdr:tgahdr		
-		Local	w,h,tgatype,bits
-		Local	buffer[]
-		Local	sbuffer:Short[]
-		Local	bbuffer:Byte[]
-		Local	i,x,y,t,a
-		Local	pixmap:TPixmap
-		
-		stream=LittleEndianStream( stream )	
-		hdr=New tgahdr
-		If stream.ReadBytes( hdr,8 )<>8 Return Null
-		hdr.x0=stream.ReadShort()
-		hdr.y0=stream.ReadShort()
-		hdr.width=stream.ReadShort()
-		hdr.height=stream.ReadShort()
-		hdr.psize=stream.ReadByte()
-		hdr.attbits=stream.ReadByte()
-
-		bits=hdr.psize
-		w=hdr.width
-		h=hdr.height
-		tgatype=hdr.imgtype
-
-		If hdr.colourmaptype Return Null
-		If Not (tgatype=TGA_MAP Or tgatype=TGA_RGB Or tgatype=TGA_RLERGB) Return Null
-		If Not (bits=15 Or bits=16 Or bits=24 Or bits=32) Return Null
-		If w<1 Or w>4096 Return Null
-		If h<1 Or h>4096 Return Null
-
-		If bits=16 Or bits=32
-			pixmap=CreatePixmap( w,h,PF_RGBA8888)
-		Else
-			pixmap=CreatePixmap( w,h,PF_RGB888)
-		EndIf
-
-		For i=1 To hdr.idlen
-			stream.ReadByte
-		Next
-
-		buffer=New Int[w]
-		bbuffer=New Byte[w*3]
-
-		Select tgatype
-			Case TGA_RGB
-				For y=h-1 To 0 Step -1
-					Select bits
-						Case 15
-							For x=0 Until w
-								t=stream.ReadShort()
-								buffer[x]=makeargb(255,(t Shr 7)&$f8,(t Shr 2)&$f8,(t Shl 3)&$f8)
-							Next
-						Case 16
-							For x=0 Until w
-								t=stream.ReadShort()
-								a=255
-								If (t&$8000) a=0
-								buffer[x]=makeargb(a,(t Shr 7)&$f8,(t Shr 2)&$f8,(t Shl 3)&$f8)
-							Next
-						Case 24
-							stream.readbytes(bbuffer,w*3)
-							For x=0 Until w
-								buffer[x]=makeargb(255,bbuffer[x*3+2],bbuffer[x*3+1],bbuffer[x*3+0])
-							Next
-						Case 32
-							stream.readbytes(buffer,w*4)
-					End Select
-					ConvertPixels(buffer,PF_BGRA8888,pixmap.pixelptr(0,y),pixmap.format,w)
-				Next
-			Case TGA_RLERGB
-				Local	n,argb
-				For y=h-1 To 0 Step -1		
-					x=0
-					Select bits
-						Case 15
-							While x<w
-								n=stream.ReadByte()
-								If n&128
-									n:-127
-									t=stream.ReadShort()
-									argb=makeargb(255,(t Shr 7)&$f8,(t Shr 2)&$f8,(t Shl 3)&$f8)
-									While n
-										buffer[x]=argb
-										n:-1
-										x:+1
-									Wend
-								Else
-									n:+1
-									For i=0 Until n
-										t=stream.ReadShort()
-										buffer[x]=makeargb(255,(t Shr 7)&$f8,(t Shr 2)&$f8,(t Shl 3)&$f8)
-										x:+1
-									Next
-								EndIf
-							Wend
-						Case 16
-							While x<w
-								n=stream.ReadByte()
-								If n&128
-									n:-127
-									t=stream.ReadShort()
-									a=255
-									If (t&$8000) a=0
-									argb=makeargb(a,(t Shr 7)&$f8,(t Shr 2)&$f8,(t Shl 3)&$f8)
-									While n
-										buffer[x]=argb
-										n:-1
-										x:+1
-									Wend
-								Else
-									n:+1
-									For i=0 Until n
-										t=stream.ReadShort()
-										a=255
-										If (t&$8000) a=0
-										buffer[x]=makeargb(a,(t Shr 7)&$f8,(t Shr 2)&$f8,(t Shl 3)&$f8)
-										x:+1
-									Next
-								EndIf
-							Wend
-						Case 24
-							While x<w
-								n=stream.ReadByte()
-								If n&128
-									n:-127
-									stream.readbytes bbuffer,3
-									argb=makeargb(255,bbuffer[2],bbuffer[1],bbuffer[0])
-									While n
-										buffer[x]=argb
-										n:-1
-										x:+1
-									Wend
-								Else
-									n:+1
-									stream.readbytes(bbuffer,n*3)
-									For i=0 Until n
-										buffer[x]=makeargb(255,bbuffer[i*3+2],bbuffer[i*3+1],bbuffer[i*3+0])
-										x:+1
-									Next
-								EndIf
-							Wend
-						Case 32
-							While x<w
-								n=stream.ReadByte()
-								If n&128
-									n:-127
-									stream.readbytes Varptr argb,4
-									While n
-										buffer[x]=argb
-										n:-1
-										x:+1
-									Wend
-								Else
-									n:+1
-									stream.readbytes(Byte Ptr(buffer)+x*4,n*4)
-									x:+n
-								EndIf
-							Wend
-					End Select
-					ConvertPixels(buffer,PF_BGRA8888,pixmap.pixelptr(0,y),pixmap.format,w)
-				Next		
-		End Select
-	
-		Return pixmap
-			
-	End Method
-End Type
-
-New TPixmapLoaderTGA
-?
+SuperStrict
+
+Module BRL.TGALoader
+
+Import Image.TGA