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

[ADM_gui] Copy image to clipboard #533

Open
wants to merge 1 commit 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
3 changes: 3 additions & 0 deletions avidemux/cli/ADM_userInterfaces/ADM_gui2/gui_none.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,7 @@ void UI_notifyPlaybackLag(uint32_t lag, int updateTimeMs)

void UI_tweaks(const char * op, char * paramS, int paramN)
{}

void UI_CopyImageToClipboard(void * image)
{}
// EOF
2 changes: 2 additions & 0 deletions avidemux/common/ADM_commonUI/GUI_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,6 @@ bool UI_askAvisynthPort(uint32_t &port);
bool UI_reset(void);

void UI_tweaks(const char * op, const char * paramS, int paramN);

void UI_CopyImageToClipboard(void * image);
// EOF
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","Copy to clipboard"),NULL,ACT_SAVE_IMAGE_TO_CLIPBOARD, NULL,"Ctrl+Shift+C",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 @@ -45,6 +45,7 @@ bool A_saveJpg (const char *name);
int A_saveBunchJpg(const char *name);
bool A_saveImg (const char *name);
bool A_savePng(const char *name);
void A_saveImageToClipboard(void);
int ADM_saveRaw (const char *name);
int A_audioSave(const char *name);
int A_SaveWrapper(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_IMAGE_TO_CLIPBOARD)
ACT(SAVE_VIDEO)
ACT(SAVE_AUDIO)
ACT(SAVE_QUEUE)
Expand Down
31 changes: 31 additions & 0 deletions avidemux/common/gui_save.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ void HandleAction_Save(Action action)
GUI_FileSelWriteExtension (QT_TRANSLATE_NOOP("adm","Select PNG to Save"),defaultExtension,(SELFILE_CB *)A_savePng);
}
break;
case ACT_SAVE_IMAGE_TO_CLIPBOARD:
{
A_saveImageToClipboard();
}
break;
//----------------------test-----------------------
case ACT_SAVE_VIDEO:
{
Expand Down Expand Up @@ -648,6 +653,32 @@ bool A_saveImg (const char *name)
return result;
}


/**
\fn A_saveImageToClipboard
\brief Save current displayed image to clibboard
*/
void A_saveImageToClipboard(void)
{
bool fromDisplayBuffer=false;
if(ADM_PREVIEW_NONE == admPreview::getPreviewMode())
fromDisplayBuffer=true;
ADMImage *image;
image=NULL;
if(fromDisplayBuffer)
image=admPreview::getBuffer();
else
image=getCurrentFilteredImage();
if(image)
{
UI_CopyImageToClipboard((void*)image);
}
if(!fromDisplayBuffer)
{
delete image;
image=NULL;
}
}
/**
\fn A_SaveWrapper

Expand Down
26 changes: 26 additions & 0 deletions avidemux/qt4/ADM_userInterfaces/ADM_gui/Q_gui2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,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_IMAGE_TO_CLIPBOARD)

for(uint32_t engineIdx = 0; engineIdx < _scriptEngines.size(); engineIdx++)
PUSH_LOADED(File, (Action)(ACT_SCRIPT_ENGINE_FIRST + (engineIdx * 3) + 2))
Expand Down Expand Up @@ -3792,6 +3793,31 @@ void UI_tweaks(const char * op, const char * paramS, int paramN)
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
}

/**
* \fn UI_CopyImageToClipboard
*/
void UI_CopyImageToClipboard(void * image)
{
if (!image) return;
ADMImage * img = (ADMImage *)image;
QClipboard *clipboard = QApplication::clipboard();
if (clipboard)
{
int w,h;
w = img->_width;
h = img->_height;
uint32_t size = ADM_IMAGE_ALIGN(w*4) * h;
uint8_t * rgbBuffer=new uint8_t[size];
ADMColorScalerFull scaler(ADM_CS_BICUBIC,w,h,w,h,img->_pixfrmt,ADM_PIXFRMT_BGR32A);
scaler.convertImage(img,rgbBuffer);
QImage rgbImage = QImage(rgbBuffer,w,h,ADM_IMAGE_ALIGN(w*4),QImage::Format_RGB32).copy(0,0,w,h);

clipboard->setImage(rgbImage);

rgbImage = QImage(); // detach rgbBuffer
delete [] rgbBuffer;
}
}

/**
* \fn dtor
Expand Down