示例#1
0
BOOL ConvertTo(LPIMAGE lpImage, int iFunction)
/***********************************************************************/
{
CONVERT_PARMS parms;
DITHER_TYPE DitherType = DT_NONE;

if (ImgInMaskEditMode(lpImage))
	return(FALSE);
ImgGetTypeInfo(lpImage, &parms.cmsInfo.src);
switch (iFunction)
	{
	case IDM_CONVLA:
		FrameSetTypeInfo(&parms.cmsInfo.dst, FDT_LINEART);
		break;
	case IDM_CONVSP:
		FrameSetTypeInfo(&parms.cmsInfo.dst, FDT_LINEART);
		DitherType = DT_SCATTER;
		break;
	case IDM_CONVCT:
		FrameSetTypeInfo(&parms.cmsInfo.dst, FDT_GRAYSCALE);
		break;
	case IDM_CONVPALETTE:
		FrameSetTypeInfo(&parms.cmsInfo.dst, FDT_PALETTECOLOR);
		if ( !AstralDlg( NO, PictPubApp.GetResourceHandle(), PictPubApp.Get_hWndAstral(), IDD_CONVERTTO, DlgConvertProc ))
			return( NO );
		DitherType = Convert.ConvertDitherType;
		break;
	case IDM_CONVRGBCOLOR:
		if (Control.CMSEnabled && IsSrcPTSelected(&parms.cmsInfo.src.ptInfo))
		{
			CMSINFO	CmsInfo;

			CmsInfo.src.DataType = FDT_CMYKCOLOR;

			if (!CmsGetDstPT(&CmsInfo))
				return(FALSE);
			else
				parms.cmsInfo.dst = CmsInfo.dst;		
		}
		else
		{
			FrameSetTypeInfo(&parms.cmsInfo.dst, FDT_RGBCOLOR);
		}
		break;
	case IDM_CONVCMYKCOLOR:
		if (Control.CMSEnabled && IsSrcPTSelected(&parms.cmsInfo.src.ptInfo))
		{
			CMSINFO	CmsInfo;

			CmsInfo.src.DataType = FDT_RGBCOLOR;

			if (!CmsGetDstPT(&CmsInfo))
				return(FALSE);
			else
				parms.cmsInfo.dst = CmsInfo.dst;		
		}
		else
		{
			FrameSetTypeInfo(&parms.cmsInfo.dst, FDT_CMYKCOLOR);
		}
		break;
	case IDM_COLORMANAGED:
		if (!CmsGetSrcDstPT(&parms.cmsInfo))
			return(TRUE);
		break;
	}
parms.DitherType = DitherType;
parms.ConvertType = Convert.ConvertType;
parms.iLevels = Convert.ConvertColors;
lstrcpy(parms.szPalette, Convert.ConvertPalette);
ProcessCommand(lpImage->lpCmdList, IDS_CMD_CONVERT, &parms);
return(TRUE);
}
示例#2
0
BOOL ConvertImage(LPIMAGE lpImage, LPCONVERT_PARMS lpParms)
/***********************************************************************/
{
BOOL fRet = FALSE;
LPFRAME lpDstFrame, lpBaseFrame;
LPOBJECT lpBase, lpObject;
BOOL fError, fOptimize, fProgressSet;
INTERNAL_DATA data;
int	inDepth, iMaxWidth, nColors, i;
LPCOLORMAP lpColorMap;
LPRGB lpRGB;
FRMTYPEINFO InTypeInfo, OutTypeInfo;
CFrameTypeConvert TypeConvert;
DITHER_TYPE DitherType = DT_DEFAULT;

if (ImgInMaskEditMode(lpImage))
	return(TRUE);

lpColorMap = NULL;

lpBase = ImgGetBase(lpImage);
lpBaseFrame = ObjGetEditFrame(lpBase);
inDepth = FrameDepth(lpBaseFrame);

OutTypeInfo = lpParms->cmsInfo.dst;
FrameGetTypeInfo(lpBaseFrame, &InTypeInfo);

// are we try to convert to a color managed image?
if (Control.CMSEnabled && IsDstPTSelected(&OutTypeInfo.ptInfo))
	{
	// see if our image already has a color managed source
	if (!IsSrcPTSelected(&InTypeInfo.ptInfo))
		{
		// nope, see if the source passed in is valid for this image
		if (IsSrcPTSelected(&lpParms->cmsInfo.src.ptInfo) &&
			(lpParms->cmsInfo.src.DataType == InTypeInfo.DataType))
			{	
			InTypeInfo = lpParms->cmsInfo.src;
			}
		// go get a source from the user
		else
			{
			CMSINFO CmsInfo2;
			if( CmsGetSrcPTType( &InTypeInfo, &CmsInfo2) )
				InTypeInfo = CmsInfo2.src;
			}
		}
	}
else
 	FrameSetTypeInfo(&InTypeInfo, InTypeInfo.DataType, InTypeInfo.ColorMap);

// no conversion necessary
if (FrameTypeInfoEqual(InTypeInfo, OutTypeInfo))
	return(TRUE);

DitherType = lpParms->DitherType;
fOptimize = lpParms->ConvertType == CT_OPTIMIZED;
fProgressSet = FALSE;


if ( OutTypeInfo.DataType == FDT_PALETTECOLOR/* && inDepth >= 3 */)
	{
	if (lpParms->ConvertType == CT_CUSTOM)
		{
		FNAME szFileName;

		if ( !LookupExtFileN( lpParms->szPalette, szFileName, IDN_PALETTE, NO ) )
			return(FALSE);
		if (!(lpColorMap = Palette_ReadColorMap(szFileName)))
			return(FALSE);
		}
	else
		{
		// allocate a map to carry around with image
		lpColorMap = FrameCreateColorMap();
		if (!lpColorMap)
			{
			Message(IDS_EMEMALLOC);
			goto MemError;
			}

		lpColorMap->NumEntries = lpParms->iLevels;

		if (InTypeInfo.DataType == FDT_GRAYSCALE && lpColorMap->NumEntries == 256 &&
			fOptimize)
			{
			DitherType = DT_NONE;
			lpRGB = lpColorMap->RGBData;
			for (i = 0; i < lpColorMap->NumEntries; ++i)
				{
				lpRGB->red = lpRGB->green = lpRGB->blue = i;
				++lpRGB;
				}
			}
		else
			{
			// 1. CreateOptimizedPalette phase - only if fOptimize
			// 2. Mapping phase
			ProgressBegin(fOptimize ? 2 : 1,
					lpParms->Common.idDirty-IDS_UNDOFIRST+IDS_PROGFIRST);
			fProgressSet = TRUE;
			if (fOptimize)
				ProgressBegin(1, 0);
			if (!CreateOptimizedPalette(lpBase, ObjGetEditFrame(lpBase),
									lpColorMap->RGBData, &lpColorMap->NumEntries,
									fOptimize,
									fOptimize ? AstralClockCursor : NULL))
				{
				if (fOptimize)
					ProgressEnd();
				Message(IDS_EMEMALLOC);
				goto ExitFalse;
				}
			if (fOptimize)
				ProgressEnd();
			}
		}
	if (lpColorMap->NumEntries <= 16)
		lpColorMap->NumEntries = 16;
	else
		lpColorMap->NumEntries = 256;
	FrameSetTypeInfo(&OutTypeInfo, FDT_PALETTECOLOR, lpColorMap);
	}

if (!fProgressSet)
	ProgressBegin(1, lpParms->Common.idDirty-IDS_UNDOFIRST+IDS_PROGFIRST);
fProgressSet = TRUE;
	
iMaxWidth = 0;
lpObject = NULL;
while (lpObject = ImgGetNextObject(lpImage, lpObject, YES, NO))
	{
	if (RectWidth(&lpObject->rObject) > iMaxWidth)
		iMaxWidth = RectWidth(&lpObject->rObject);
	}
if (!TypeConvert.Init(InTypeInfo, OutTypeInfo, iMaxWidth, DitherType))
	{
	Message(IDS_EMEMALLOC);
	goto ExitFalse;
	}

if (ImgMultipleObjects(lpImage))
	{
	ProgressBegin(ImgCountObjects(lpImage), 0);
	
	if ( !ImgEditInit(lpImage, ET_ALLOBJECTS, UT_NEWDATA|UT_COLORMAP, lpBase) )
		goto ExitFalse;

	fError = NO;
	lpObject = NULL;
	while (lpObject = ImgGetNextObject(lpImage, lpObject, YES, NO))
		{
		lpDstFrame = ConvertFrame(ObjGetEditFrame(lpObject), OutTypeInfo, &TypeConvert);
		if (!lpDstFrame)
			{
			fError = YES;
			break;
			}
 		ImgEditedObjectFrame( lpImage, lpObject, lpParms->Common.idDirty, NULL,
						lpDstFrame, NULL);
		}

	if (fError)
		{
		lpObject = NULL;
		while (lpObject = ImgGetNextObject(lpImage, lpObject, YES, NO))
			{
			if (lpObject->Pixmap.UndoFrame)
				{
		 		lpDstFrame = lpObject->Pixmap.EditFrame;
		 		lpObject->Pixmap.EditFrame = lpObject->Pixmap.UndoFrame;
		 		lpObject->Pixmap.UndoFrame = NULL;
		 		FrameClose(lpDstFrame);
		 		}
			}
		}
	ProgressEnd();
	}
else
	{
	if ( !ImgEditInit(lpImage, ET_OBJECT, UT_NEWDATA|UT_COLORMAP, lpBase) )
		goto ExitFalse;

	ProgressBegin(1, 0);
	lpDstFrame = ConvertFrame(lpBaseFrame, OutTypeInfo, &TypeConvert);
	ProgressEnd();

	if (!lpDstFrame)
		goto ExitFalse;
	/* Setup the new image and bring up the new image window */
	ImgEditedObjectFrame( lpImage, lpBase, lpParms->Common.idDirty, NULL,
						lpDstFrame, NULL);
	}

switch (lpParms->cmsInfo.dst.DataType)
	{
	case FDT_LINEART:
		lpImage->DataType = IDC_SAVELA;
		break;
	case FDT_GRAYSCALE:
		lpImage->DataType = IDC_SAVECT;
		break;
	case FDT_PALETTECOLOR:
		lpImage->DataType = IDC_SAVE8BITCOLOR;
		break;
	case FDT_RGBCOLOR:
		lpImage->DataType = IDC_SAVE24BITCOLOR;
		break;
	case FDT_CMYKCOLOR:
		lpImage->DataType = IDC_SAVE32BITCOLOR;
		break;
	}
ImgColorMapChanged(lpImage);
lpParms->Common.UpdateType = UT_DATATYPE;

fRet = TRUE;

ExitFalse:
if (fProgressSet)
	ProgressEnd();
MemError:
if (lpColorMap)
	FrameDestroyColorMap(lpColorMap);
return(fRet);
}
示例#3
0
BOOL HandleSaveCommand(HWND hWindow, WPARAM wParam, BOOL fCommand)
/***********************************************************************/
{
FNAME szFileName;
//LPSTR lpString;
int idDataType, idOldDataType, idFileType, idOldFileType;
BOOL fChanged, fStatus;
DWORD dwReturn;

if (ImgInMaskEditMode(lpImage))
	{
	ImgSetupMaskEditMode(lpImage);
	UpdateStatusBar(NO, NO, NO, NO);
	}
fStatus = YES;
switch (wParam)
	{
	case IDM_SAVE:
	if ( !lpImage )
		break;
	PPOLEClientNotify( (LPIMAGEOBJECT)lpImage->pObj, OLE_CHANGED );
#ifdef USEOLE
	OleSavedServerDoc( lpImage->lhDoc );
#endif // #ifdef USEOLE
	if ( lpImage->fOwnedByClient )
		{ // If it IS embedded client data, inform the client
//		ImgEditApplyAll( lpImage, YES/*fApplyData*/, YES/*fApplyAlpha*/ );
		break;
		}
	/* Save the image under the current name */
	if ( !lpImage->fUntitled) /* If the picture has a name, save into it */
		{
		if ( !(fStatus = AstralImageSave( lpImage->FileType,
			lpImage->DataType, lpImage->CurFile )) )
			break;
		SetImgChanged(lpImage, NO);
//		ImgEditApplyAll( lpImage, YES/*fApplyData*/, YES/*fApplyAlpha*/ );
		break;
		}
	/* else fall through to SaveAs... */

	case IDM_SAVEAS:
	if ( !lpImage )
		break;
	/* Bring up the modal 'SaveAs' box */
	// save current image format information
	lstrcpy(szFileName, lpImage->CurFile);
	fChanged = lpImage->fChanged;
	idOldDataType = lpImage->DataType;
	idOldFileType = IDN_ART;    // save all as ART files

	// ask user for a name
	if ( !(dwReturn = DoOpenDlg( hWindow, IDD_SAVEAS,
	     lpImage->FileType, szFileName, YES )) )
		{
		fStatus = NO;
		break;
		}

	// save the image in the user specified file type and data type
	idFileType = LOWORD( dwReturn );
	idDataType = HIWORD( dwReturn );

	if ( !(fStatus = AstralImageSave( idFileType, idDataType, szFileName )))
		break;

//	// If it IS NOT embedded client data, inform the client
	PPOLEClientNotify( (LPIMAGEOBJECT)lpImage->pObj, OLE_CHANGED );
	
#ifdef USEOLE
	OleSavedServerDoc( lpImage->lhDoc );
#endif // #ifdef USEOLE
	
	// whenever you save changes become permanent - NOT ANY MORE - tmr
	SetImgChanged(lpImage, NO);
//	ImgEditApplyAll( lpImage, YES/*fApplyData*/, YES/*fApplyAlpha*/ );

	// Add the file name to our recall list
	AddRecallImageName( szFileName );

	if (!fCommand)
		break;

	// If this is a chunked image, don't revert or change name
	if (lpImage->DocumentType == IMG_DOCPIECE)
		break;
	if (ImgInMaskEditMode(lpImage))
		break;

	// if data type or file type did not change, just take new name
	if ( idDataType == idOldDataType && idFileType == idOldFileType )
		{ // it has the same FileType, same DataType
		lpImage->fUntitled = NO;
			lstrcpy( lpImage->CurFile, szFileName );
			/* Force the non-client area (title bar) of image to paint */
				SetTitleBar(lpImage->hWnd);
#ifdef USEOLE		
		// If it IS NOT embedded client data, inform the client
		OleRenameServerDoc( lpImage->lhDoc, lpImage->CurFile);
#endif // #ifdef USEOLE		
		break;
		}

	// see if the user wants to convert to using the new format
	if ( !AstralAffirm(IDS_CONFIRM_CONVERT) )
		{ // the user doesn't want to convert to the new format
		lpImage->fChanged = fChanged; // restore the changed flag
		break;
		}

	// the user wants to convert to the new format
	lpImage->FileType = idFileType;
	lpImage->DataType = idDataType;
	lpImage->fUntitled = NO;
	lstrcpy( lpImage->CurFile, szFileName );
	/* Force the non-client area (title bar) of image to paint */
		SetTitleBar(lpImage->hWnd);
#ifdef USEOLE		
		// If it IS NOT embedded client data, inform the client
		OleRenameServerDoc( lpImage->lhDoc, lpImage->CurFile);
#endif // #ifdef USEOLE		
	DoCommand(hWindow, IDM_REVERT, 0L);
	break;

	case IDM_SAVESPECIAL:
	if ( !lpImage )
		break;
	// save current image format information
	lstrcpy(szFileName, lpImage->CurFile);
	fChanged = lpImage->fChanged;
	idOldDataType = lpImage->DataType;
	idOldFileType = IDN_ART;    // save all as ART files

	if (lpImage->fUntitled)
	{
    	// get the new name for the file
    	GetNextIniFilename ((char FAR *)&szFileName);
    	SaveToIniEntry (szFileName, NULL);
    }
	else
	{
		lstrcpy (szFileName, lpImage->CurFile);
	}
    // save the image as the same type
    idFileType = idOldFileType;
    idDataType = idOldDataType;
	if ( !(fStatus = AstralImageSave( idFileType, idDataType, szFileName )))
		break;

	// whenever you save changes become permanent - NOT ANY MORE - tmr
	SetImgChanged(lpImage, NO);
//	ImgEditApplyAll( lpImage, YES/*fApplyData*/, YES/*fApplyAlpha*/ );

	// Add the file name to our recall list
	AddRecallImageName( szFileName );

	if (!fCommand)
		break;

	// If this is a chunked image, don't revert or change name
	if (lpImage->DocumentType == IMG_DOCPIECE)
		break;
	if (ImgInMaskEditMode(lpImage))
		break;

	// if data type or file type did not change, just take new name
	if ( idDataType == idOldDataType && idFileType == idOldFileType )
		{ // it has the same FileType, same DataType
		lpImage->fUntitled = NO;
			lstrcpy( lpImage->CurFile, szFileName );
			/* Force the non-client area (title bar) of image to paint */
				SetTitleBar(lpImage->hWnd);
#ifdef USEOLE
	OleRenameServerDoc( lpImage->lhDoc, lpImage->CurFile );
#endif // #ifdef USEOLE
		break;
		}

	// see if the user wants to convert to using the new format
	if ( !AstralAffirm(IDS_CONFIRM_CONVERT) )
		{ // the user doesn't want to convert to the new format
		lpImage->fChanged = fChanged; // restore the changed flag
		break;
		}

	// the user wants to convert to the new format
	lpImage->FileType = idFileType;
	lpImage->DataType = idDataType;
	lpImage->fUntitled = NO;
	lstrcpy( lpImage->CurFile, szFileName );
	/* Force the non-client area (title bar) of image to paint */
		SetTitleBar(lpImage->hWnd);
	// If it IS NOT embedded client data, inform the client
#ifdef USEOLE
	OleRenameServerDoc( lpImage->lhDoc, lpImage->CurFile );
#endif // #ifdef USEOLE
	DoCommand(hWindow, IDM_REVERT, 0L);
	break;

	default:
	break;
	}

return( fStatus );
}