Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

ImageCreateFromFile Class Reference

Create a number of images that are generated from the input file. More...

Inheritance diagram for ImageCreateFromFile:

Inheritance graph
[legend]
Collaboration diagram for ImageCreateFromFile:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ImageCreateFromFile ()
char * GetDescription () const
void CreateFrame (uint8_t *pixels, int width, int height, double position, double frame_delta)
void AttachWidgets (GtkBin *bin)
void DetachWidgets (GtkBin *bin)
void InterpretWidgets (GtkBin *bin)
GtkEntry * getEntry () const

Static Public Member Functions

static void on_button_file_clicked (GtkButton *button, gpointer user_data)

Protected Attributes

GtkWidget * file_entry
int count
GdkPixbuf * still
bool hasFilenameChanged
int count_offset

Static Protected Attributes

static char file [PATH_MAX+NAME_MAX] = ""

Detailed Description

Create a number of images that are generated from the input file.

Definition at line 499 of file image_create.cc.


Constructor & Destructor Documentation

ImageCreateFromFile::ImageCreateFromFile  )  [inline]
 

Definition at line 510 of file image_create.cc.

00511         : file_entry( 0 )
00512         , still( 0 ) 
00513         , hasFilenameChanged( false )
00514         , count_offset( 0 )
00515     { }


Member Function Documentation

void ImageCreateFromFile::AttachWidgets GtkBin *  bin  )  [inline, virtual]
 

Reimplemented from ImageCreateColourRange.

Definition at line 629 of file image_create.cc.

References ImageCreateColour::AddFrameCollector(), file, file_entry, on_button_file_clicked(), and Repaint().

00630     {
00631         GtkWidget * table = gtk_table_new ( 2, 2, FALSE );
00632         gtk_table_set_row_spacings( GTK_TABLE( table ), 6 );
00633         gtk_table_set_col_spacings( GTK_TABLE( table ), 6 );
00634 
00635         GtkWidget *label = gtk_label_new( _( "File:" ) );
00636         gtk_widget_show( label );
00637 
00638         GtkWidget *hbox = gtk_hbox_new( FALSE, 6 );
00639         file_entry = gtk_entry_new();
00640         gtk_entry_set_text( GTK_ENTRY( file_entry ), file );
00641         g_signal_connect( G_OBJECT( file_entry ), "activate", G_CALLBACK( Repaint ), 0 );
00642         gtk_box_pack_start( GTK_BOX( hbox ), file_entry, TRUE, TRUE, 0 );
00643         GtkWidget *button = gtk_button_new();
00644         GtkWidget *image = gtk_image_new_from_stock( GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON );
00645         gtk_container_add( GTK_CONTAINER( button ), image );
00646         gtk_button_set_relief( GTK_BUTTON( button ), GTK_RELIEF_NONE );
00647         g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( on_button_file_clicked ), this );
00648 
00649         gtk_box_pack_start( GTK_BOX( hbox ), button, FALSE, TRUE, 0 );
00650         gtk_widget_show( hbox );
00651         gtk_widget_show( file_entry );
00652         gtk_widget_show( button );
00653         gtk_widget_show( image );
00654 
00655         AddFrameCollector( table, 0 );
00656         gtk_table_attach( GTK_TABLE( table ), label, 0, 1, 1, 2, ( GtkAttachOptions ) ( 0 ), ( GtkAttachOptions ) ( 0 ), 0, 0 );
00657         gtk_table_attach( GTK_TABLE( table ), hbox, 1, 2, 1, 2, ( GtkAttachOptions ) ( GTK_EXPAND | GTK_FILL | GTK_SHRINK ), ( GtkAttachOptions ) ( 0 ), 0, 0 );
00658 
00659         GtkWidget *tip_label = gtk_label_new( _( "TIP: use a format specifier in the file name\nto import from an image sequence.\nFor example: gap-%06d.png." ) );
00660         gtk_label_set_line_wrap( GTK_LABEL( tip_label ), FALSE );
00661         gtk_widget_show( tip_label );
00662         gtk_table_attach( GTK_TABLE( table ), tip_label, 0, 2, 2, 3, ( GtkAttachOptions ) ( GTK_EXPAND | GTK_FILL | GTK_SHRINK ), ( GtkAttachOptions ) ( 0 ), 0, 0 );
00663 
00664         gtk_widget_show( table );
00665         gtk_container_add( GTK_CONTAINER( bin ), table );
00666     }

