Differenze tra le versioni di "Conoscere in modo sicuro il formato di un file immagine mediante le funzioni esterne del API di SDL2"

Da Gambas-it.org - Wikipedia.
(Creata pagina con 'Per sapere a quale formato appartiene un file immagine, al di là della sua estensione, è possibile utilizzare alcune funzioni esterne del API di ''SDL2''. ''SDL2'' è una l...')
 
 
(7 versioni intermedie di uno stesso utente non sono mostrate)
Riga 3: Riga 3:
 
''SDL2'' è una libreria di sviluppo multi-piattaforma progettata per fornire un accesso a basso livello all'audio, alla tastiera, al mouse, al joystick ed alla grafica.
 
''SDL2'' è una libreria di sviluppo multi-piattaforma progettata per fornire un accesso a basso livello all'audio, alla tastiera, al mouse, al joystick ed alla grafica.
  
 
+
Per poter fruire delle funzioni utilizzate dall'attuale argomento, bisognerà richiamare le seguenti librerie:
Per poter fruire delle funzioni utilizzate dall'attuale argomento, bisognerà richiamare le seguenti librerie: "''libSDL2-2.0.so.0.2.0''" e "''libSDL2_image-2.0.so.0.0.0''"
+
* "''libSDL2-2.0.so.0.3000.5'' ";
 
+
* "''libSDL2_image-2.0.so.0.800.2''"
 
 
  
 
Mostriamo un possibile esempio:
 
Mostriamo un possibile esempio:
  Library "libSDL2-2.0:0.2.0"
+
  Library "<FONT Color=blue>libSDL2-2.0:0.3000.5</font>"
 
   
 
   
 
  Private Const SDL_INIT_VIDEO As Integer = 32
 
  Private Const SDL_INIT_VIDEO As Integer = 32
Riga 26: Riga 25:
 
   
 
   
 
   
 
   
  Library "libSDL2_image-2.0:0.0.0"
+
  Library "<FONT Color=red>libSDL2_image-2.0:0.800.2</font>"
 
   
 
   
 
  <FONT Color=gray>' '''''Functions to detect a file type, given a seekable source:'''''</font>
 
  <FONT Color=gray>' '''''Functions to detect a file type, given a seekable source:'''''</font>
Riga 73: Riga 72:
 
   
 
   
 
   
 
   
  '''Public''' Sub Main()
+
  Public Sub Main()
 
   
 
   
  Dim fl As Pointer
+
  Dim fl As Pointer
  Dim percorsoFile As String = "''/percorso/del/file/immagine''"
+
  Dim percorsoFile As String = "<FONT Color=darkgreen>''/percorso/del/file/immagine''</font>"
 +
 +
  SDL_Init(SDL_INIT_VIDEO)
 +
 +
  fl = SDL_RWFromFile(percorsoFile, "rb")
 +
 
 +
  If IMG_isICO(fl) Then Print "Il file '"; percorsoFile; "' è un file ICO."
 +
  If IMG_isCUR(fl) Then Print "Il file '"; percorsoFile; "' è un file CUR."
 +
  If IMG_isBMP(fl) Then Print "Il file '"; percorsoFile; "' è un file BMP."
 +
  If IMG_isGIF(fl) Then Print "Il file '"; percorsoFile; "' è un file GIF."
 +
  If IMG_isJPG(fl) Then Print "Il file '"; percorsoFile; "' è un file JPG."
 +
  If IMG_isLBM(fl) Then Print "Il file '"; percorsoFile; "' è un file LBM."
 +
  If IMG_isPCX(fl) Then Print "Il file '"; percorsoFile; "' è un file PCX."
 +
  If IMG_isPNG(fl) Then Print "Il file '"; percorsoFile; "' è un file PNG."
 +
  If IMG_isPNM(fl) Then Print "Il file '"; percorsoFile; "' è un file PNM."
 +
  If IMG_isTIF(fl) Then Print "Il file '"; percorsoFile; "' è un file TIF."
 +
  If IMG_isXCF(fl) Then Print "Il file '"; percorsoFile; "' è un file XCF."
 +
  If IMG_isXPM(fl) Then Print "Il file '"; percorsoFile; "' è un file XPM."
 +
  If IMG_isXV(fl) Then Print "Il file '"; percorsoFile; "' è un file XV."
 +
  If IMG_isWEBP(fl) Then Print "Il file '"; percorsoFile; "' è un file WEBP."
 
    
 
    
    SDL_Init(SDL_INIT_VIDEO)
+
  SDL_Quit()
 
+
 
    fl = SDL_RWFromFile(percorsoFile, "rb")
+
  End
   
 
    If IMG_isICO(fl) Then Print "Il file '"; percorsoFile; "' è un file ICO."
 
    If IMG_isCUR(fl) Then Print "Il file '"; percorsoFile; "' è un file CUR."
 
    If IMG_isBMP(fl) Then Print "Il file '"; percorsoFile; "' è un file BMP."
 
    If IMG_isGIF(fl) Then Print "Il file '"; percorsoFile; "' è un file GIF."
 
    If IMG_isJPG(fl) Then Print "Il file '"; percorsoFile; "' è un file JPG."
 
    If IMG_isLBM(fl) Then Print "Il file '"; percorsoFile; "' è un file LBM."
 
    If IMG_isPCX(fl) Then Print "Il file '"; percorsoFile; "' è un file PCX."
 
    If IMG_isPNG(fl) Then Print "Il file '"; percorsoFile; "' è un file PNG."
 
    If IMG_isPNM(fl) Then Print "Il file '"; percorsoFile; "' è un file PNM."
 
    If IMG_isTIF(fl) Then Print "Il file '"; percorsoFile; "' è un file TIF."
 
    If IMG_isXCF(fl) Then Print "Il file '"; percorsoFile; "' è un file XCF."
 
    If IMG_isXPM(fl) Then Print "Il file '"; percorsoFile; "' è un file XPM."
 
    If IMG_isXV(fl) Then Print "Il file '"; percorsoFile; "' è un file XV."
 
    If IMG_isWEBP(fl) Then Print "Il file '"; percorsoFile; "' è un file WEBP."
 
   
 
    SDL_Quit()
 
   
 
  '''End'''
 
 
 
  
  

