Permalink
Browse files

[GUI] Allow to save selection as a set of JPEG images, apply filters …

…if preview mode is enabled
  • Loading branch information...
eumagga0x2a committed Jan 20, 2018
1 parent 1b431ed commit c740522a65c298d7b8de70c7ff351ad916707c46
Showing with 103 additions and 49 deletions.
  1. +1 −0 avidemux/common/ADM_commonUI/myOwnMenu.h
  2. +1 −1 avidemux/common/A_functions.h
  3. +101 −48 avidemux/common/gui_save.cpp
@@ -38,6 +38,7 @@ static const MenuEntry _myMenuFile[] = {
{MENU_SUBMENU,QT_TRANSLATE_NOOP("adm","Save as Image"), NULL,ACT_DUMMY ,NULL,NULL},
{MENU_SUBACTION,QT_TRANSLATE_NOOP("adm","Save as BMP"), NULL,ACT_SAVE_BMP ,NULL,"Ctrl+M"},
{MENU_SUBACTION,QT_TRANSLATE_NOOP("adm","Save as JPEG"), NULL,ACT_SAVE_JPG ,NULL,"Ctrl+E"},
{MENU_SUBACTION,QT_TRANSLATE_NOOP("adm","Save Selection as JPEG"),NULL,ACT_SAVE_BUNCH_OF_JPG,NULL,NULL},
{MENU_ACTION,QT_TRANSLATE_NOOP("adm","Close"), NULL,ACT_CLOSE ,NULL, "Ctrl+W"},
{MENU_SEPARATOR,QT_TRANSLATE_NOOP("adm","-"), NULL,ACT_DUMMY ,NULL,NULL},
{MENU_ACTION,QT_TRANSLATE_NOOP("adm","Information"), NULL,ACT_VIDEO_PROPERTIES, MKICON(info),NULL},
@@ -38,7 +38,7 @@ void A_saveAVI (const char *name);
void A_playAvi (void);
void A_queueJob (void);
int A_saveAudioCopy (const char *name);
int A_saveJpg (const char *name);
bool A_saveJpg (const char *name);
int A_saveBunchJpg(const char *name);
int A_saveImg (const char *name);
int ADM_saveRaw (const char *name);
@@ -35,6 +35,7 @@
#include "DIA_factory.h"
#include "ADM_coreJobs.h"
#include "ADM_audioWrite.h"
#include "ADM_filterChain.h"
// Local prototypes
#include "A_functions.h"
#include "ADM_script2/include/ADM_script.h"
@@ -316,22 +317,40 @@ int A_saveAudioProcessed (const char *name)
\fn A_saveJpg
\brief Save a Jpg image from current display buffer
*/
int A_saveJpg (const char *name)
bool A_saveJpg (const char *name)
{
uint8_t fl;
ADMImage *image=admPreview::getBuffer();
if(!image)
bool result=true;
uint64_t current=video_body->getCurrentFramePts();
uint64_t end=video_body->getVideoDuration();
ADM_HW_IMAGE hw=admPreview::getPreferedHwImageFormat();
ADM_videoFilterChain *chain;
if(getPreviewMode()==ADM_PREVIEW_NONE)
chain=createEmptyVideoFilterChain(current,end);
else
chain=createVideoFilterChain(current,end);
if(chain && chain->size())
{
printf("[SaveJpeg] No image\n");
return false;
}
if(!image->saveAsJpg (name))
{
GUI_Error_HIG(QT_TRANSLATE_NOOP("adm","Jpeg"),QT_TRANSLATE_NOOP("adm","Fail to save as jpeg"));
return false;
ADM_coreVideoFilter *filter;
filter=chain->back();
FilterInfo *info=filter->getInfo();
uint32_t width=info->width;
uint32_t height=info->height;
ADMImage *image=new ADMImageDefault(width,height);
uint32_t fn;
if(!filter->getNextFrameAs(hw,&fn,image))
{
ADM_error("No image\n");
result=false;
}
if(result && !image->saveAsJpg (name))
{
GUI_Error_HIG(QT_TRANSLATE_NOOP("adm","Jpeg"),QT_TRANSLATE_NOOP("adm","Failed to save as JPEG"));
result=false;
}
delete image;
image=NULL;
}
return true ;
return result;
}
@@ -342,48 +361,82 @@ int A_saveJpg (const char *name)
*/
int A_saveBunchJpg(const char *name)
{
ADMImage *src=NULL;
uint32_t curImg;
char fullName[2048],*ext;
char *baseName;
DIA_workingBase *working;
uint8_t success=0;
ADM_error("Broken\n");
return 0;
#if 0
int success=0;
uint64_t pts=admPreview::getCurrentPts();
uint64_t start=video_body->getMarkerAPts();
uint64_t end=video_body->getMarkerBPts();
uint64_t inc=video_body->getFrameIncrement();
uint64_t original=pts;
pts=start;
admPreview::deferDisplay(true);
admPreview::seekToTime(start);
ADM_HW_IMAGE hw=admPreview::getPreferedHwImageFormat();
ADM_videoFilterChain *chain;
if(getPreviewMode()==ADM_PREVIEW_NONE)
chain=createEmptyVideoFilterChain(start,end);
else
chain=createVideoFilterChain(start,end);
if(!chain || chain->empty())
{
admPreview::seekToTime(original);
admPreview::deferDisplay(false);
return 0;
}
ADM_coreVideoFilter *filter;
filter=chain->back();
FilterInfo *info=filter->getInfo();
uint32_t width=info->width;
uint32_t height=info->height;
ADMImage *src=new ADMImageDefault(width,height);
uint32_t fn;
// Split name into base + extension
ADM_PathSplit(name,&baseName,&ext);
char fullName[2048];
std::string baseName,ext;
uint32_t range=(uint32_t)((end-start)/1000);
DIA_workingBase *working;
src=new ADMImageDefault(avifileinfo->width,avifileinfo->height);
ADM_assert(src);
// Split name into base + extension
ADM_PathSplit(std::string(name),baseName,ext);
working=createWorking(QT_TRANSLATE_NOOP("adm","Saving as set of jpegs"));
for(curImg=frameStart;curImg<=frameEnd;curImg++)
working=createWorking(QT_TRANSLATE_NOOP("adm","Saving selection as set of JPEG images"));
while(pts<=end)
{
uint32_t current=(uint32_t)((pts-start)/1000);
working->update(current,range);
if(!filter->getNextFrameAs(hw,&fn,src))
{
working->update(curImg-frameStart,frameEnd-frameStart);
if (!GUI_getFrameContent (src,curImg ))
{
GUI_Error_HIG(QT_TRANSLATE_NOOP("adm","Cannot decode frame"), QT_TRANSLATE_NOOP("adm","Aborting."));
goto _bunch_abort;
}
if(!working->isAlive()) goto _bunch_abort;
sprintf(fullName,"%s%04d.jpg",baseName,curImg-frameStart);
if(!src->saveAsJpg(fullName)) goto _bunch_abort;
//GUI_Error_HIG(QT_TRANSLATE_NOOP("adm","Cannot decode frame"), QT_TRANSLATE_NOOP("adm","Aborting."));
break;
}
success=1;
_bunch_abort:
if(success)
GUI_Info_HIG(ADM_LOG_INFO,QT_TRANSLATE_NOOP("adm","Done"),QT_TRANSLATE_NOOP("adm", "Saved %d images."), curImg-frameStart);
if(src->Pts==ADM_NO_PTS)
pts+=inc;
else
GUI_Error_HIG(QT_TRANSLATE_NOOP("adm","Error"),QT_TRANSLATE_NOOP("adm", "Could not save all images."));
delete working ;
delete src;
return success;
#endif
pts=src->Pts;
success++;
if(!working->isAlive()) break;
sprintf(fullName,"%s-%04d.jpg",baseName.c_str(),success);
if(!src->saveAsJpg(fullName)) break;
if(success==9999)
{
GUI_Info_HIG(ADM_LOG_INFO,QT_TRANSLATE_NOOP("adm","Warning"),QT_TRANSLATE_NOOP("adm","Maximum number of 9999 images reached, aborting."));
break;
}
}
if(success)
GUI_Info_HIG(ADM_LOG_INFO,QT_TRANSLATE_NOOP("adm","Done"),QT_TRANSLATE_NOOP("adm","Saved %d images."),success);
else
GUI_Error_HIG(QT_TRANSLATE_NOOP("adm","Error"),QT_TRANSLATE_NOOP("adm","Saving images failed."));
delete working;
working=NULL;
delete src;
src=NULL;
admPreview::seekToTime(original);
admPreview::deferDisplay(false);
return success;
}
/**
\fn A_saveImg

0 comments on commit c740522

Please sign in to comment.