Esempio n. 1
0
TCHAR* SaveImage(FREE_IMAGE_FORMAT fif, FIBITMAP* dib, TCHAR* pszFilename, TCHAR* pszExt, int flag) {
	int ret=0;
	TCHAR* pszFile = NULL;
	TCHAR* FileExt = GetFileExt(pszFilename);
	if(!FileExt) {
		if(!pszExt) return NULL;
		mir_tcsadd(pszFile, pszFilename);
		mir_tcsadd(pszFile, _T("."));
		mir_tcsadd(pszFile, pszExt);
	}
	else {
		mir_tcsadd(pszFile, pszFilename);
	}

	if(fif==FIF_UNKNOWN) {
		fif = FIP->FI_GetFIFFromFilenameU(pszFile);
	}

	ret = FIP->FI_SaveU(fif, dib, pszFile, flag);


	mir_free(FileExt);

	if(ret) return pszFile;
	mir_free(pszFile);
	return NULL;
}
Esempio n. 2
0
//---------------------------------------------------------------------------
INT_PTR TfrmMain::SaveScreenshot(FIBITMAP* dib) {
    //generate File name
    FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
    LPTSTR ret;
    LPTSTR path = NULL;
    LPTSTR pszFilename = NULL;
    LPTSTR pszFileDesc = NULL;
    if (!dib) return 1;		//error
    unsigned FileNumber=db_get_dw(NULL,SZ_SENDSS,"FileNumber",0)+1;
    if(FileNumber>99999) FileNumber=1;
    //Generate FileName
    mir_tcsadd(path, m_FDestFolder);
    if (path[_tcslen(path)-1] != _T('\\')) mir_tcsadd(path, _T("\\"));
    mir_tcsadd(path, _T("shot%.5u"));//on format change, adapt "len" below
    size_t len=_tcslen(path)+2;
    pszFilename = (LPTSTR)mir_alloc(sizeof(TCHAR)*(len));
    mir_sntprintf(pszFilename,len,path,FileNumber);
    mir_free(path);

    //Generate a description according to the screenshot
    TCHAR winText[1024];
    mir_tcsadd(pszFileDesc, TranslateT("Screenshot "));
    if (m_opt_tabCapture == 0 && m_opt_chkClientArea) {
        mir_tcsadd(pszFileDesc, TranslateT("for Client area "));
    }
    mir_tcsadd(pszFileDesc, TranslateT("of \""));
    GetDlgItemText(m_hwndTabPage, ID_edtCaption, winText, 1024);
    mir_tcsadd(pszFileDesc, winText);
    if(m_opt_tabCapture==1)
        mir_tcsadd(pszFileDesc, _T("\""));
    else
        mir_tcsadd(pszFileDesc, TranslateT("\" Window"));

    // convert to 32Bits (make shure it is 32bit)
    FIBITMAP *dib_new = FIP->FI_ConvertTo32Bits(dib);
    //RGBQUAD appColor = { 245, 0, 254, 0 };	//bgr0	schwarz
    //FIP->FI_SetBackgroundColor(dib_new, &appColor);
    FIP->FI_SetTransparent(dib_new,TRUE);

    // Investigates the color type of the bitmap (test for RGB or CMYK colour space)
    switch (FREE_IMAGE_COLOR_TYPE ColTye=FIP->FI_GetColorType(dib_new)) {
    case FIC_MINISBLACK:
    //Monochrome bitmap (1-bit) : first palette entry is black.
    //Palletised bitmap (4 or 8-bit) and single channel non standard bitmap: the bitmap has a greyscale palette
    case FIC_MINISWHITE:
    //Monochrome bitmap (1-bit) : first palette entry is white.
    //Palletised bitmap (4 or 8-bit) : the bitmap has an inverted greyscale palette
    case FIC_PALETTE:
    //Palettized bitmap (1, 4 or 8 bit)
    case FIC_RGB:
    //High-color bitmap (16, 24 or 32 bit), RGB16 or RGBF
    case FIC_RGBALPHA:
    //High-color bitmap with an alpha channel (32 bit bitmap, RGBA16 or RGBAF)
    case FIC_CMYK:
    //CMYK bitmap (32 bit only)
    default:
        break;
    }

//	bool bDummy = !(FIP->FI_GetICCProfile(dib_new)->flags & FIICC_COLOR_IS_CMYK);

    FIBITMAP *dib32,*dib24;
    HWND hwndCombo = GetDlgItem(m_hWnd, ID_cboxFormat);
    switch (ComboBox_GetItemData(hwndCombo, ComboBox_GetCurSel(hwndCombo))) {
    case 0: //PNG
        ret = SaveImage(fif,dib_new, pszFilename, _T("png"));
        break;

    case 1: //JPG
        /*
        #define JPEG_QUALITYSUPERB  0x80	// save with superb quality (100:1)
        #define JPEG_QUALITYGOOD    0x0100	// save with good quality (75:1)
        #define JPEG_QUALITYNORMAL  0x0200	// save with normal quality (50:1)
        #define JPEG_QUALITYAVERAGE 0x0400	// save with average quality (25:1)
        #define JPEG_QUALITYBAD     0x0800	// save with bad quality (10:1)
        #define JPEG_PROGRESSIVE	0x2000	// save as a progressive-JPEG (use | to combine with other save flags)
        */
        dib32 = FIP->FI_Composite(dib_new,FALSE,&m_AlphaColor,NULL);
        dib24 = FIP->FI_ConvertTo24Bits(dib32);
        FIP->FI_Unload(dib32);
        ret = SaveImage(fif,dib24, pszFilename, _T("jpg"));
        FIP->FI_Unload(dib24);
        break;

    case 2: //BMP
        //	ret = SaveImage(FIF_BMP,dib_new, pszFilename, _T("bmp")); //32bit alpha BMP
        dib32 = FIP->FI_Composite(dib_new,FALSE,&m_AlphaColor,NULL);
        dib24 = FIP->FI_ConvertTo24Bits(dib32);
        FIP->FI_Unload(dib32);
        ret = SaveImage(FIF_BMP,dib24, pszFilename, _T("bmp"));
        FIP->FI_Unload(dib24);
        break;

    case 3: //TIFF (miranda freeimage interface do not support save tiff, we udse GDI+)
    {
        LPTSTR pszFile = NULL;
        mir_tcsadd(pszFile, pszFilename);
        mir_tcsadd(pszFile, _T(".tif"));

        dib32 = FIP->FI_Composite(dib_new,FALSE,&m_AlphaColor,NULL);
        dib24 = FIP->FI_ConvertTo24Bits(dib32);
        FIP->FI_Unload(dib32);

        HBITMAP hBmp = FIP->FI_CreateHBITMAPFromDIB(dib24);
        FIP->FI_Unload(dib24);
        SaveTIF(hBmp, pszFile);
        ret=pszFile;
        DeleteObject(hBmp);
    }
    break;

    case 4: //GIF
    {
        //dib24 = FIP->FI_ConvertTo8Bits(dib_new);
        //ret = SaveImage(FIF_GIF,dib24, pszFilename, _T("gif"));
        //FIP->FI_Unload(dib24);
        LPTSTR pszFile = NULL;
        mir_tcsadd(pszFile, pszFilename);
        mir_tcsadd(pszFile, _T(".gif"));
        HBITMAP hBmp = FIP->FI_CreateHBITMAPFromDIB(dib_new);
        SaveGIF(hBmp, pszFile);
        ret=pszFile;
        DeleteObject(hBmp);
    }
    break;

    default:
        ret=NULL;
    }
    /*	//load PNG and save file in user format (if differ)
    	//this get better result for transparent aereas
    	//LPTSTR pszFormat = (LPTSTR)ComboBox_GetItemData(hwndCombo, ComboBox_GetCurSel(hwndCombo));
    	TCHAR pszFormat[6];
    	ComboBox_GetText(hwndCombo, pszFormat, 6);
    	if(ret && (_tcsicmp (pszFormat,_T("png")) != 0)) {

    			fif = FIP->FI_GetFIFFromFilenameU(ret);
    			dib_new = FIP->FI_LoadU(fif, ret,0);


    		if(dib_new) {
    			DeleteFile(ret);
    			mir_freeAndNil(ret);
    			FIBITMAP *dib_save = FIP->FI_ConvertTo24Bits(dib_new);
    			ret = SaveImage(FIF_UNKNOWN,dib_save, pszFilename, pszFormat);
    			FIP->FI_Unload(dib_new); dib_new = NULL;
    			FIP->FI_Unload(dib_save); dib_save = NULL;
    		}
    	}*/
    FIP->FI_Unload(dib_new);
    mir_freeAndNil(pszFilename);

    if(ret) {
        db_set_dw(NULL,SZ_SENDSS,"FileNumber",FileNumber);
        mir_freeAndNil(m_pszFile);
        m_pszFile=ret;
        mir_freeAndNil(m_pszFileDesc);
        if(IsWindowEnabled(GetDlgItem(m_hWnd,ID_btnDesc)) && m_opt_btnDesc) {
            m_pszFileDesc=pszFileDesc;
        } else {
            mir_free(pszFileDesc);
            mir_tcsadd(m_pszFileDesc, _T(""));
        }

        if(m_cSend) {
            mir_freeAndNil(m_cSend->m_pszFile);
            m_cSend->m_pszFile=mir_tstrdup(m_pszFile);
            mir_freeAndNil(m_cSend->m_pszFileDesc);
            m_cSend->m_pszFileDesc=mir_tstrdup(m_pszFileDesc);
        }
        return 0;//OK
    }
    mir_free(pszFileDesc);
    return 1;//error
}
Esempio n. 3
0
//---------------------------------------------------------------------------
//WM_INITDIALOG:
void TfrmMain::wmInitdialog(WPARAM wParam, LPARAM lParam) {
    HWND hCtrl;
    //Taskbar and Window icon
    SendMessage(m_hWnd, WM_SETICON, ICON_BIG,	(LPARAM)IcoLib_GetIcon(ICO_PLUG_SSWINDOW1, true));
    SendMessage(m_hWnd, WM_SETICON, ICON_SMALL,	(LPARAM)IcoLib_GetIcon(ICO_PLUG_SSWINDOW2));
    LPTSTR pt = mir_a2t(__PLUGIN_NAME);
    SetWindowText(m_hWnd, pt);
    mir_freeAndNil(pt);

    // Headerbar
    pt = mir_tstrdup((LPTSTR)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)m_hContact, (LPARAM)GCDNF_TCHAR));
    if (pt && (m_hContact != 0)) {
        LPTSTR lptString = NULL;
        mir_tcsadd(lptString , TranslateT("Send screenshot to\n"));
        mir_tcsadd(lptString , pt);
        SetDlgItemText(m_hWnd, IDC_HEADERBAR, lptString);
        mir_free(lptString);
    }
    mir_freeAndNil(pt);

    SendMessage(GetDlgItem(m_hWnd, IDC_HEADERBAR), WM_SETICON, 0, (WPARAM)IcoLib_GetIcon(ICO_PLUG_SSWINDOW1, true));

    //Timed controls
    CheckDlgButton(m_hWnd,ID_chkTimed,				m_opt_chkTimed ? BST_CHECKED : BST_UNCHECKED);
    SetDlgItemInt (m_hWnd,ID_edtTimed,				(UINT)m_opt_edtTimed, FALSE);
    SendDlgItemMessage(m_hWnd, ID_upTimed,			UDM_SETRANGE, 0, (LPARAM)MAKELONG(250, 1));
    chkTimedClick();		//enable disable Timed controls

    //create Image list for tab control
    if(m_himlTab == 0) {
        //m_himlTab = ImageList_Create(16, 16, PluginConfig.m_bIsXP ? ILC_COLOR32 | ILC_MASK : ILC_COLOR8 | ILC_MASK, 2, 0);
        m_himlTab = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 2, 0);
        ImageList_AddIcon(m_himlTab, IcoLib_GetIcon(ICO_PLUG_SSWINDOW2));
        ImageList_AddIcon(m_himlTab, IcoLib_GetIcon(ICO_PLUG_SSWINDOW2));
    }

    //create the tab control.
    {
        TAB_INFO itab;
        RECT rcClient, rcTab;
        m_hwndTab = GetDlgItem(m_hWnd, IDC_CAPTURETAB);
        TabCtrl_SetItemExtra(m_hwndTab, sizeof(TAB_INFO) - sizeof(TCITEMHEADER));

        ZeroMemory(&itab, sizeof(itab));
        itab.hwndMain	= m_hWnd;
        itab.hwndTab	= m_hwndTab;

        GetWindowRect(m_hwndTab, &rcTab);
        GetWindowRect(m_hWnd, &rcClient);

        TabCtrl_SetImageList(m_hwndTab, m_himlTab);

        // Add a tab for each of the three child dialog boxes.
        itab.tcih.mask		= TCIF_PARAM|TCIF_TEXT|TCIF_IMAGE;

        itab.tcih.pszText	= TranslateT("Window");
        itab.tcih.iImage	= 0;
        itab.hwndTabPage	= CreateDialog(hInst,MAKEINTRESOURCE(IDD_UMain_CaptureWindow), m_hWnd,DlgProc_CaptureWindow);
        TabCtrl_InsertItem(m_hwndTab, 0, &itab);
        MoveWindow(itab.hwndTabPage, (rcTab.left - rcClient.left)+2, (rcTab.top - rcClient.top), (rcTab.right - rcTab.left) - 2*5, (rcTab.bottom - rcTab.top) - 2*20, TRUE);
        ShowWindow(itab.hwndTabPage, SW_HIDE);
        CheckDlgButton(itab.hwndTabPage, ID_chkClientArea, m_opt_chkClientArea ? BST_CHECKED : BST_UNCHECKED);

        itab.tcih.pszText	= TranslateT("Desktop");
        itab.tcih.iImage	= 1;
        itab.hwndTabPage	= CreateDialog(hInst,MAKEINTRESOURCE(IDD_UMain_CaptureDesktop), m_hWnd, DlgProc_CaptureDesktop);
        TabCtrl_InsertItem(m_hwndTab, 1, &itab);
        MoveWindow(itab.hwndTabPage, (rcTab.left - rcClient.left)+2, (rcTab.top - rcClient.top), (rcTab.right - rcTab.left) - 2*5, (rcTab.bottom - rcTab.top) - 2*20, TRUE);
        ShowWindow(itab.hwndTabPage, SW_HIDE);

        hCtrl = GetDlgItem(itab.hwndTabPage, ID_edtCaption);
        ComboBox_ResetContent(hCtrl);
        ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("<Entire Desktop>"))  ,0);
        ComboBox_SetCurSel (hCtrl,0);
        if(m_MonitorCount >1) {
            TCHAR	tszTemp[120];
            for (size_t i = 0; i < m_MonitorCount; ++i) {
                mir_sntprintf(tszTemp, SIZEOF(tszTemp),_T("%i. %s%s"),
                              i+1,
                              TranslateT("Monitor"),
                              (m_Monitors[i].dwFlags & MONITORINFOF_PRIMARY) ? TranslateT(" (primary)") : _T("")
                             );
                ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, tszTemp)  , i+1);
            }
            ComboBox_SelectItemData (hCtrl, -1, m_opt_cboxDesktop);	//use Workaround for MS bug ComboBox_SelectItemData
        }
        PostMessage(m_hWnd, WM_COMMAND, MAKEWPARAM(ID_edtCaption, CBN_SELCHANGE),(LPARAM)hCtrl);

        //select tab and set m_hwndTabPage
        TabCtrl_SetCurSel(m_hwndTab, m_opt_tabCapture);
        ZeroMemory(&itab, sizeof(itab));
        itab.tcih.mask = TCIF_PARAM;
        TabCtrl_GetItem(m_hwndTab,TabCtrl_GetCurSel(m_hwndTab),&itab);
        ShowWindow(itab.hwndTabPage,SW_SHOW);
        m_hwndTabPage = itab.hwndTabPage;
    }
    //init Format combo box
    {
        hCtrl = GetDlgItem(m_hWnd, ID_cboxFormat);
        ComboBox_ResetContent(hCtrl);
        ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("PNG")),0);
        ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("JPG")),1);
        ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("BMP")),2);
        ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("TIF")),3);
        ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("GIF")),4);
        ComboBox_SelectItemData (hCtrl, -1, m_opt_cboxFormat);	//use Workaround for MS bug ComboBox_SelectItemData
    }
    //init SendBy combo box
    {
        hCtrl = GetDlgItem(m_hWnd, ID_cboxSendBy);
        ComboBox_ResetContent(hCtrl);
        ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("<Only save>"))  ,SS_JUSTSAVE);
        if (m_hContact) {
            ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("File Transfer")),SS_FILESEND);
        }
        else if(m_opt_cboxSendBy == SS_FILESEND) {
            m_opt_cboxSendBy = SS_IMAGESHACK;
        }
        ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("E-mail"))       ,SS_EMAIL);
        if (myGlobals.PluginHTTPExist) {
            ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("HTTP Server"))  ,SS_HTTPSERVER);
        }
        else if(m_opt_cboxSendBy == SS_HTTPSERVER) {
            m_opt_cboxSendBy = SS_IMAGESHACK;
        }
        if (myGlobals.PluginFTPExist) {
            ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("FTP File"))     ,SS_FTPFILE);
        }
        else if(m_opt_cboxSendBy == SS_FTPFILE) {
            m_opt_cboxSendBy = SS_IMAGESHACK;
        }
        ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("ImageShack"))   ,(BYTE)SS_IMAGESHACK);
        ComboBox_SelectItemData (hCtrl, -1, m_opt_cboxSendBy);	//use Workaround for MS bug ComboBox_SelectItemData
        cboxSendByChange();		//enable disable controls
    }
    //init footer options
    CheckDlgButton(m_hWnd,ID_chkOpenAgain, m_opt_chkOpenAgain ? BST_CHECKED : BST_UNCHECKED);

    if (hCtrl = GetDlgItem(m_hWnd, ID_btnAbout)) {
        SendDlgItemMessage(m_hWnd, ID_btnAbout, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Information"), MBBF_TCHAR);
        HICON hIcon = IcoLib_GetIcon(ICO_PLUG_SSHELP);
        SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
        SetWindowText(hCtrl, hIcon ? _T("") : _T("?"));
    }

    if (hCtrl = GetDlgItem(m_hWnd, ID_btnExplore)) {
        SendDlgItemMessage(m_hWnd, ID_btnExplore, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Open Folder"), MBBF_TCHAR);
        HICON hIcon = IcoLib_GetIcon(ICO_PLUG_SSFOLDERO);
        SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
        SetWindowText(hCtrl, hIcon ? _T("") : _T("..."));
    }

    if (hCtrl = GetDlgItem(m_hWnd, ID_btnDesc)) {
        SendDlgItemMessage(m_hWnd, ID_btnDesc, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Fill description textbox."), MBBF_TCHAR);
        HICON hIcon = IcoLib_GetIcon(m_opt_btnDesc ? ICO_PLUG_SSDESKON : ICO_PLUG_SSDESKOFF);
        SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
        SetWindowText(hCtrl, hIcon ? _T("") : _T("D"));
        SendMessage(hCtrl, BM_SETCHECK, m_opt_btnDesc ? BST_CHECKED : BST_UNCHECKED, NULL);
    }

    if (hCtrl = GetDlgItem(m_hWnd, ID_btnDeleteAfterSend)) {
        SendDlgItemMessage(m_hWnd, ID_btnDeleteAfterSend, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Delete after send"), MBBF_TCHAR);
        HICON hIcon = IcoLib_GetIcon(m_opt_btnDeleteAfterSend ? ICO_PLUG_SSDELON : ICO_PLUG_SSDELOFF);
        SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
        SetWindowText(hCtrl, hIcon ? _T("") : _T("X"));
        SendMessage(hCtrl, BM_SETCHECK, m_opt_btnDeleteAfterSend ? BST_CHECKED : BST_UNCHECKED, NULL);
    }

    if (hCtrl = GetDlgItem(m_hWnd, ID_btnCapture)) {
        SendDlgItemMessage(m_hWnd, ID_btnCapture, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Capture"), MBBF_TCHAR);
        HICON hIcon = IcoLib_GetIcon(ICO_PLUG_OK);
        SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
        SetWindowText(hCtrl, TranslateT("&Capture"));
        SendMessage(hCtrl, BUTTONSETDEFAULT, (WPARAM)1, NULL);
    }

//	CheckDlgButton(m_hWnd,ID_chkEditor, m_opt_chkEditor ? BST_CHECKED : BST_UNCHECKED);
    TranslateDialogDefault(m_hWnd);
}