Versione attuale delle 15:21, 18 lug 2024

Per sapere a quale formato appartiene un file immagine, al di là della sua estensione, è possibile utilizzare alcune funzioni esterne del API di SDL2.

SDL2 è una libreria di sviluppo multi-piattaforma progettata per fornire un accesso a basso livello all'audio, alla tastiera, al mouse, al joystick ed alla grafica.

Per poter fruire delle funzioni utilizzate dall'attuale argomento, bisognerà richiamare le seguenti librerie:

  • "libSDL2-2.0.so.0.3000.5 ";
  • "libSDL2_image-2.0.so.0.800.2"

Mostriamo un possibile esempio:

Library "libSDL2-2.0:0.3000.5"

Private Const SDL_INIT_VIDEO As Integer = 32

' int SDL_Init(Uint32 flags)
' Initializes the SDL library.
Private Extern SDL_Init(flags As Integer) As Integer

' SDL_RWops* SDL_RWFromFile(const char* file, const char* mode)
' Creates a new SDL_RWops structure for reading from and/or writing to a named file.
Private Extern SDL_RWFromFile($file As String, mode As String) As Pointer

' void SDL_Quit(void)
' Clean up all initialized subsystems.
Private Extern SDL_Quit()


Library "libSDL2_image-2.0:0.800.2"

' Functions to detect a file type, given a seekable source:

' int IMG_isICO(SDL_RWops * src)
Private Extern IMG_isICO(src As Pointer) As Integer

' int IMG_isCUR(SDL_RWops * src)
Private Extern IMG_isCUR(src As Pointer) As Integer

' int IMG_isBMP(SDL_RWops * src)
Private Extern IMG_isBMP(src As Pointer) As Integer

' int IMG_isGIF(SDL_RWops * src)
Private Extern IMG_isGIF(src As Pointer) As Integer

' int IMG_isJPG(SDL_RWops * src)
Private Extern IMG_isJPG(src As Pointer) As Integer

' int IMG_isLBM(SDL_RWops * src)
Private Extern IMG_isLBM(src As Pointer) As Integer

' int IMG_isPCX(SDL_RWops * src)
Private Extern IMG_isPCX(src As Pointer) As Integer

' int IMG_isPNG(SDL_RWops * src)
Private Extern IMG_isPNG(src As Pointer) As Integer

' int IMG_isPNM(SDL_RWops * src)
Private Extern IMG_isPNM(src As Pointer) As Integer

' int IMG_isTIF(SDL_RWops * src)
Private Extern IMG_isTIF(src As Pointer) As Integer

' int IMG_isXCF(SDL_RWops * src)
Private Extern IMG_isXCF(src As Pointer) As Integer

' int IMG_isXPM(SDL_RWops * src)
Private Extern IMG_isXPM(src As Pointer) As Integer

' int IMG_isXV(SDL_RWops * src)
Private Extern IMG_isXV(src As Pointer) As Integer

' int IMG_isWEBP(SDL_RWops * src)
Private Extern IMG_isWEBP(src As Pointer) As Integer


Public Sub Main()

  Dim fl As Pointer
  Dim percorsoFile As String = "/percorso/del/file/immagine"

  SDL_Init(SDL_INIT_VIDEO)

  fl = SDL_RWFromFile(percorsoFile, "rb")
  
  If IMG_isICO(fl) Then Print "Il file '"; percorsoFile; "' è un file ICO."
  If IMG_isCUR(fl) Then Print "Il file '"; percorsoFile; "' è un file CUR."
  If IMG_isBMP(fl) Then Print "Il file '"; percorsoFile; "' è un file BMP."
  If IMG_isGIF(fl) Then Print "Il file '"; percorsoFile; "' è un file GIF."
  If IMG_isJPG(fl) Then Print "Il file '"; percorsoFile; "' è un file JPG."
  If IMG_isLBM(fl) Then Print "Il file '"; percorsoFile; "' è un file LBM."
  If IMG_isPCX(fl) Then Print "Il file '"; percorsoFile; "' è un file PCX."
  If IMG_isPNG(fl) Then Print "Il file '"; percorsoFile; "' è un file PNG."
  If IMG_isPNM(fl) Then Print "Il file '"; percorsoFile; "' è un file PNM."
  If IMG_isTIF(fl) Then Print "Il file '"; percorsoFile; "' è un file TIF."
  If IMG_isXCF(fl) Then Print "Il file '"; percorsoFile; "' è un file XCF."
  If IMG_isXPM(fl) Then Print "Il file '"; percorsoFile; "' è un file XPM."
  If IMG_isXV(fl) Then Print "Il file '"; percorsoFile; "' è un file XV."
  If IMG_isWEBP(fl) Then Print "Il file '"; percorsoFile; "' è un file WEBP."
 
  SDL_Quit()
  
End


Riferimenti