Вечером написал процедуру, которую давно собирался написать, так правильнее.
;f$="Big-endian-and-Little-endian-1024x576.png"
f$="PNG_transparency_demonstration_1.png"
fs=FileSize(f$)
If fs>0
*m=AllocateMemory(fs)
If *m
If ReadFile(0,f$)
ReadData(0,*m,fs)
CloseFile(0)
;check PNG signature
notpng=0
For i=0 To 7
If PeekA(*m+i)<>PeekA(?pngsig+i)
notpng=1
Break
EndIf
Next i
If notpng
MessageRequester("not PNG file",f$)
Else
*p=*m+8
While *p<*m+fs
cl=PeekA(*p+3)+PeekA(*p+2)<<8+PeekA(*p+1)<<16+PeekA(*p+0)<<24
;ShowMemoryViewer(*p+4,1024)
c$=PeekS(*p+4,4,#PB_Ascii)
Debug c$
If c$="IEND"
Break
EndIf
*p=*p+cl+12
Wend
EndIf
Else
MessageRequester("read file error!",f$)
EndIf
Else
MessageRequester("memory allocate error!",Str(fs))
EndIf
FreeMemory(*m)
Else
MessageRequester("no file!",f$)
EndIf
DataSection
pngsig:
Data.a $89,$50,$4E,$47,$0D,$0A,$1A,$0A
f$="PNG_transparency_demonstration_1.png"
fs=FileSize(f$)
If fs>0
*m=AllocateMemory(fs)
If *m
If ReadFile(0,f$)
ReadData(0,*m,fs)
CloseFile(0)
;check PNG signature
notpng=0
For i=0 To 7
If PeekA(*m+i)<>PeekA(?pngsig+i)
notpng=1
Break
EndIf
Next i
If notpng
MessageRequester("not PNG file",f$)
Else
*p=*m+8
While *p<*m+fs
cl=PeekA(*p+3)+PeekA(*p+2)<<8+PeekA(*p+1)<<16+PeekA(*p+0)<<24
;ShowMemoryViewer(*p+4,1024)
c$=PeekS(*p+4,4,#PB_Ascii)
Debug c$
If c$="IEND"
Break
EndIf
*p=*p+cl+12
Wend
EndIf
Else
MessageRequester("read file error!",f$)
EndIf
Else
MessageRequester("memory allocate error!",Str(fs))
EndIf
FreeMemory(*m)
Else
MessageRequester("no file!",f$)
EndIf
DataSection
pngsig:
Data.a $89,$50,$4E,$47,$0D,$0A,$1A,$0A
Осталось впихнуть в пару своих програмулин.
Комментарии
Отправить комментарий