void ImageCreateFromFile::CreateFrame uint8_t *  pixels,
int  width,
int  height,
double  position,
double  frame_delta
[inline, virtual]
 

Reimplemented from ImageCreateColourRange.

Definition at line 522 of file image_create.cc.

References count, count_offset, file, GAP_MAX, ImageCreateColour::GetNumberOfFrames(), GetSelectedFramesForFX(), hasFilenameChanged, SelectedFrames::IsPreviewing(), SelectedFrames::IsRepainting(), modal_message(), and still.

00523     {
00524         if ( strcmp( file, "" ) == 0 )
00525             return;
00526         
00527         GError* gerror = NULL;
00528         SelectedFrames& fx = GetSelectedFramesForFX();
00529 
00530         // Determine if this is an image sequence
00531         if ( strchr( file, '%' ) != NULL )
00532         {
00533             char full[ PATH_MAX + NAME_MAX ];
00534             int gap = 0;
00535         
00536             if ( fx.IsRepainting() || fx.IsPreviewing() )
00537             {
00538                 // compute the relative count
00539                 count = int( position * GetNumberOfFrames() + 0.5 );
00540                 
00541                 // determine offset to first file
00542                 if ( hasFilenameChanged )
00543                 for ( count_offset = 0; count_offset < GAP_MAX; ++count_offset )
00544                 {
00545                     struct stat buf;
00546                     snprintf( full, PATH_MAX + NAME_MAX, file, count + count_offset );
00547                     if ( stat( full, &buf ) == 0 )
00548                         break;
00549                 }
00550                 count += count_offset;
00551             }
00552             // Permit gaps in the file number sequence
00553             while ( gap < GAP_MAX )
00554             {
00555                 struct stat buf;
00556                 snprintf( full, PATH_MAX + NAME_MAX, file, count++ );
00557                 if ( stat( full, &buf ) == 0 )
00558                     break;
00559                 else
00560                     gap ++;
00561             }
00562             // If successfully obtained a new file
00563             if ( gap < GAP_MAX )
00564             {
00565                 GdkPixbuf *image = gdk_pixbuf_new_from_file( full, &gerror );
00566                 if ( still )
00567                     g_object_unref( still );
00568                 still = gdk_pixbuf_scale_simple( image, width, height, GDK_INTERP_HYPER );
00569                 g_object_unref( image );
00570             }
00571         }
00572         // Otherwise, import single image just once
00573         else if ( hasFilenameChanged )
00574         {
00575             GdkPixbuf *image = gdk_pixbuf_new_from_file( file, &gerror );
00576             if ( still )
00577                 g_object_unref( still );
00578             if ( image )
00579             {
00580                 still = gdk_pixbuf_scale_simple( image, width, height, GDK_INTERP_HYPER );
00581                 g_object_unref( image );
00582             }
00583         }
00584         // If gdk-pixbuf loader generated an error
00585         if ( gerror != NULL )
00586         {
00587             if ( hasFilenameChanged )
00588             {
00589                 if ( fx.IsPreviewing() )
00590                     gdk_threads_enter();
00591                 modal_message( gerror->message );
00592                 if ( fx.IsPreviewing() )
00593                     gdk_threads_leave();
00594             }
00595             g_error_free( gerror );
00596             if ( still )
00597                 g_object_unref( still );
00598             still = 0;
00599         }
00600         // Otherwise, if there is a pixbuf
00601         else if ( still )
00602         {
00603             if ( gdk_pixbuf_get_has_alpha( still ) ) {
00604             // This is a hack! The correct calls would be:
00605             // gdk_pixbuf_new/gdk_pixbuf_copy_area
00606                 uint8_t *jp = gdk_pixbuf_get_pixels( still ), *jz = pixels;
00607                 for ( int i = 0; i < width * height; i++ ) {
00608                     memcpy( jz, jp, 3 );
00609                     jp += 4; jz += 3;
00610                 }
00611             }
00612             else
00613                 memcpy( pixels, gdk_pixbuf_get_pixels( still ), width * height * 3 );
00614         }
00615         hasFilenameChanged = false;
00616     }

void ImageCreateFromFile::DetachWidgets GtkBin *  bin  )  [inline, virtual]
 

