-/*****************************************************************************
- * VideoWindow::_SaveScreenShot
- *****************************************************************************/
-void
-VideoWindow::_SaveScreenShot( BBitmap* bitmap, char* path,
- uint32_t translatorID ) const
-{
- // make the info object from the parameters
- screen_shot_info* info = new screen_shot_info;
- info->bitmap = bitmap;
- info->path = path;
- info->translatorID = translatorID;
- info->width = CorrectAspectRatio() ? i_width : fTrueWidth;
- info->height = CorrectAspectRatio() ? i_height : fTrueHeight;
- // spawn a new thread to take care of the actual saving to disk
- thread_id thread = spawn_thread( _save_screen_shot,
- "screen shot saver",
- B_LOW_PRIORITY, (void*)info );
- // start thread or do the job ourself if something went wrong
- if ( thread < B_OK || resume_thread( thread ) < B_OK )
- _save_screen_shot( (void*)info );
-}
-
-/*****************************************************************************
- * VideoWindow::_save_screen_shot
- *****************************************************************************/
-int32
-VideoWindow::_save_screen_shot( void* cookie )
-{
- screen_shot_info* info = (screen_shot_info*)cookie;
- if ( info && info->bitmap && info->bitmap->IsValid() && info->path )
- {
- // try to be as quick as possible creating the file (the user might have
- // taken the next screen shot already!)
- // make sure we have a unique name for the screen shot
- BString path( info->path );
- // create the folder if it doesn't exist
- BString folder( info->path );
- create_directory( folder.String(), 0777 );
- path << "/vlc screenshot";
- BEntry entry( path.String() );
- int32_t appendedNumber = 0;
- if ( entry.Exists() && !entry.IsSymLink() )
- {
- // we would clobber an existing entry
- bool foundUniqueName = false;
- appendedNumber = 1;
- while ( !foundUniqueName ) {
- BString newName( path.String() );
- newName << " " << appendedNumber;
- BEntry possiblyClobberedEntry( newName.String() );
- if ( possiblyClobberedEntry.Exists()
- && !possiblyClobberedEntry.IsSymLink() )
- appendedNumber++;
- else
- foundUniqueName = true;
- }
- }
- if ( appendedNumber > 0 )
- path << " " << appendedNumber;
- // there is still a slight chance to clobber an existing
- // file (if it was created in the "meantime"), but we take it...
- BFile outFile( path.String(),
- B_CREATE_FILE | B_WRITE_ONLY | B_ERASE_FILE );
-
- // make colorspace converted copy of bitmap
- BBitmap* converted = new BBitmap( BRect( 0.0, 0.0, info->width, info->height ),
- B_RGB32 );
- status_t status = convert_bitmap( info->bitmap, converted );
- if ( status == B_OK )
- {
- BTranslatorRoster* roster = BTranslatorRoster::Default();
- uint32_t imageFormat = 0;
- translator_id translator = 0;
- bool found = false;
-
- // find suitable translator
- translator_id* ids = NULL;
- int32 count = 0;
-
- status = roster->GetAllTranslators( &ids, &count );
- if ( status >= B_OK )
- {
- for ( int tix = 0; tix < count; tix++ )
- {
- const translation_format *formats = NULL;
- int32 num_formats = 0;
- bool ok = false;
- status = roster->GetInputFormats( ids[tix],
- &formats, &num_formats );
- if (status >= B_OK)
- {
- for ( int iix = 0; iix < num_formats; iix++ )
- {
- if ( formats[iix].type == B_TRANSLATOR_BITMAP )
- {
- ok = true;
- break;
- }
- }
- }
- if ( !ok )
- continue;
- status = roster->GetOutputFormats( ids[tix],
- &formats, &num_formats);
- if ( status >= B_OK )
- {
- for ( int32_t oix = 0; oix < num_formats; oix++ )
- {
- if ( formats[oix].type != B_TRANSLATOR_BITMAP )
- {
- if ( formats[oix].type == info->translatorID )
- {
- found = true;
- imageFormat = formats[oix].type;
- translator = ids[tix];
- break;
- }
- }
- }
- }
- }
- }
- delete[] ids;
- if ( found )
- {
- // make bitmap stream
- BBitmapStream outStream( converted );
-
- status = outFile.InitCheck();
- if (status == B_OK) {
- status = roster->Translate( &outStream, NULL, NULL,
- &outFile, imageFormat );
- if ( status == B_OK )
- {
- BNodeInfo nodeInfo( &outFile );
- if ( nodeInfo.InitCheck() == B_OK )
- {
- translation_format* formats;
- int32 count;
- status = roster->GetOutputFormats( translator,
- (const translation_format **) &formats,
- &count);
- if ( status >= B_OK )
- {
- const char * mime = NULL;
- for ( int ix = 0; ix < count; ix++ ) {
- if ( formats[ix].type == imageFormat ) {
- mime = formats[ix].MIME;
- break;
- }
- }
- if ( mime )
- nodeInfo.SetType( mime );
- }
- }
- }
- }
- outStream.DetachBitmap( &converted );
- outFile.Unset();
- }
- }
- delete converted;
- }
- if ( info )
- {
- delete info->bitmap;
- free( info->path );
- }
- delete info;
- return B_OK;
-}
-
-