|
Полезные функции Выкладываем полезные функции, чтоб не изобретать велосипед заново... |
15.02.2008, 16:04
|
#1
|
Зануда с интернетом
Регистрация: 04.09.2005
Сообщений: 14,014
Написано 6,798 полезных сообщений (для 20,935 пользователей)
|
ImageFromBank
Function ImageFromBank%(BANK%)
;impersonalis
;функция загрузки картинки (24BPP без сжатия)
;-----------------------------------------------
;неоптимизированный прототип (http://forum.boolean.name/showthread.php?t=1196
;http://www.freecoder.chat-blitz.de/viewtopic.php?t=290)
;------------------------------------------------------
Local ReadIndex%
Local bfType%
Local bfSize%
Local bfReserved%
Local bfOffBits%
Local biSize%
Local biWidth%
Local biHeight%
Local biPlanes%
Local biBitCount%
Local biCompression%
Local biSizeImage%
Local biXPelsPerMeter%
Local biYPelsPerMeter%
Local biClrUsed%
Local biClrImportant%
Local biMaskRed%
Local biMaskGreen%
Local biMaskBlue%
Local biDown%
Local ClrTable%[256]
Local tmp
Local tmp2
Local pixel
Local rgb
Local BetweenStringSpace%
Local img
;----------------------- Bitmap Header
ReadIndex=0
bfType%=PeekShort(BANK,ReadIndex)
ReadIndex=ReadIndex+2
bfSize%=PeekInt(BANK,ReadIndex)
ReadIndex=ReadIndex+4
bfReserved%=PeekInt(BANK,ReadIndex)
ReadIndex=ReadIndex+4
bfOffBits%=PeekInt(BANK,ReadIndex)
ReadIndex=ReadIndex+4
;-----------------------
If bfType% <> 19778 Then RuntimeError("Error: File ist not a valid Windows Bitmap(.bmp)")
;----------------------- Bitmap InfoHeader
biSize%= PeekInt(BANK,ReadIndex)
ReadIndex=ReadIndex+4
biWidth%=PeekInt(BANK,ReadIndex)
ReadIndex=ReadIndex+4
biHeight%=PeekInt(BANK,ReadIndex)
ReadIndex=ReadIndex+4
biPlanes%=PeekShort(BANK,ReadIndex)
ReadIndex=ReadIndex+2
biBitCount%=PeekShort(BANK,ReadIndex)
ReadIndex=ReadIndex+2
biCompression%=PeekInt(BANK,ReadIndex)
ReadIndex=ReadIndex+4
biSizeImage%=PeekInt(BANK,ReadIndex)
ReadIndex=ReadIndex+4
biXPelsPerMeter%=PeekInt(BANK,ReadIndex)
ReadIndex=ReadIndex+4
biYPelsPerMeter%=PeekInt(BANK,ReadIndex)
ReadIndex=ReadIndex+4
biClrUsed%=PeekInt(BANK,ReadIndex)
ReadIndex=ReadIndex+4
biClrImportant%=PeekInt(BANK,ReadIndex)
ReadIndex=ReadIndex+4
If biHeight%>0 Then biDown%=0
If biHeight%<0 Then biDown%=1
;---------------------- evt. Farbmasken
If biCompression%=3 Then
biMaskBlue%=PeekInt(BANK,ReadIndex)
ReadIndex=ReadIndex+4
biMaskGreen%=PeekInt(BANK,ReadIndex)
ReadIndex=ReadIndex+4
biMaskBlue%=PeekInt(BANK,ReadIndex)
ReadIndex=ReadIndex+4
EndIf
;---------------------- FarbTabellen
If biClrUsed%=0 Then
If biBitCount%=1 Or biBitCount%=4 Or biBitCount%=8 Then
For tmp=0 To 2^biBitCount%
ClrTable[tmp] =PeekInt(BANK,ReadIndex)
ReadIndex=ReadIndex+4
Next
EndIf
EndIf
;---------------------- BildDaten
BetweenStringSpace=((BankSize(BANK)-ReadIndex)-biWidth*biHeight*3)/Float(biHeight)
img=CreateImage( biWidth%,biHeight% )
;DebugLog biWidth%+" x "+biHeight%+" BPP="+biBitCount
;DebugLog BetweenStringSpace
SetBuffer ImageBuffer(img)
If biCompression%=0 Then ; BI-RGB
If biBitCount% = 1 Then
RuntimeError "Sorry, non-supported value of BPP ("+biBitCount+")"
ElseIf biBitCount% = 4
RuntimeError "Sorry, non-supported value of BPP ("+biBitCount+")"
ElseIf biBitCount% = 8
RuntimeError "Sorry, non-supported value of BPP ("+biBitCount+")"
ElseIf biBitCount% = 16
RuntimeError "Sorry, non-supported value of BPP ("+biBitCount+")"
ElseIf biBitCount% = 24 Then
If biDown% = 0 Then
LockBuffer ImageBuffer(img)
For tmp2=biHeight%-1 To 0 Step -1
For tmp=0 To biWidth%-1
blue=PeekByte(BANK,ReadIndex)
ReadIndex=ReadIndex+1
green=PeekByte(BANK,ReadIndex)
ReadIndex=ReadIndex+1
red=PeekByte(BANK,ReadIndex)
ReadIndex=ReadIndex+1
rgb=255*$1000000 + red*$10000 + green*$100 + blue
WritePixelFast tmp,tmp2,rgb
Next
ReadIndex=ReadIndex+BetweenStringSpace
Next
UnlockBuffer ImageBuffer(img)
ElseIf biDown%=1 Then
LockBuffer ImageBuffer(img)
For tmp2=0 To biHeight%-1
For tmp=0 To biWidth%-1
blue=PeekByte(BANK,ReadIndex)
ReadIndex=ReadIndex+1
green=PeekByte(BANK,ReadIndex)
ReadIndex=ReadIndex+1
red=PeekByte(BANK,ReadIndex)
ReadIndex=ReadIndex+1
rgb=255*$1000000 + red*$10000 + green*$100 + blue
WritePixelFast tmp,tmp2,rgb
Next
ReadIndex=ReadIndex+BetweenStringSpace
Next
UnlockBuffer ImageBuffer(img)
EndIf
ElseIf BiBitCount% = 32
RuntimeError "Sorry, non-supported value of BPP ("+biBitCount+")"
EndIf
ElseIf biCompression%=1 ; BI-RLE8
RuntimeError "Sorry, non-supported value of Compression (BI-RLE8)"
ElseIf biCompression%=2 ; BI-RLE4
RuntimeError "Sorry, non-supported value of Compression (BI-RLE4)"
ElseIf biCompression%=3 ; BI-BITFIELD
RuntimeError "Sorry, non-supported value of Compression (BI-BITFIELD)"
EndIf
SetBuffer BackBuffer()
Return img
End Function
;--- demo code
Graphics 800,600,32
name$="Imper.bmp"
size=FileSize(name)
bank=CreateBank(size)
file=OpenFile(name)
ReadBytes(bank,file,0,size-1)
CloseFile file
image=ImageFromBank(bank)
DrawImage image,0,0
Flip
__________________
http://nabatchikov.com
Мир нужно делать лучше и чище. Иначе, зачем мы живем? tormoz
А я растила сына на преданьях
о принцах, троллях, потайных свиданьях,
погонях, похищениях невест.
Да кто же знал, что сказка душу съест?
|
(Offline)
|
|
Эти 4 пользователя(ей) сказали Спасибо impersonalis за это полезное сообщение:
|
|
17.09.2008, 17:41
|
#2
|
AnyKey`щик
Регистрация: 12.09.2008
Сообщений: 8
Написано 0 полезных сообщений (для 0 пользователей)
|
Ответ: ImageFromBank
А У тебя есть функция для загрузки картинки в формате (jpg или в каком нибудь другом) ? Очень Нужно !
|
(Offline)
|
|
Ваши права в разделе
|
Вы не можете создавать темы
Вы не можете отвечать на сообщения
Вы не можете прикреплять файлы
Вы не можете редактировать сообщения
HTML код Выкл.
|
|
|
Часовой пояс GMT +4, время: 08:52.
|