Reimplemented from ImageCreateColourRange.

Definition at line 668 of file image_create.cc.

References file, file_entry, and ImageCreateColour::InterpretFrameCollector().

00669     {
00670         if ( bin->child != NULL )
00671         {
00672             // Make sure we save the current settings (this should be a method, rather than a duplicate
00673             // of InterpretWidgets ... since Interpret may throw exceptions, it can't be called directly
00674             // here...)
00675             InterpretFrameCollector( );
00676             strcpy( file, gtk_entry_get_text( GTK_ENTRY( file_entry ) ) );
00677             gtk_container_remove( GTK_CONTAINER( bin ), bin->child );
00678         }
00679     }

char* ImageCreateFromFile::GetDescription  )  const [inline, virtual]
 

Reimplemented from ImageCreateColourRange.

Definition at line 517 of file image_create.cc.

00518     {
00519         return _( "From File" );
00520     }

GtkEntry* ImageCreateFromFile::getEntry  )  const [inline]
 

Definition at line 701 of file image_create.cc.

References file_entry.

Referenced by on_button_file_clicked().

00702     {
00703         if ( file_entry )
00704             return GTK_ENTRY( file_entry );
00705         else
00706             return NULL;
00707     }

void ImageCreateFromFile::InterpretWidgets GtkBin *  bin  )  [inline, virtual]
 

Reimplemented from ImageCreateColourRange.

Definition at line 681 of file image_create.cc.

References count, file, file_entry, GetSelectedFramesForFX(), hasFilenameChanged, ImageCreateColour::InterpretFrameCollector(), SelectedFrames::IsPreviewing(), and SelectedFrames::IsRepainting().

00682     {
00683         if ( bin->child != NULL )
00684         {
00685             InterpretFrameCollector( );
00686             if ( file_entry )
00687             {
00688                 int n = PATH_MAX + NAME_MAX - 1;
00689                 char newFileName[ n + 1 ];
00690                 newFileName[ n ] = '\0';
00691                 strncpy( newFileName, gtk_entry_get_text( GTK_ENTRY( file_entry ) ), n );
00692                 SelectedFrames& fx = GetSelectedFramesForFX();
00693                 if ( strcmp( newFileName, file ) || !( fx.IsRepainting() || fx.IsPreviewing() ) )
00694                     hasFilenameChanged = true;
00695                 strcpy( file, newFileName );
00696                 count = 0;
00697             }
00698         }
00699     }

static void ImageCreateFromFile::on_button_file_clicked GtkButton *  button,
gpointer  user_data
[inline, static]
 

Definition at line 619 of file image_create.cc.

References common, getEntry(), and KinoCommon::getFileToOpen().

Referenced by AttachWidgets().

00620     {
00621         char *filename = common->getFileToOpen( _("Select an Image"), false );
00622         if ( filename && strcmp( filename, "" ) )
00623         {
00624             ImageCreateFromFile *me = static_cast< ImageCreateFromFile* >( user_data );
00625             gtk_entry_set_text( me->getEntry(), filename );
00626         }
00627     }


Member Data Documentation

int ImageCreateFromFile::count [protected]
 

Definition at line 504 of file image_create.cc.

Referenced by CreateFrame(), and InterpretWidgets().

int ImageCreateFromFile::count_offset [protected]
 

Definition at line 507 of file image_create.cc.

Referenced by CreateFrame().

char ImageCreateFromFile::file = "" [static, protected]
 

Definition at line 710 of file image_create.cc.

Referenced by AttachWidgets(), CreateFrame(), DetachWidgets(), and InterpretWidgets().

GtkWidget* ImageCreateFromFile::file_entry [protected]
 

Definition at line 503 of file image_create.cc.

Referenced by AttachWidgets(), DetachWidgets(), getEntry(), and InterpretWidgets().

bool ImageCreateFromFile::hasFilenameChanged [protected]
 

Definition at line 506 of file image_create.cc.

Referenced by CreateFrame(), and InterpretWidgets().

GdkPixbuf* ImageCreateFromFile::still [protected]
 

Definition at line 505 of file image_create.cc.

Referenced by CreateFrame().


The documentation for this class was generated from the following file:
Generated on Sun Mar 11 22:13:02 2007 for Kino by  doxygen 1.4.2