Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gui_save] Save selection as PNG #389

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions avidemux/common/ADM_commonUI/myOwnMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ static const MenuEntry _myMenuFile[] = {
{MENU_SUBACTION,QT_TRANSLATE_NOOP("adm","Save as PNG"), NULL,ACT_SAVE_PNG, NULL,"Ctrl+P",0},
{MENU_SUBACTION,QT_TRANSLATE_NOOP("adm","Save as JPEG"), NULL,ACT_SAVE_JPG, NULL,"Ctrl+E",0},
{MENU_SUBACTION,QT_TRANSLATE_NOOP("adm","Save Selection as JPEG"),NULL,ACT_SAVE_BUNCH_OF_JPG,NULL,NULL,0},
{MENU_SUBACTION,QT_TRANSLATE_NOOP("adm","Save Selection as PNG"),NULL,ACT_SAVE_BUNCH_OF_PNG,NULL,NULL,0},
{MENU_ACTION,QT_TRANSLATE_NOOP("adm","Close"), NULL,ACT_CLOSE, NULL,"Ctrl+W",0},
{MENU_SEPARATOR,"-",NULL,ACT_DUMMY,NULL,NULL,1},
{MENU_ACTION,QT_TRANSLATE_NOOP("adm","Information"), NULL,ACT_VIDEO_PROPERTIES, MKICON(info),"Alt+Return",0},
Expand Down
1 change: 1 addition & 0 deletions avidemux/common/A_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void A_queueJob (void);
int A_saveAudioCopy (const char *name);
bool A_saveJpg (const char *name);
int A_saveBunchJpg(const char *name);
int A_saveBunchPng(const char *name);
bool A_saveImg (const char *name);
bool A_savePng(const char *name);
int ADM_saveRaw (const char *name);
Expand Down
1 change: 1 addition & 0 deletions avidemux/common/gui_action.names
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ ACT(SAVE_BMP)
ACT(SAVE_PNG)
ACT(SAVE_JPG)
ACT(SAVE_BUNCH_OF_JPG)
ACT(SAVE_BUNCH_OF_PNG)
ACT(SAVE_VIDEO)
ACT(SAVE_AUDIO)
ACT(SAVE_QUEUE)
Expand Down
50 changes: 41 additions & 9 deletions avidemux/common/gui_save.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ void HandleAction_Save(Action action)
GUI_FileSelWriteExtension (QT_TRANSLATE_NOOP("adm","Select JPEG Sequence to Save"),defaultExtension,(SELFILE_CB *)A_saveBunchJpg);
}
break;
case ACT_SAVE_BUNCH_OF_PNG:
{
const char *defaultExtension="png";
GUI_FileSelWriteExtension (QT_TRANSLATE_NOOP("adm","Select PNG Sequence to Save"),defaultExtension,(SELFILE_CB *)A_saveBunchPng);
}
break;
case ACT_SAVE_BMP:
{
const char *defaultExtension="bmp";
Expand Down Expand Up @@ -474,12 +480,7 @@ bool A_saveJpg (const char *name)
}


/**
\fn A_saveBunchJpg
\brief Save the selection as a bunch of jpeg 95% qual

*/
int A_saveBunchJpg(const char *name)
int saveSelectionAsImages(const char *name, bool saveAsPng)
{
#if defined(__APPLE__)
#define MAX_LEN 1024
Expand Down Expand Up @@ -549,7 +550,11 @@ int A_saveBunchJpg(const char *name)
uint32_t fn;
DIA_workingBase *working;

working=createWorking(QT_TRANSLATE_NOOP("adm","Saving selection as set of JPEG images"));
if (saveAsPng)
working=createWorking(QT_TRANSLATE_NOOP("adm","Saving selection as set of PNG images"));
else
working=createWorking(QT_TRANSLATE_NOOP("adm","Saving selection as set of JPEG images"));

while(true)
{
if(!filter->getNextFrameAs(hw,&fn,src))
Expand All @@ -565,8 +570,15 @@ int A_saveBunchJpg(const char *name)
working->update((uint32_t)pts,range);
success++;
if(!working->isAlive()) break;
sprintf(fullName,"%s-%05d.jpg",baseName.c_str(),success);
if(!src->saveAsJpg(fullName)) break;
sprintf(fullName,"%s-%05d.%s",baseName.c_str(),success, saveAsPng ? "png":"jpg");
if (saveAsPng)
{
if(!src->saveAsPng(fullName)) break;
}
else
{
if(!src->saveAsJpg(fullName)) break;
}
if(success==99999) break;
}

Expand All @@ -590,6 +602,26 @@ int A_saveBunchJpg(const char *name)
return success;
}

/**
\fn A_saveBunchJpg
\brief Save the selection as a bunch of jpeg 95% qual

*/
int A_saveBunchJpg(const char *name)
{
return saveSelectionAsImages(name, false);
}

/**
\fn A_saveBunchPng
\brief Save the selection as bunch of png

*/
int A_saveBunchPng(const char *name)
{
return saveSelectionAsImages(name, true);
}

/**
\fn A_savePng
\brief Save a PNG image from current display buffer or from filter chain
Expand Down
1 change: 1 addition & 0 deletions avidemux/qt4/ADM_userInterfaces/ADM_gui/Q_gui2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,7 @@ void MainWindow::buildActionLists(void)
PUSH_LOADED(File, ACT_SAVE_PNG)
PUSH_LOADED(File, ACT_SAVE_JPG)
PUSH_LOADED(File, ACT_SAVE_BUNCH_OF_JPG)
PUSH_LOADED(File, ACT_SAVE_BUNCH_OF_PNG)

PUSH_LOADED(File, ACT_CLOSE)
PUSH_LOADED(File, ACT_VIDEO_PROPERTIES)
Expand Down
13 changes: 10 additions & 3 deletions avidemux_core/ADM_coreImage/src/ADM_imageSave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ bool ADMImage::saveAsPngInternal(const char *filename)
AVCodecContext *context=NULL;
AVFrame *frame=NULL;
AVCodec *codec=NULL;
AVDictionary * options = NULL;
FILE *f=NULL;
bool result=false;
const uint32_t sz=ADM_IMAGE_ALIGN(_width*3)*_height;
Expand Down Expand Up @@ -338,8 +339,10 @@ bool ADMImage::saveAsPngInternal(const char *filename)
context->time_base.num=1;
context->width=_width;
context->height=_height;

r=avcodec_open2(context, codec, NULL);
context->compression_level=1; // least compression -> faster

av_dict_set(&options, "pred", "paeth", 0);
r=avcodec_open2(context, codec, &options);

if(r<0)
{
Expand Down Expand Up @@ -426,7 +429,11 @@ bool ADMImage::saveAsPngInternal(const char *filename)
av_frame_free(&frame);
frame=NULL;
}

if (options)
{
av_dict_free(&options);
options=NULL;
}
return result;
}

Expand Down