Differenze tra le versioni di "Ottenere alcune informazioni su file immagine JPEG con le funzioni del API di libjpeg"
Da Gambas-it.org - Wikipedia.
(Creata pagina con ''''Libjpeg''' è una libreria scritta in C utilizzata per la lettura e la scrittura di file immagine JPEG. Utilizzando alcune risorse della libreria, attaulmente alla version...') |
|||
(4 versioni intermedie di uno stesso utente non sono mostrate) | |||
Riga 1: | Riga 1: | ||
'''Libjpeg''' è una libreria scritta in C utilizzata per la lettura e la scrittura di file immagine JPEG. | '''Libjpeg''' è una libreria scritta in C utilizzata per la lettura e la scrittura di file immagine JPEG. | ||
− | Utilizzando alcune risorse della libreria, | + | Utilizzando alcune risorse della libreria, attualmente alla versione "''libjpeg.so.8.2.2'' " è possibile, fra l'altro, ottenere alcune informazioni relative al file immagine jpeg, come, ad esempio, la dimensione in pixel della larghezza e dell'altezza, nonché il numero di byte usato per definire un pixel. |
Mostriamo un semplice esempio al riguardo: | Mostriamo un semplice esempio al riguardo: | ||
− | + | Library "libjpeg:8.2.2" | |
− | + | ||
− | + | <FONT Color=gray>' ''struct jpeg_error_mgr * jpeg_std_error(struct jpeg_error_mgr * err)'' | |
+ | ' ''Update error manager with error handling routines.''</font> | ||
+ | Private Extern jpeg_std_error(jpeg_error_mgr As Pointer) As Pointer | ||
+ | |||
+ | <FONT Color=gray>' ''void jpeg_CreateDecompress(j_decompress_ptr cinfo, int version, size_t structsize)'' | ||
+ | ' ''Allocate and initialize a JPEG decompression object.''</font> | ||
+ | Private Extern jpeg_CreateDecompress(j_decompress_ptr As Pointer, version As Integer, structsize As Integer) | ||
+ | |||
+ | <FONT Color=gray>' ''void jpeg_stdio_src(j_decompress_ptr cinfo, FILE * infile)'' | ||
+ | ' ''Initialize state for input from stdio stream.''</font> | ||
+ | Private Extern jpeg_stdio_src(j_decompress_ptr As Pointer, infile As Pointer) | ||
+ | |||
+ | <FONT Color=gray>' ''int jpeg_read_header(j_decompress_ptr cinfo, boolean require_image)'' | ||
+ | ' ''Read start of JPEG datastream.''</font> | ||
+ | Private Extern jpeg_read_header(j_decompress_ptr As Pointer, require_image As Integer) As Integer | ||
+ | |||
+ | <FONT Color=gray>' ''boolean jpeg_start_decompress(j_decompress_ptr cinfo)'' | ||
+ | ' ''Initialize a decompression cycle.''</font> | ||
+ | Private Extern jpeg_start_decompress(j_decompress_ptr As Pointer) As Integer | ||
+ | |||
+ | <FONT Color=gray>' ''void jpeg_destroy_decompress(j_decompress_ptr cinfo)'' | ||
+ | ' ''Deallocate a JPEG decompression object''</font> | ||
+ | Private Extern jpeg_destroy_decompress(j_decompress_ptr As Pointer) | ||
+ | |||
+ | |||
+ | Library "libc:6" | ||
+ | |||
+ | <FONT Color=gray>' ''FILE *fopen(const char *path, const char *mode)''</font> | ||
+ | Private Extern fopen(path As String, mode As String) As Pointer | ||
+ | |||
+ | <FONT Color=gray>' ''int fclose(FILE *stream)''</font> | ||
+ | Private Extern fclose(fileStream As Pointer) As Integer | ||
+ | |||
+ | |||
+ | '''Public''' Sub Main() | ||
+ | |||
+ | Dim fl, err_mgr, cinfo As Pointer | ||
+ | Dim width, height, bytePerPixel As Integer | ||
+ | Dim st As Stream | ||
+ | |||
+ | fl = fopen("<FONT Color=gray>''/percorso/del/file.jpg''</font>", "rb") | ||
+ | |||
+ | err_mgr = Alloc(SizeOf(gb.Byte), 168) | ||
+ | cinfo = Alloc(SizeOf(gb.Byte), 656) | ||
+ | |||
+ | st = Memory cinfo For Read Write | ||
+ | Write #st, jpeg_std_error(err_mgr) As Pointer | ||
+ | |||
+ | jpeg_CreateDecompress(cinfo, 80, 656) | ||
+ | |||
+ | jpeg_stdio_src(cinfo, fl) | ||
+ | |||
+ | jpeg_read_header(cinfo, 1) | ||
+ | |||
+ | jpeg_start_decompress(cinfo) | ||
+ | |||
+ | Seek #st, 48 | ||
+ | Read #st, width | ||
+ | Print "Numero pixel in larghezza: "; width | ||
+ | |||
+ | Read #st, height | ||
+ | Print "Numero pixel in altezza: "; height | ||
+ | Seek #st, 60 | ||
+ | |||
+ | Read #st, bytePerPixel | ||
+ | Print "Numero byte per pixel: "; bytePerPixel | ||
+ | |||
+ | <FONT Color=gray>' ''Va a terminare:''</font> | ||
+ | jpeg_destroy_decompress(cinfo) | ||
+ | st.Close | ||
+ | Free(cinfo) | ||
+ | Free(err_mgr) | ||
+ | fclose(fl) | ||
+ | |||
+ | '''End''' | ||
Riga 14: | Riga 88: | ||
* [http://libjpeg.sourceforge.net/ libjpeg.sourceforge.net] | * [http://libjpeg.sourceforge.net/ libjpeg.sourceforge.net] | ||
* [http://www.jpeg.org/ www.jpeg.org] | * [http://www.jpeg.org/ www.jpeg.org] | ||
− | |||
− | |||
− | |||
− |
Versione attuale delle 19:01, 1 dic 2021
Libjpeg è una libreria scritta in C utilizzata per la lettura e la scrittura di file immagine JPEG.
Utilizzando alcune risorse della libreria, attualmente alla versione "libjpeg.so.8.2.2 " è possibile, fra l'altro, ottenere alcune informazioni relative al file immagine jpeg, come, ad esempio, la dimensione in pixel della larghezza e dell'altezza, nonché il numero di byte usato per definire un pixel.
Mostriamo un semplice esempio al riguardo:
Library "libjpeg:8.2.2" ' struct jpeg_error_mgr * jpeg_std_error(struct jpeg_error_mgr * err) ' Update error manager with error handling routines. Private Extern jpeg_std_error(jpeg_error_mgr As Pointer) As Pointer ' void jpeg_CreateDecompress(j_decompress_ptr cinfo, int version, size_t structsize) ' Allocate and initialize a JPEG decompression object. Private Extern jpeg_CreateDecompress(j_decompress_ptr As Pointer, version As Integer, structsize As Integer) ' void jpeg_stdio_src(j_decompress_ptr cinfo, FILE * infile) ' Initialize state for input from stdio stream. Private Extern jpeg_stdio_src(j_decompress_ptr As Pointer, infile As Pointer) ' int jpeg_read_header(j_decompress_ptr cinfo, boolean require_image) ' Read start of JPEG datastream. Private Extern jpeg_read_header(j_decompress_ptr As Pointer, require_image As Integer) As Integer ' boolean jpeg_start_decompress(j_decompress_ptr cinfo) ' Initialize a decompression cycle. Private Extern jpeg_start_decompress(j_decompress_ptr As Pointer) As Integer ' void jpeg_destroy_decompress(j_decompress_ptr cinfo) ' Deallocate a JPEG decompression object Private Extern jpeg_destroy_decompress(j_decompress_ptr As Pointer) Library "libc:6" ' FILE *fopen(const char *path, const char *mode) Private Extern fopen(path As String, mode As String) As Pointer ' int fclose(FILE *stream) Private Extern fclose(fileStream As Pointer) As Integer Public Sub Main() Dim fl, err_mgr, cinfo As Pointer Dim width, height, bytePerPixel As Integer Dim st As Stream fl = fopen("/percorso/del/file.jpg", "rb") err_mgr = Alloc(SizeOf(gb.Byte), 168) cinfo = Alloc(SizeOf(gb.Byte), 656) st = Memory cinfo For Read Write Write #st, jpeg_std_error(err_mgr) As Pointer jpeg_CreateDecompress(cinfo, 80, 656) jpeg_stdio_src(cinfo, fl) jpeg_read_header(cinfo, 1) jpeg_start_decompress(cinfo) Seek #st, 48 Read #st, width Print "Numero pixel in larghezza: "; width Read #st, height Print "Numero pixel in altezza: "; height Seek #st, 60 Read #st, bytePerPixel Print "Numero byte per pixel: "; bytePerPixel ' Va a terminare: jpeg_destroy_decompress(cinfo) st.Close Free(cinfo) Free(err_mgr) fclose(fl) End