Beispiel #1
0
BMMRES BitmapIO_GIF::Write(int frame) {
     
	//-- If we haven't gone through an OpenOutput(), leave

	if (openMode != BMM_OPEN_W)
		return (ProcessImageIOError(&bi,BMMRES_INTERNALERROR));

     //-- Resolve Filename --------------------------------

     TCHAR filename[MAX_PATH];

     if (frame == BMM_SINGLEFRAME) {
        _tcscpy(filename,bi.Name());
     } else {
        if (!BMMCreateNumberedFilename(bi.Name(),frame,filename)) {
			return (ProcessImageIOError(&bi,BMMRES_NUMBEREDFILENAMEERROR));
        }
     }
     
     //-- Create Image File -------------------------------
     
     File file(filename, _T("wb"));
     
     if (!file.stream) {
		return (ProcessImageIOError(&bi));
     }

	// Below this line formatted for Tom's editor (sorry.)

	outStream = file.stream;

	// Find out what kind of output file we're dealing with

	saveStorage = map->Storage();
	if(!saveStorage)
		return (ProcessImageIOError(&bi,BMMRES_INTERNALERROR));

	int result = SaveGIF(map);

	switch(result) {
		case 1:
			return BMMRES_SUCCESS;
		case 0:
		default:
			return (ProcessImageIOError(&bi,GetString(IDS_WRITE_ERROR)));
		}

}
Beispiel #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
}