Permalink
Browse files

removed gdk-pixbuf dependency (and thus GTK is gone)

  • Loading branch information...
1 parent 5fcfd44 commit 36bf60ee0458291cbd4b64603306ff5bbb6d26a0 rtv committed Apr 14, 2008
Showing with 73 additions and 87 deletions.
  1. +1 −1 CMakeLists.txt
  2. +72 −86 libstage/stage.cc
View
2 CMakeLists.txt
@@ -5,7 +5,7 @@ SET (STAGE_API_VERSION 3.0.0 CACHE STRING "Stage API version")
MESSAGE (STATUS "${PROJECT_NAME} version ${STAGE_VERSION}")
include(FindPkgConfig)
-pkg_check_modules( GLIB gdk-pixbuf-2.0 )
+pkg_check_modules( GLIB glib-2.0 )
find_package(OPENGL REQUIRED)
View
158 libstage/stage.cc
@@ -12,7 +12,7 @@
#include <glib.h>
#include <locale.h>
-#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <FL/Fl_Shared_Image.H>
//#define DEBUG
@@ -30,13 +30,14 @@ void Stg::Init( int* argc, char** argv[] )
// seed the RNG
srand48( time(NULL) );
- g_type_init();
-
if(!setlocale(LC_ALL,"POSIX"))
PRINT_WARN("Failed to setlocale(); config file may not be parse correctly\n" );
typetable = stg_create_typetable();
init_called = true;
+
+ // ask FLTK to load support for various image formats
+ fl_register_images();
}
bool Stg::InitDone()
@@ -335,62 +336,65 @@ stg_pose_t Stg::pose_sum( stg_pose_t p1, stg_pose_t p2 )
// pb_* functions are only used inside this file
-static guchar* pb_get_pixel( GdkPixbuf* pb, int x, int y )
-{
- guchar* pixels = gdk_pixbuf_get_pixels(pb);
- int rs = gdk_pixbuf_get_rowstride(pb);
- int ch = gdk_pixbuf_get_n_channels(pb);
- return( pixels + y * rs + x * ch );
-}
-
-// static void pb_set_pixel( GdkPixbuf* pb, int x, int y, uint8_t val )
+// static guchar* pb_get_pixel( GdkPixbuf* pb, int x, int y )
// {
-// // bounds checking
-// int width = gdk_pixbuf_get_width(pb);
-// int height = gdk_pixbuf_get_height(pb);
-// if( x >=0 && x < width && y >= 0 && y < height )
-// {
-// // zeroing
-// guchar* pix = pb_get_pixel( pb, x, y );
-// int bytes_per_sample = gdk_pixbuf_get_bits_per_sample (pb) / 8;
-// int num_samples = gdk_pixbuf_get_n_channels(pb);
-// memset( pix, val, num_samples * bytes_per_sample );
-// }
-// else
-// PRINT_WARN4( "pb_set_pixel coordinate %d,%d out of range (image dimensions %d by %d)", x, y, width, height );
+// guchar* pixels = gdk_pixbuf_get_pixels(pb);
+// int rs = gdk_pixbuf_get_rowstride(pb);
+// int ch = gdk_pixbuf_get_n_channels(pb);
+// return( pixels + y * rs + x * ch );
// }
-// set all the pixels in a rectangle
-static void pb_set_rect( GdkPixbuf* pb, int x, int y, int width, int height, uint8_t val )
+static guchar* pb_get_pixel( Fl_Shared_Image* img, int x, int y )
{
- int bytes_per_sample = gdk_pixbuf_get_bits_per_sample (pb) / 8;
- int num_samples = gdk_pixbuf_get_n_channels(pb);
-
- int a, b;
- for( a = y; a < y+height; a++ )
- for( b = x; b < x+width; b++ )
- {
- // zeroing
- guchar* pix = pb_get_pixel( pb, b, a );
- memset( pix, val, num_samples * bytes_per_sample );
- }
-}
+ guchar* pixels = (guchar*)(img->data()[0]);
+ //int rs = gdk_pixbuf_get_rowstride(pb);
+ //int ch = gdk_pixbuf_get_n_channels(pb);
+
+ //unsigned int depth = img->d();
+ //unsigned int width = img->w();
+ unsigned int index = (y * img->w() * img->d()) + (x * img->d());
+ return( pixels + index );
+}
-// returns TRUE if any channel in the pixel is non-zero
-static gboolean pb_pixel_is_set( GdkPixbuf* pb, int x, int y, int threshold )
+static void pb_set_pixel( Fl_Shared_Image* pb, int x, int y, uint8_t val )
{
- guchar* pixel = pb_get_pixel( pb,x,y );
- //int channels = gdk_pixbuf_get_n_channels(pb);
- //int i;
- //for( i=0; i<channels; i++ )
- //if( pixel[i] ) return TRUE;
- if( pixel[0] > threshold ) return TRUE; // just use the red channel for now
-
- return FALSE;
+ // bounds checking
+ int width = pb->w();//gdk_pixbuf_get_width(pb);
+ int height = pb->h();//gdk_pixbuf_get_height(pb);
+ if( x >=0 && x < width && y >= 0 && y < height )
+ {
+ // zeroing
+ guchar* pix = pb_get_pixel( pb, x, y );
+ unsigned int bytes_per_sample = 1;//gdk_pixbuf_get_bits_per_sample (pb) / 8;
+ unsigned int num_samples = pb->d();//gdk_pixbuf_get_n_channels(pb);
+ memset( pix, val, num_samples * bytes_per_sample );
+ }
+ else
+ PRINT_WARN4( "pb_set_pixel coordinate %d,%d out of range (image dimensions %d by %d)", x, y, width, height );
}
-
-
+// set all the pixels in a rectangle
+static void pb_set_rect( Fl_Shared_Image* pb, int x, int y, int width, int height, uint8_t val )
+ {
+ int bytes_per_sample = 1;//gdk_pixbuf_get_bits_per_sample (pb) / 8;
+ int num_samples = pb->d();//gdk_pixbuf_get_n_channels(pb);
+
+ int a, b;
+ for( a = y; a < y+height; a++ )
+ for( b = x; b < x+width; b++ )
+ {
+ // zeroing
+ guchar* pix = pb_get_pixel( pb, b, a );
+ memset( pix, val, num_samples * bytes_per_sample );
+ }
+ }
+
+// // returns TRUE if any channel in the pixel is non-zero
+static gboolean pb_pixel_is_set( Fl_Shared_Image* img, int x, int y, int threshold )
+{
+ guchar* pixel = pb_get_pixel( img,x,y );
+ return( pixel[0] > threshold );
+}
int Stg::stg_rotrects_from_image_file( const char* filename,
stg_rotrect_t** rects,
@@ -400,63 +404,43 @@ int Stg::stg_rotrects_from_image_file( const char* filename,
{
// TODO: make this a parameter
const int threshold = 127;
-
- GError* err = NULL;
- GdkPixbuf* pb = gdk_pixbuf_new_from_file( filename, &err );
-
- if( err )
- {
- fprintf( stderr, "\nError loading bitmap: %s\n", err->message );
- return 1; // error
- }
-
- // this should be ok as no error was reported
- assert( pb );
-
-#ifdef DEBUG
- printf( "debug: Loaded image \"%s\" \n\tchannels:%d bits:%d alpha:%d "
- "width:%d height:%d rowstride:%d pixels:%p (%s %s)\n",
- filename,
- gdk_pixbuf_get_n_channels(pb),
- gdk_pixbuf_get_bits_per_sample(pb),
- gdk_pixbuf_get_has_alpha(pb),
- gdk_pixbuf_get_width(pb),
- gdk_pixbuf_get_height(pb),
- gdk_pixbuf_get_rowstride(pb),
- gdk_pixbuf_get_pixels(pb),
- __FILE__, __FUNCTION__ );
-#endif
+ Fl_Shared_Image *img = Fl_Shared_Image::get(filename);
+ assert( img );
+
+ //printf( "loaded image %s w %d h %d d %d count %d ld %d\n",
+ // filename, img->w(), img->h(), img->d(), img->count(), img->ld() );
-
*rect_count = 0;
size_t allocation_unit = 1000;
size_t rects_allocated = allocation_unit;
*rects = (stg_rotrect_t*)g_new( stg_rotrect_t, rects_allocated );
- int img_width = gdk_pixbuf_get_width(pb);
- int img_height = gdk_pixbuf_get_height(pb);
+ int img_width = img->w();//gdk_pixbuf_get_width(pb);
+ int img_height = img->h();//gdk_pixbuf_get_height(pb);
// if the caller wanted to know the dimensions
if( widthp ) *widthp = img_width;
if( heightp ) *heightp = img_height;
+
int y, x;
for(y = 0; y < img_height; y++)
{
+ puts("");
for(x = 0; x < img_width; x++)
{
// skip blank (white) pixels
- if( pb_pixel_is_set( pb,x,y, threshold) )
+ if( pb_pixel_is_set( img,x,y, threshold) )
continue;
-
+
// a rectangle starts from this point
int startx = x;
int starty = y;
int height = img_height; // assume full height for starters
// grow the width - scan along the line until we hit an empty (white) pixel
- for( ; x < img_width && ! pb_pixel_is_set(pb,x,y,threshold); x++ )
+ for( ; x < img_width && ! pb_pixel_is_set(img,x,y,threshold); x++ )
{
// handle horizontal cropping
//double ppx = x * sx;
@@ -465,7 +449,7 @@ int Stg::stg_rotrects_from_image_file( const char* filename,
// look down to see how large a rectangle below we can make
int yy = y;
- while( ! pb_pixel_is_set(pb,x,yy,threshold) && (yy < img_height-1) )
+ while( ! pb_pixel_is_set(img,x,yy,threshold) && (yy < img_height-1) )
{
// handle vertical cropping
//double ppy = (this->image->height - yy) * sy;
@@ -482,7 +466,7 @@ int Stg::stg_rotrects_from_image_file( const char* filename,
}
// whiten the pixels we have used in this rect
- pb_set_rect( pb, startx, starty, x-startx, height, 0xFF );
+ pb_set_rect( img, startx, starty, x-startx, height, 0xFF );
// add this rectangle to the array
(*rect_count)++;
@@ -512,8 +496,10 @@ int Stg::stg_rotrects_from_image_file( const char* filename,
}
}
+ printf( "rects found %d\n", *rect_count );
+
// free the image data
- gdk_pixbuf_unref( pb );
+ //gdk_pixbuf_unref( pb );
return 0; // ok
}

0 comments on commit 36bf60e

Please sign in to comment.