jpeglib.bi

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Post Reply
livewire
Posts: 78
Joined: Dec 07, 2006 3:43
Location: Orlando, FL

jpeglib.bi

Post by livewire »

Hello,

Before I submit a bug, I wanted to get confirmation here.

In jpeglib.bi, should

Code: Select all

#ifdef __FB_WIN32__
type boolean as ubyte
#else
type boolean as integer
#endif
be just:

Code: Select all

type boolean as integer
...in other words boolean => integer in windows

The example under 'examples\gfx\jpeg_read.bas' and my jpeg writing code only seem to work with this update above.

JPEG write (doesn't work in Windows for me with 'Type boolean As Ubyte'):

Code: Select all

#include "jpeglib.bi"

Declare Function PutScreenToJPEG(Byval Jpeg_File As String) As Any Ptr

ScreenRes 1280, 1024, 24, 1 '32-bit works also, as-is, but can only write 24
Bload("test.bmp")   'whatever..
PutScreenToJPEG("test.jpg") 'this overwrites any existing file, no warning

Function PutScreenToJPEG(Byval Jpeg_File As String) As Any Ptr
	Dim As Integer myw,myh,mydepth
	screeninfo myw,myh,mydepth
	
	' Create cinfo
	Dim cinfo As jpeg_compress_struct
	
	' Error object
	Dim jerr As jpeg_error_mgr
	cinfo.err = jpeg_std_error(@jerr)
	jpeg_create_compress(@cinfo)
	
	' Open file
	Dim outfile As FILE Ptr
	outfile = fopen(Jpeg_File,"wb")
	If outfile = 0 Then
		jpeg_destroy_compress @cinfo
		Return 0
	End If
	
	' Latch file to cinfo
	jpeg_stdio_dest @cinfo, outfile
	
	cinfo.image_width = myw       '/* image width&height, in pixels */
	cinfo.image_height = myh      '
	cinfo.input_components = 3    '/* # of color components per pixel */
	cinfo.in_color_space = JCS_RGB'/* colorspace of input image */
	
	jpeg_set_defaults(@cinfo)
	jpeg_set_quality(@cinfo, 85, TRUE)
	
	' Start writing
	jpeg_start_compress @cinfo,TRUE
	
	' Allocate space
	Dim row_stride As Integer
	row_stride = cinfo.image_width * cinfo.input_components
	
	Dim buffer As JSAMPARRAY
	buffer = cinfo.mem->alloc_sarray(Cast(j_common_ptr, @cinfo), JPOOL_IMAGE, row_stride, 1)
	
	Dim b As Ubyte Ptr
	b=*buffer
	Dim p As Ubyte Ptr
	p=screenptr
	Dim As Ubyte Ptr p1
	p1=p
	Dim As Integer a
	
	Do While cinfo.next_scanline < cinfo.image_height
		For a=0 To row_stride-1 Step 3
			p1=p+2                    'deal
			b[a]=*p1                  'with
			p1-=1                     'reversed
			b[a+1]=*p1                'BGR
			p1-=1                     'coding
			b[a+2]=*p1                'in
			p+=4                      'video buffer, grumble..
		Next
		jpeg_write_scanlines @cinfo, buffer, 1
	Loop
	
	jpeg_finish_compress @cinfo
	jpeg_destroy_compress @cinfo
	fclose outfile
End Function
Note:
I'm using
FreeBASIC Compiler - Version 0.20.0 (08-10-2008) for win32 (target:win32)
Copyright (C) 2004-2008 The FreeBASIC development team.
Configured as standalone

-Livewire
Post Reply