示例#1
0
static void ProcessVignette8(
	LPTR   lpSrc,
	int    iCount,
	LPGRADIENT_DATA lpGrad)
{
	long d, D, lTableRange;
	int  r;
	LFIXED rate;
	LPTR   lpMyMidPoint = lpGrad->lpMidpointTable;
	int    iTableIndex;
	int nRepetitions, SoftTransition;
	LPLONG lpld, lplD;

	lpld = lpGrad->lpld;
	lplD = lpGrad->lplD;
	lTableRange = lpGrad->lTableRange;
	nRepetitions = lpGrad->nRepetitions;
	SoftTransition = lpGrad->SoftTransition;

	if (nRepetitions == 1)
	{
		while (iCount-- > 0)
		{
			DO_RANDOM;

			REPS_EQUAL_ONE;

			iTableIndex = WHOLE(rate*lTableRange);

			QUICK_BOUND(lpMyMidPoint[iTableIndex] + r, *lpSrc);

			lpSrc++;
		}
	}
	else
	{
		while (iCount-- > 0)
		{
			DO_RANDOM;

			REPS_NOT_ONE;

			iTableIndex = WHOLE(rate*lTableRange);

			QUICK_BOUND(lpMyMidPoint[iTableIndex] + r, *lpSrc);

			lpSrc++;
		}
	}
}
示例#2
0
	// Divide the number of parametrizations in total by the number of parametrizations sharing the same regulatory function
	double computeExpectedFreq(const RegInfo & reg_info, const CompID reg_ID) 
	{
		const size_t context_c = accumulate(WHOLE(reg_info.regulators), 1, [](const size_t part_val, const pair<CompID, Levels> & regulator) {
			return part_val * (regulator.second.size() + 1);
		});
		const size_t other_c = context_c / (reg_info.regulators.at(reg_ID).size() + 1);
		double all_params = pow(reg_info.max_activity + 1, context_c);
		double same_params = pow(reg_info.max_activity + 1, other_c) * pow(reg_info.max_activity + 1, other_c * (reg_info.regulators.at(reg_ID).size() - 1));

		return 1.0 - (same_params / all_params);
	}
示例#3
0
/***************************************************************************
	ZoomBoundRect
		Takes sugested position and size for the zoom window in owner coords.
		Will set the inputs to allowed values.
***************************************************************************/
void ZoomBoundRect(int *x, int *y, int *width, int *height)
{
	LPIMAGE lpMyImage;
	RECT 	rZoom;
	int borderW, borderH, oldwidth, oldheight;
	LFIXED fRatio, fPreposedRatio;

	if (!hZoomWindow)
		return;

    lpMyImage = (LPIMAGE)GetImagePtr (hZoomWindow );
	if (!lpMyImage)
		return;
	// compute size or border
	GetWindowRect(hZoomWindow, &rZoom);
	oldwidth = rZoom.right - rZoom.left;
	oldheight = rZoom.bottom - rZoom.top;
	GetClientRect(hZoomWindow, &rZoom);
	borderW = oldwidth -(rZoom.right - rZoom.left);
	borderH = oldheight -(rZoom.bottom - rZoom.top);

//	GetClientRect(hOwner, &rOwner);
	// be sure the zoom widow is not larger than window
//	*width = Min(*width, rOwner.right - rOwner.left);
//	*height = Min(*height, rOwner.bottom - rOwner.top);

	// be sure aspect ratios are the same
	fPreposedRatio = FGET(*width-borderW, *height-borderH);
	fRatio = FGET(lpMyImage->npix, lpMyImage->nlin);

	// is it good enough?
	oldwidth = WHOLE(fRatio*(*height-borderH));
	if (oldwidth == (*width - borderW))
		return;
	
	if (fPreposedRatio > fRatio)
		{											// width too big
		*width = FMUL(*height-borderH, fRatio);
		*width += borderW;
		}
	else if (fPreposedRatio < fRatio)
		{												// height top big
		*height = FMUL(*width-borderW,
					FGET(lpMyImage->nlin, lpMyImage->npix));
		*height += borderH;
		}

//	*x = Bound (*x, -*width/2, rOwner.right-*width/2);
//	*y = Bound (*y, -*height/2, rOwner.bottom-*height/2);
	return;
}
示例#4
0
static void linear_vignette_proc( int y, int left, int right, LPTR lpDst,
                                    LPTR lpSrc, int depth,
                                    LPGRADIENT_DATA lpGrad )
{
	int xn;
	LPLONG lptld, lptlD;
	long D;

	lptld = lpGrad->lpld;
	lptlD = lpGrad->lplD;
	D = lpGrad->D;

	for (xn = left; xn <= right; ++xn)
	{
		*lptld++ = WHOLE( rotx(xn, y, lpGrad->x1, lpGrad->y1, lpGrad->cosine,
         lpGrad->sine) );
		*lptlD++ = D;
	}
	(*lpGrad->lpProcessProc)(lpSrc, right-left+1, lpGrad);
}
示例#5
0
//=======================================================================
// 	int CurveToPoints
//		lpPoints:  Bezier handle points.
//		type:  BEZIER_MARKER is the only type supported.
//		lpOutputPoints:  Result. - must be at least MAX_BEZIER_OUT or NULL
//		
//		returns the number of points written (or needed if !lpOutputPoints)
//=======================================================================
int CurveToPoints(LPPOINT lpPoints, int type, LPPOINT lpOutputPoints )
//=======================================================================
{
	int n, t, i, nOutPoints, lastx, lasty, x, y;
	int nMaxPoints;
	int nPoints;
	LFIXED tscale, fdx, fdy, tscalebase;
	FPOINT ptR[MAX_BEZIER_IN];
	LPFPOINT R;
	LPPOINT P;

	if (type != BEZIER_MARKER)
		return(0);
	nPoints = BEZIER_IN;
	
	// determine the maximum number of points we will want (may effect quality)
	x = y = INT_MAX; 
	lastx = lasty = INT_MIN;
	for (i=0;i<nPoints;i++)
	{
		x = min(x, lpPoints[i].x);
		y = min(y, lpPoints[i].y);
		lastx = max(lastx, lpPoints[i].x);
		lasty = max(lasty, lpPoints[i].y);
	}
	// get delta
	x = lastx-x;
	y = lasty-y;
	nMaxPoints = (x+y)/4;
	nMaxPoints = bound(nMaxPoints, 5, MAX_BEZIER_OUT);
	
//	Transformer(lpTForm, lpPoints, &lastx, &lasty);
	if (lpOutputPoints)
		*lpOutputPoints++ = *lpPoints; //lastx,lasty;
	nOutPoints = 1;
	
	tscalebase = FGET( 1, nMaxPoints );
	tscale = 0;
	
	for ( t=1; t<nMaxPoints; t++ )
	{
		R = ptR;
		P = lpPoints;
		n = nPoints;
		tscale += tscalebase;
		while (--n >= 0)
		{
//			FTransformer(lpTForm, P, &R->fx, &R->fy);
			R->fx = MAKEFIXED(P->x);
			R->fy = MAKEFIXED(P->y);
			R++;
			P++;
		}
		n = nPoints - 1;
		while ( --n >= 0 )
		{
			R = ptR;
			for ( i=0; i<=n; i++ )
			{
				fdx = (R+1)->fx - R->fx;
				fdy = (R+1)->fy - R->fy;
				R->fx += FIXMUL( fdx, tscale );
				R->fy += FIXMUL( fdy, tscale );
				R++;
			}
		}
		x = WHOLE(ptR[0].fx);
		y = WHOLE(ptR[0].fy);
		if (x != lastx || y != lasty)
		{
			lastx = x;
			lasty = y;
			if (lpOutputPoints)
			{
				lpOutputPoints->x = lastx;
				lpOutputPoints->y = lasty;
				lpOutputPoints++;
			}
			++nOutPoints;
		}
	}
	
	n = nPoints - 1;
	x = WHOLE(ptR[n].fx);
	y = WHOLE(ptR[n].fy);
	if (x != lastx || y != lasty)
	{
		if (lpOutputPoints)
		{
			lpOutputPoints->x = x;
			lpOutputPoints->y = y;
		}
		++nOutPoints;
	}
	return( nOutPoints );
}
示例#6
0
/// \file Entry point of tremppi_qualitative
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int tremppi_quantitative(int argc, char ** argv) 
{
	TremppiSystem::initiate("tremppi_quantitative", argc, argv);
	Logging logging;

	const vector<string> prefixes = { "K", "C", "R", "E", "B", "I" };
	RegInfos reg_infos;
	sqlite3pp::database db;
	vector<string> selections;
	vector<string> sels_name;
	DatabaseReader reader;
	try
	{
		DEBUG_LOG << "Reading data.";
		db = move(sqlite3pp::database((TremppiSystem::DATA_PATH / DATABASE_FILENAME).string().c_str()));
		selections = reader.getSelectionList();
		sels_name = reader.getSelectionNames();
		reg_infos = reader.readRegInfos(db);
	}
	catch (exception & e)
	{
		logging.exceptionMessage(e, 2);
	}

	// Create a report for each selection
	logging.newPhase("making report", selections.size());
	for (const size_t sel_no : cscope(selections))
	{
		Json::Value out;
		map<size_t, string> columns;
		vector<ComputedData> results;

		try
		{
			DEBUG_LOG << "Selection " + sels_name[sel_no];
			out = Report::createSetup(selections[sel_no], sels_name[sel_no]);
			for (const string & prefix : prefixes)
			{
				const auto new_columns = sqlite3pp::func::matchingColumns(PARAMETRIZATIONS_TABLE, regex{ prefix + "_.*" }, db);
				columns.insert(WHOLE(new_columns));
			}
			for (const pair<size_t, string> column : columns)
			{
				results.push_back(ComputedData{ column.second, 0, numeric_limits<double>::max(), -1 * numeric_limits<double>::max(), 0 });
			}
		}
		catch (exception & e)
		{
			logging.exceptionMessage(e, 3);
		}

		const size_t row_count = sqlite3pp::func::rowCount(PARAMETRIZATIONS_TABLE, out["setup"]["select"].asString(), db);
		try
		{
			DEBUG_LOG << "Reading the values, computing the statistics.";
			logging.newPhase("Reading row", row_count);
			sqlite3pp::query group_qry = DatabaseReader::selectionFilter(columns, out["setup"]["select"].asString(), db);

			// Read the data
			for (auto row : group_qry)
			{
				for (int i = 0; i < group_qry.column_count(); i++) {
					if (row.column_type(i) == SQLITE_NULL)
					{
						throw runtime_error(string("A null valued entry in the column ") + group_qry.column_name(i));
					}
					double val;
					if (row.column_type(i) == SQLITE_INTEGER)
					{
						val = row.get<int>(i);
					}
					else if (row.column_type(i) == SQLITE_FLOAT)
					{
						val = row.get<double>(i);
					}
					if (val != 0)
					{
						results[i].count++;
					}
					results[i].min = min(results[i].min, val);
					results[i].max = max(results[i].max, val);
					results[i].mean += val;

				}
				logging.step();
			}
			// Compute mean
			for (ComputedData & result : results)
			{
				result.mean = result.mean / row_count;
			}
		}
		catch (exception & e)
		{
			logging.exceptionMessage(e, 4);
		}

		try
		{
			DEBUG_LOG << "Writing results.";
			// For each graph create the graph data and add configuration details
			for (ComputedData & result : results)
			{
				Json::Value result_node;
				result_node["name"] = Report::reformName(reg_infos, result.name);
				result_node["count"] = static_cast<Json::Value::UInt>(result.count);
				result_node["min"] = result.min;
				result_node["max"] = result.max;
				result_node["mean"] = result.mean;
				out["records"].append(result_node);
			}

			FileManipulation::writeJSON(TremppiSystem::DATA_PATH / "quantitative" / (out["setup"]["s_name"].asString() + ".json"), out);
		}
		catch (exception & e)
		{
			logging.exceptionMessage(e, 5);
		}
	}
	try
	{
		PythonFunctions::configure("quantitative");
	}
示例#7
0
static void ProcessVignette24(
	LPRGB  lpSrc,
	int    iCount,
	LPGRADIENT_DATA lpGrad)
{
	long d, D, lTableRange;
	int  r;
	LFIXED rate;
	LPRGB  lpMyMidPoint = (LPRGB)lpGrad->lpMidpointTable;
	int    iTableIndex;
	int nRepetitions, SoftTransition;
	LPLONG lpld, lplD;

	lpld = lpGrad->lpld;
	lplD = lpGrad->lplD;
	lTableRange = lpGrad->lTableRange;
	nRepetitions = lpGrad->nRepetitions;
	SoftTransition = lpGrad->SoftTransition;

	if (nRepetitions == 1)
	{
		while (iCount-- > 0)
		{
			DO_RANDOM;

			REPS_EQUAL_ONE;

			iTableIndex = WHOLE(rate * lTableRange);

			if (r)
			{
				QUICK_BOUND(lpMyMidPoint[iTableIndex].red   + r, lpSrc->red);
				NEW_RANDOM;
				QUICK_BOUND(lpMyMidPoint[iTableIndex].green + r, lpSrc->green);
				NEW_RANDOM;
				QUICK_BOUND(lpMyMidPoint[iTableIndex].blue  + r, lpSrc->blue);
			}
			else
			{
				QUICK_BOUND(lpMyMidPoint[iTableIndex].red  , lpSrc->red);
				QUICK_BOUND(lpMyMidPoint[iTableIndex].green, lpSrc->green);
				QUICK_BOUND(lpMyMidPoint[iTableIndex].blue , lpSrc->blue);
			}

			lpSrc++;
		}
	}
	else
	{
		while (iCount-- > 0)
		{
			DO_RANDOM;

			REPS_NOT_ONE;

			iTableIndex = WHOLE(rate*lTableRange);

			if (r)
			{
				QUICK_BOUND(lpMyMidPoint[iTableIndex].red   + r, lpSrc->red);
				NEW_RANDOM;
				QUICK_BOUND(lpMyMidPoint[iTableIndex].green + r, lpSrc->green);
				NEW_RANDOM;
				QUICK_BOUND(lpMyMidPoint[iTableIndex].blue  + r, lpSrc->blue);
			}
			else
			{
				QUICK_BOUND(lpMyMidPoint[iTableIndex].red  , lpSrc->red);
				QUICK_BOUND(lpMyMidPoint[iTableIndex].green, lpSrc->green);
				QUICK_BOUND(lpMyMidPoint[iTableIndex].blue , lpSrc->blue);
			}

			lpSrc++;
		}
	}
}
示例#8
0
static void ProcessVignette8P(
	LPTR  lpSrc,
	int    iCount,
	LPGRADIENT_DATA lpGrad)
{
	long d, D, lTableRange;
	int  r;
	LFIXED rate;
	LPRGB  lpMyMidPoint = (LPRGB)lpGrad->lpMidpointTable;
	LPTR lpPaletteLUT = lpGrad->lpPaletteLUT;
	int    iTableIndex;
	int nRepetitions, SoftTransition;
	LPLONG lpld, lplD;
	RGBS rgb;
	WORD wRGB;

	lpld = lpGrad->lpld;
	lplD = lpGrad->lplD;
	lTableRange = lpGrad->lTableRange;
	nRepetitions = lpGrad->nRepetitions;
	SoftTransition = lpGrad->SoftTransition;

	if (nRepetitions == 1)
	{
		while (iCount-- > 0)
		{
			DO_RANDOM;

			REPS_EQUAL_ONE;

			iTableIndex = WHOLE(rate * lTableRange);

			if (r)
			{
				QUICK_BOUND(lpMyMidPoint[iTableIndex].red   + r, rgb.red);
				NEW_RANDOM;
				QUICK_BOUND(lpMyMidPoint[iTableIndex].green + r, rgb.green);
				NEW_RANDOM;
				QUICK_BOUND(lpMyMidPoint[iTableIndex].blue  + r, rgb.blue);
			}
			else
			{
				QUICK_BOUND(lpMyMidPoint[iTableIndex].red  , rgb.red);
				QUICK_BOUND(lpMyMidPoint[iTableIndex].green, rgb.green);
				QUICK_BOUND(lpMyMidPoint[iTableIndex].blue , rgb.blue);
			}
			wRGB = RGBtoMiniRGB(&rgb);
			*lpSrc++ = lpPaletteLUT[wRGB];
		}
	}
	else
	{
		while (iCount-- > 0)
		{
			DO_RANDOM;

			REPS_NOT_ONE;

			iTableIndex = WHOLE(rate*lTableRange);

			if (r)
			{
				QUICK_BOUND(lpMyMidPoint[iTableIndex].red   + r, rgb.red);
				NEW_RANDOM;
				QUICK_BOUND(lpMyMidPoint[iTableIndex].green + r, rgb.green);
				NEW_RANDOM;
				QUICK_BOUND(lpMyMidPoint[iTableIndex].blue  + r, rgb.blue);
			}
			else
			{
				QUICK_BOUND(lpMyMidPoint[iTableIndex].red  , rgb.red);
				QUICK_BOUND(lpMyMidPoint[iTableIndex].green, rgb.green);
				QUICK_BOUND(lpMyMidPoint[iTableIndex].blue , rgb.blue);
			}

			wRGB = RGBtoMiniRGB(&rgb);
			*lpSrc++ = lpPaletteLUT[wRGB];
		}
	}
}
示例#9
0
BOOL GradientImage( LPIMAGE lpImage, LPGRADIENT_PARMS lpParms)
{
	LPFRAME lpFrame;
	RECT rMask;
	LPINT lpD;
	FRMTYPEINFO TypeInfo;
	int dx, dy, iCount;
	int index, prev, next, pi, ni;
	long ldx, ldy, x, y, xs, xe, ys, ye, asqrd, bsqrd, r;
	LPDATAPROC lpVignetteProc;
	ENGINE Engine;
	BOOL   DoHSL;
	GRADIENT_DATA data;
	int res;

   FRMDATATYPE type;
	ImgGetInfo(lpImage, NULL, NULL, NULL, &type);
	if (type == FDT_LINEART)
		return(FALSE);
	if (!(lpFrame = ImgGetBaseEditFrame(lpImage)))
		return(FALSE);
	res = FrameResolution(lpFrame);
	data.x1 = lpParms->x1;
	data.y1 = lpParms->y1;
	data.x2 = lpParms->x2;
	data.y2 = lpParms->y2;
	ResConvertUL(lpParms->iBaseRes, res, &data.x1, &data.y1);
	ResConvertLR(lpParms->iBaseRes, res, &data.x2, &data.y2);
	dx = data.x2 - data.x1;
	dy = data.y2 - data.y1;
	data.SoftTransition = lpParms->SoftTransition;
	data.lpPaletteLUT = NULL;

	if (lpParms->Gradient == IDC_VIGLINEAR || lpParms->Gradient == IDC_VIGRADIAL)
	{
		if (abs(dx) <= 3 && abs(dy) <= 3)
			return(FALSE);
	}
	else
	{
		if (abs(dx) <= 3 || abs(dy) <= 3)
			return(FALSE);
	}

	data.xc = (data.x1 + data.x2) / 2;
	data.yc = (data.y1 + data.y2) / 2;

	if ( (data.nRepetitions = lpParms->RepeatCount) <= 0 )
		data.nRepetitions = 1;

	FrameGetTypeInfo(lpFrame, &TypeInfo);

	DoHSL = (lpParms->VigColorModel+IDC_FIRST_MODEL) != IDC_MODEL_RGB &&
				(TypeInfo.DataType > FDT_GRAYSCALE);

	switch (lpParms->Gradient)
	{
		case IDC_VIGLINEAR:
			data.D = lsqrt(((long)dx*(long)dx)+((long)dy*(long)dy));
			data.sine = FGET(-dy, data.D);
			data.cosine = FGET(dx, data.D);
			data.xr = WHOLE(( rotx(data.x2, data.y2, data.x1, data.y1,
            data.cosine, data.sine) ));
			lpVignetteProc = (LPDATAPROC)linear_vignette_proc;
		break;

		case IDC_VIGRADIAL:
			data.D = lsqrt(((long)dx*(long)dx)+((long)dy*(long)dy));
			lpVignetteProc = (LPDATAPROC)radial_vignette_proc;
		break;

		case IDC_VIGCIRCLE:
			data.x1 = data.xc;
			data.y1 = data.yc;
			data.y2 = data.yc;
			dx = data.x2 - data.x1;
			dy = data.y2 - data.y1;
			if (!dx && !dy)
				return(FALSE);
			data.D = lsqrt(((long)dx*(long)dx)+((long)dy*(long)dy));
			lpVignetteProc = (LPDATAPROC)radial_vignette_proc;
		break;

		case IDC_VIGSQUARE:
		case IDC_VIGRECTANGLE:
			data.ymin = min(data.y1, data.y2);
			data.ymax = max(data.y1, data.y2);
			data.xmin = min(data.x1, data.x2);
			data.xmax = max(data.x1, data.x2);

			ldx = data.xmin-data.xc;		// upper left
			ldy = data.ymin-data.yc;
			data.m1 = (256L * ldy) / ldx;
			data.b1 = data.ymin - ((data.m1 * data.xmin)/256L);
			data.D1 = lsqrt((ldx*ldx)+(ldy*ldy));

			ldx = data.xmax-data.xc;		// upper right
			ldy = data.ymin-data.yc;
			data.m2 = (256L * ldy) / ldx;
			data.b2 = data.ymin - ((data.m2 * data.xmax)/256L);
			data.D2 = lsqrt((ldx*ldx)+(ldy*ldy));

			ldx = data.xmax-data.xc;		// lower right
			ldy = data.ymax-data.yc;
			data.m3 = (256L * ldy) / ldx;
			data.b3 = data.ymax - ((data.m3 * data.xmax)/256L);
			data.D3 = lsqrt((ldx*ldx)+(ldy*ldy));

			ldx = data.xmin-data.xc;		// lower left
			ldy = data.ymax-data.yc;
			data.m4 = (256L * ldy) / ldx;
			data.b4 = data.ymax - ((data.m4 * data.xmin)/256L);
			data.D4 = lsqrt((ldx*ldx)+(ldy*ldy));

			lpVignetteProc = (LPDATAPROC)rectangle_vignette_proc;
		break;

		case IDC_VIGELLIPSE:
			if ( !(data.lpD = (LPINT)Alloc((long)sizeof(int)*(TSIZE+1))) )
			{
				Message(IDS_EMEMALLOC);
				return(FALSE);
			}
			iCount = TSIZE+1;
			lpD = data.lpD;
			while (--iCount >= 0)
				*lpD++ = -1;				
			data.ymin = min(data.y1, data.y2);
			data.ymax = max(data.y1, data.y2);
			data.xmin = min(data.x1, data.x2);
			data.xmax = max(data.x1, data.x2);
			data.ea = dx/2;
			data.eb = dy/2;
			if (!data.ea || !data.eb)
			{
				FreeUp((LPTR)data.lpD);
				return(FALSE);
			}
			asqrd = data.ea*data.ea;
			bsqrd = data.eb*data.eb;

			// fill in a table with radius information for the
			// ellipse.  The radius for a given point would be
			// starting from the center of the ellipse, going 
			// through to point, and where it intersects the 
			// edge of the ellipse.  We need the radius for
			// the D value used in the ellipse_proc, which is
			// the maximum distance used for determining how to
			// calculate the gradient, which is d/D.  d is the 
			// distance of the point from the center, D is extracted
			// from the table built below.  The index of the table is
			// formed from the ratio of sides of the triangle formed.
			// This is like looking up the angle to see where the
			// point would intersect the circle.  But we calculate
			// the radii ahead of time to speed things up.
			if (data.ea > data.eb)	// step in x
			{
				xs = data.xc - data.xc;
				xe = data.xmax - data.xc;
				for (x = xs; x <= xe; ++x)
				{
					y = ((data.eb*(long)lsqrt(asqrd - (x*x)))+(data.ea/2))/data.ea;
					r = (x*x)+(y*y);
					if (r <= 0)
						r = 1;
					index = ((x * x * (long)TSIZE)+(r/2)) / r;
					index = bound(abs(index), 0, TSIZE);
					data.lpD[index] = lsqrt(r);
				}
			}
			else		// step in y
			{
				ys = data.yc - data.yc;
				ye = data.ymax - data.yc;
				for (y = ys; y <= ye; ++y)
				{
					x = ((data.ea*(long)lsqrt(bsqrd - (y*y)))+(data.eb/2))/data.eb;
					r = (x*x)+(y*y);
					if (r <= 0)
						r = 1;
					index = ((y * y * (long)TSIZE)+(r/2)) / r;
					index = bound(abs(index), 0, TSIZE);
					data.lpD[index] = lsqrt(r);
				}
			}
			// find the first valid entry in our table
			for (index = 0; index <= TSIZE && data.lpD[index] < 0; ++index)
				;

			// see if we have any entries
			if (index > TSIZE)
			{
				FreeUp((LPTR)data.lpD);
				return(FALSE);
			}

			// fill in all entries before first with value of first
			while (--index >= 0)
				data.lpD[index] = data.lpD[index+1];

			// find last valid entry in table
			for (index = TSIZE; index >= 0 && data.lpD[index] < 0; --index)
				;

			// see if we have any entries
			if (index < 0)
			{
				FreeUp((LPTR)data.lpD);
				return(FALSE);
			}

			// fill in all entries after last with value of last
			while (++index <= TSIZE)
				data.lpD[index] = data.lpD[index-1];

			// interpolate values of all empty cells
			for (index = 0; index <= TSIZE; ++index)
			{
				if (data.lpD[index] < 0)
				{
					pi = index - 1;
					prev = data.lpD[pi];
					ni = index;
					while (data.lpD[ni] < 0)
						++ni;
					next = data.lpD[ni];
					// remember here that (index-pi) == 1
					data.lpD[index] = prev + ((next-prev)/(ni-pi));
				}
			}
			lpVignetteProc = (LPDATAPROC)ellipse_vignette_proc;
		break;

		default:
			return(FALSE);
		break;
	}

	switch(TypeInfo.DataType)
	{
		case FDT_LINEART :
		case FDT_GRAYSCALE :
			data.lpProcessProc = (LPVIGPROC)ProcessVignette8;
		break;

		case FDT_PALETTECOLOR:
			data.lpProcessProc = (LPVIGPROC)ProcessVignette8P;
			data.lpPaletteLUT = CreatePaletteLut15(TypeInfo.ColorMap->RGBData,
					TypeInfo.ColorMap->NumEntries, NULL, NULL);
		break;

		case FDT_RGBCOLOR :
			data.lpProcessProc = (LPVIGPROC)ProcessVignette24;
		break;

		case FDT_CMYKCOLOR :
			data.lpProcessProc = (LPVIGPROC)ProcessVignette32;
		break;
	}

	data.lpMidpointTable = BuildMidPointTable(
							DoHSL,
							TypeInfo.DataType,
							lpParms->Midpoint,
							&lpParms->StartColor,
							&lpParms->EndColor,
							&data );

	ImgGetMaskRect( lpImage, &rMask );
	data.lplD = (LPLONG)Alloc((long)sizeof(long)*(long)RectWidth(&rMask));
	data.lpld = (LPLONG)Alloc((long)sizeof(long)*(long)RectWidth(&rMask));

	if (!data.lpld || !data.lplD || !data.lpMidpointTable ||
		(TypeInfo.DataType == FDT_PALETTECOLOR && !data.lpPaletteLUT))
	{
		if (lpParms->Gradient == IDC_VIGELLIPSE)
			FreeUp((LPTR)data.lpD);
		if (data.lplD)
			FreeUp((LPTR)data.lplD);
		if (data.lpld)
			FreeUp((LPTR)data.lpld);
		if (data.lpMidpointTable)
			FreeUp((LPTR)data.lpMidpointTable);
		if (data.lpPaletteLUT)
			FreeUp(data.lpPaletteLUT);
		return(FALSE);
	}

	SetEngineDraw(&Engine,lpVignetteProc,lpParms->VigOpacity,lpParms->VigMergeMode);
	Engine.lpParam = &data;
	Engine.fThread = NO;
	lpParms->Common.StatusCode = LineEngineSelObj(lpImage,&Engine,lpParms->Common.idDirty);
	if (!AstralIsRectEmpty(&Engine.rUpdate))
	{
		lpParms->Common.UpdateType = UT_AREA;
		lpParms->Common.rUpdateArea = Engine.rUpdate;
	}

	FreeUp((LPTR)data.lpld);
	FreeUp((LPTR)data.lplD);
	FreeUp((LPTR)data.lpMidpointTable);
	if (data.lpPaletteLUT)
		FreeUp(data.lpPaletteLUT);

	if (lpParms->Gradient == IDC_VIGELLIPSE)
		FreeUp((LPTR)data.lpD);
	return(lpParms->Common.StatusCode == SC_SUCCESS);
}
示例#10
0
static void ProcessVignette32(
	LPCMYK lpSrc,
	int    iCount,
	LPGRADIENT_DATA lpGrad)
{
	long   d, D, lTableRange;
	int    r;
	LFIXED rate;
	LPCMYK lpMyMidPoint = (LPCMYK)lpGrad->lpMidpointTable;
	int    iTableIndex;
	int nRepetitions, SoftTransition;
	LPLONG lpld, lplD;

	lpld = lpGrad->lpld;
	lplD = lpGrad->lplD;
	lTableRange = lpGrad->lTableRange;
	nRepetitions = lpGrad->nRepetitions;
	SoftTransition = lpGrad->SoftTransition;

	if (nRepetitions == 1)
	{
		while (iCount-- > 0)
		{
			DO_RANDOM;

			REPS_EQUAL_ONE;

			iTableIndex = WHOLE(rate*lTableRange);

			if (r)
			{
				QUICK_BOUND(lpMyMidPoint[ iTableIndex ].c + r, lpSrc->c);
				NEW_RANDOM;
				QUICK_BOUND(lpMyMidPoint[ iTableIndex ].m + r, lpSrc->m);
				NEW_RANDOM;
				QUICK_BOUND(lpMyMidPoint[ iTableIndex ].y + r, lpSrc->y);
				NEW_RANDOM;
				QUICK_BOUND(lpMyMidPoint[ iTableIndex ].k + r, lpSrc->k);
			}
			else
			{
				QUICK_BOUND(lpMyMidPoint[ iTableIndex ].c, lpSrc->c);
				QUICK_BOUND(lpMyMidPoint[ iTableIndex ].m, lpSrc->m);
				QUICK_BOUND(lpMyMidPoint[ iTableIndex ].y, lpSrc->y);
				QUICK_BOUND(lpMyMidPoint[ iTableIndex ].k, lpSrc->k);
			}

			lpSrc++;
		}
	}
	else
	{
		while (iCount-- > 0)
		{
			DO_RANDOM;

			REPS_NOT_ONE;

			iTableIndex = WHOLE(rate*lTableRange);

			if (r)
			{
				QUICK_BOUND(lpMyMidPoint[ iTableIndex ].c + r, lpSrc->c);
				NEW_RANDOM;
				QUICK_BOUND(lpMyMidPoint[ iTableIndex ].m + r, lpSrc->m);
				NEW_RANDOM;
				QUICK_BOUND(lpMyMidPoint[ iTableIndex ].y + r, lpSrc->y);
				NEW_RANDOM;
				QUICK_BOUND(lpMyMidPoint[ iTableIndex ].k + r, lpSrc->k);
			}
			else
			{
				QUICK_BOUND(lpMyMidPoint[ iTableIndex ].c, lpSrc->c);
				QUICK_BOUND(lpMyMidPoint[ iTableIndex ].m, lpSrc->m);
				QUICK_BOUND(lpMyMidPoint[ iTableIndex ].y, lpSrc->y);
				QUICK_BOUND(lpMyMidPoint[ iTableIndex ].k, lpSrc->k);
			}

			lpSrc++;
		}
	}
}
示例#11
0
BOOL PSPrint(
	LPIMAGE lpImage,
	LPFRAME lpFrame,
	BYTE    cSep,
	int     xSrc,
	int     ySrc,
	int     dxSrc,
	int     dySrc,
	int     xDest,
	int     yDest,
	int     dxDest,
	int     dyDest,
	int     iPrResX,
	int     iPrResY )
{
int y, yline, ystart, ylast, x, depth;
LFIXED yrate, yoffset;
LPTR lpBuffer[5], p1Buf, p2Buf, p3Buf, p4Buf;
LPSTR lpAngle, lpRuling;
LPTR lpImageData;
BOOL Negative, Asciize;
STRING szAngle, szRuling;
long lSize;
LPFRAME lpBaseFrame;

#define C_ANGLE Halftone.ScreenAngle[0]
#define M_ANGLE Halftone.ScreenAngle[1]
#define Y_ANGLE Halftone.ScreenAngle[2]
#define K_ANGLE Halftone.ScreenAngle[3]
#define C_RULING Halftone.ScreenRuling[0]
#define M_RULING Halftone.ScreenRuling[1]
#define Y_RULING Halftone.ScreenRuling[2]
#define K_RULING Halftone.ScreenRuling[3]

ProgressBegin(1,0);

lpAngle = szAngle;
lpRuling = szRuling;
Negative = Page.Negative;
Asciize = !Page.BinaryPS;

PS_ID( IDS_PS_DICTDEF );

/* Send the definition of the read data function */
if ( Asciize )
{
	PS_ID( IDS_PS_HEXDATA );
}
else
{
	PS_ID( IDS_PS_BINDATA );
}

if ( !Halftone.DoHalftoning )
	goto HalftoningDone;

/* Send the definition of the spot function */
if ( Halftone.DotShape == IDC_ELLIPSEDOT )
	{
	PS_ID( IDS_PS_ELLDOT1 );
	PS_ID( IDS_PS_ELLDOT2 );
	}
else
if ( Halftone.DotShape == IDC_SQUAREDOT )
	{
	PS_ID( IDS_PS_SQUDOT );
	}
else
if ( Halftone.DotShape == IDC_CIRCLEDOT )
	{
	PS_ID( IDS_PS_CIRDOT );
	}
else
if ( Halftone.DotShape == IDC_TRIANGLEDOT )
	{
	PS_ID( IDS_PS_TRIDOT );
	}
else
if ( Halftone.DotShape == IDC_PROPELLERDOT )
	{
	PS_ID( IDS_PS_PROPDOT );
	}

if ( Page.OutputType == IDC_PRINT_BLACKSEPS ||
     Page.OutputType == IDC_PRINT_GRAY )
	{ // Setup the "image" screen angles and freqs based on the sep
	if ( cSep == 'C' )
		{
		FixedAscii( C_ANGLE,  lpAngle,  -2 );
		FixedAscii( C_RULING, lpRuling, -2 );
		}
	else
	if ( cSep == 'M' )
		{
		FixedAscii( M_ANGLE,  lpAngle,  -2 );
		FixedAscii( M_RULING, lpRuling, -2 );
		}
	else
	if ( cSep == 'Y' )
		{
		FixedAscii( Y_ANGLE,  lpAngle,  -2 );
		FixedAscii( Y_RULING, lpRuling, -2 );
		}
	else
	//if ( cSep == 'K' || cSep == 'X' || !cSep )
		{
		FixedAscii( K_ANGLE,  lpAngle,  -2 );
		FixedAscii( K_RULING, lpRuling, -2 );
		}
	PS_ID2( IDS_PS_SETSCREEN, lpRuling, lpAngle );
	}
else
	{ // Setup the "colorimage" screen angles and frequencies
	PS_ID( IDS_PS_COLOREXT );
	PS_ID( IDS_PS_STARTBLOCK );

	FixedAscii( C_RULING, lpRuling, -2 );
	FixedAscii( C_ANGLE,  lpAngle,  -2 );
	PS_ID2( IDS_PS_SETSPOT, lpRuling, lpAngle );

	FixedAscii( M_RULING, lpRuling, -2 );
	FixedAscii( M_ANGLE,  lpAngle,  -2 );
	PS_ID2( IDS_PS_SETSPOT, lpRuling, lpAngle );

	FixedAscii( Y_RULING, lpRuling, -2 );
	FixedAscii( Y_ANGLE,  lpAngle,  -2 );
	PS_ID2( IDS_PS_SETSPOT, lpRuling, lpAngle );

	FixedAscii( K_RULING, lpRuling, -2 );
	FixedAscii( K_ANGLE,  lpAngle,  -2 );
	PS_ID2( IDS_PS_SETSPOT, lpRuling, lpAngle );
	PS_ID( IDS_PS_SETCOLORSCREEN );
	PS_ID( IDS_PS_ENDBLOCK );

	PS_ID( IDS_PS_STARTBLOCK );
	FixedAscii( K_RULING, lpRuling, -2 );
	FixedAscii( K_ANGLE,  lpAngle,  -2 );
	PS_ID2( IDS_PS_SETSCREEN, lpRuling, lpAngle );
	PS_ID( IDS_PS_ENDBLOCK );
	PS_ID( IDS_PS_IFELSE );
	}

HalftoningDone:

// Setup a null transfer curve unless doing seps w/black ink (image operator)
if ( Page.OutputType == IDC_PRINT_BLACKSEPS )
{
	PS_ID( IDS_PS_BLACKSEPS );
}
else
if ( Page.OutputType == IDC_PRINT_COLORSEPS )
{
	PS_ID( IDS_PS_COLORSEPS );
}
else
{
	PS_ID( IDS_PS_NOINVERT );
}

PS_ID( IDS_PS_CHECKINVERT );

/* Send the destination point (x,y) in spots */
PS_ID2( IDS_PS_TRANSLATE, xDest, yDest );

/* Send the destination size (w,h) in spots */
PS_ID2( IDS_PS_SCALE, dxDest, dyDest );

if (lpImage)
	lpBaseFrame =  ImgGetBaseEditFrame(lpImage);
else 
	lpBaseFrame = lpFrame;
/* Compute how many pixels we're going to send */
/* Never send more than 16 pixels per halftone grid (or 4/grid in x and y) */
if (depth = FrameDepth( lpBaseFrame ))
	{
	if ( iPrResX < 600 )
		dxDest /= 4;
	else	dxDest /= 8;
	if ( iPrResY < 600 )
		dyDest /= 4;
	else	dyDest /= 8;
	}

if (depth == 0) depth = 1;

/* Let the printer do any upsizing */
if ( dySrc < dyDest )
	{
	yrate = UNITY;
	dxDest = dxSrc;
	dyDest = dySrc;
	}
else yrate = FGET( dySrc, dyDest );

/* Send the definition for the line buffers */
PS_ID1( IDS_PS_LINE1, dxDest );
PS_ID1( IDS_PS_LINE2, dxDest );
PS_ID1( IDS_PS_LINE3, dxDest );
PS_ID1( IDS_PS_LINE4, dxDest );
PS_ID1( IDS_PS_LINE5, dxDest );

if ( cSep ) // Plane at a time
{ // cSep is either 'C', 'M', 'Y', 'K', 'X'(gray) or NULL
	if ( Page.OutputType == IDC_PRINT_COLORSEPS )
	{
		PS_ID( IDS_PS_DOCOLORSEPDEF );
	}
	else
	{
		PS_ID( IDS_PS_NOCOLORSEPDEF );
	}

	PS_ID( IDS_PS_DOIMAGEDEF );
	PS_ID( IDS_PS_COLORSEPVAL );

	// Start color image proc
	PS_ID( IDS_PS_STARTBLOCK );
	PS_ID( IDS_PS_STARTBLOCK );

	if ( cSep == 'C' )
	{
		PS_ID( IDS_PS_SEPCYAN );
	}
	else
	if ( cSep == 'M' )
	{
		PS_ID( IDS_PS_SEPMAGENTA );
	}
	else
	if ( cSep == 'Y' )
	{
		PS_ID( IDS_PS_SEPYELLOW );
	}
	else
	if ( cSep == 'K' || cSep == 'X' )
	{
		PS_ID( IDS_PS_SEPBLACK );
	}

	PS_ID( IDS_PS_COLORIMAGE4 );

	PS_ID( IDS_PS_ENDBLOCK );
	PS_ID( IDS_PS_ENDBLOCK );

	// Start gray image proc
	PS_ID( IDS_PS_STARTBLOCK );
	PS_ID( IDS_PS_STARTBLOCK );

	PS_ID( IDS_PS_GETLINE1 );
	PS_ID( IDS_PS_IMAGE );
	PS_ID( IDS_PS_ENDBLOCK );
	PS_ID( IDS_PS_ENDBLOCK );

	PS_ID( IDS_PS_IFELSE );
	PS_ID( IDS_PS_DEF );
}
else
if ( Page.Type == IDC_PRINTER_IS_CMYK )
{
	if (Page.OutputType == IDC_PRINT_COLORGRAY)
	{
		PS_ID( IDS_PS_DOIMAGEDEF );
		PS_ID( IDS_PS_COLOREXT );

		// Start color image proc
		PS_ID( IDS_PS_STARTBLOCK );
			PS_ID( IDS_PS_STARTBLOCK );

				PS_ID( IDS_PS_GETLINE1 );
				PS_ID( IDS_PS_GETLINE2 );
				PS_ID( IDS_PS_GETLINE3 );

				PS_ID( IDS_PS_STARTBLOCK );
					PS_ID( IDS_PS_GETLINE4 );
					PS_ID( IDS_PS_GETLINE5 );
					PS_ID( IDS_PS_POP );
				PS_ID( IDS_PS_ENDBLOCK );

				PS_ID( IDS_PS_COLORIMAGE4 );
			PS_ID( IDS_PS_ENDBLOCK );
		PS_ID( IDS_PS_ENDBLOCK );

		// Start gray image proc
		PS_ID( IDS_PS_STARTBLOCK );
			PS_ID( IDS_PS_STARTBLOCK );
				PS_ID( IDS_PS_STARTBLOCK );
					PS_ID( IDS_PS_DUMPLINE1 );
					PS_ID( IDS_PS_DUMPLINE2 );
					PS_ID( IDS_PS_DUMPLINE3 );
					PS_ID( IDS_PS_STARTBLOCK );
						PS_ID( IDS_PS_GETLINE4 );
						PS_ID( IDS_PS_GETLINE5 );
					PS_ID( IDS_PS_ENDBLOCK );
					PS_ID( IDS_PS_IMAGE );
				PS_ID( IDS_PS_ENDBLOCK );
			PS_ID( IDS_PS_ENDBLOCK );
		PS_ID( IDS_PS_ENDBLOCK );

		PS_ID( IDS_PS_IFELSE );
		PS_ID( IDS_PS_DEF );
	}
	else
	{
		PS_ID( IDS_PS_DOIMAGEDEF );
		PS_ID( IDS_PS_COLOREXT );

		// Start color image proc
		PS_ID( IDS_PS_STARTBLOCK );
			PS_ID( IDS_PS_STARTBLOCK );
				PS_ID( IDS_PS_GETLINE1 );
				PS_ID( IDS_PS_GETLINE2 );
				PS_ID( IDS_PS_GETLINE3 );
				PS_ID( IDS_PS_GETLINE4 );
				PS_ID( IDS_PS_COLORIMAGE4 );
			PS_ID( IDS_PS_ENDBLOCK );
		PS_ID( IDS_PS_ENDBLOCK );

		// Start gray image proc
		PS_ID( IDS_PS_STARTBLOCK );
			PS_ID( IDS_PS_STARTBLOCK );
				PS_ID( IDS_PS_STARTBLOCK );
					PS_ID( IDS_PS_DUMPLINE1 );
					PS_ID( IDS_PS_DUMPLINE2 );
					PS_ID( IDS_PS_DUMPLINE3 );
					PS_ID( IDS_PS_GETLINE4 );
				PS_ID( IDS_PS_ENDBLOCK );
				PS_ID( IDS_PS_NOIMAGE );
			PS_ID( IDS_PS_ENDBLOCK );
		PS_ID( IDS_PS_ENDBLOCK );

		PS_ID( IDS_PS_IFELSE );
		PS_ID( IDS_PS_DEF );
	}
}
else
if ( Page.Type == IDC_PRINTER_IS_RGB )
{
	PS_ID( IDS_PS_DOIMAGEDEF );
	PS_ID( IDS_PS_COLOREXT );

	// Start color image proc
	PS_ID( IDS_PS_STARTBLOCK );
	PS_ID( IDS_PS_STARTBLOCK );

	PS_ID( IDS_PS_GETLINE1 );
	PS_ID( IDS_PS_GETLINE2 );
	PS_ID( IDS_PS_GETLINE3 );

	if ( Page.OutputType == IDC_PRINT_COLORGRAY )
	{
		PS_ID( IDS_PS_DUMPLINE4 );
	}

	PS_ID( IDS_PS_COLORIMAGE3 );
	PS_ID( IDS_PS_ENDBLOCK );
	PS_ID( IDS_PS_ENDBLOCK );

	// Start gray image proc
	PS_ID( IDS_PS_STARTBLOCK );
	PS_ID( IDS_PS_STARTBLOCK );

	PS_ID( IDS_PS_STARTBLOCK );
	PS_ID( IDS_PS_DUMPLINE1 );
	PS_ID( IDS_PS_DUMPLINE2 );

	if ( Page.OutputType == IDC_PRINT_COLORGRAY )
	{
		PS_ID( IDS_PS_DUMPLINE3 );
		PS_ID( IDS_PS_GETLINE4 );
		PS_ID( IDS_PS_ENDBLOCK );
		PS_ID( IDS_PS_IMAGE );
	}
	else
	{
		PS_ID( IDS_PS_GETLINE3 );
		PS_ID( IDS_PS_ENDBLOCK );
		PS_ID( IDS_PS_NOIMAGE );
	}
	PS_ID( IDS_PS_ENDBLOCK );
	PS_ID( IDS_PS_ENDBLOCK );
	PS_ID( IDS_PS_IFELSE );
	PS_ID( IDS_PS_DEF );
}

/* Send the inline image's size, packing, and transform */
PS_ID5( IDS_PS_TRANSFORM, dxDest, dyDest, 8, dxDest, dyDest );

if ( !Asciize )
{
	// The size must include the doimage command that follows
	lSize = (long)dxDest * dyDest * depth;
	PS_ID1( IDS_PS_BEGINBINARY, lSize + 9 + 2 );
}

PS_ID( IDS_PS_DOIMAGE ); // Should be 9 characters

for ( x=0; x<5; x++ )
	lpBuffer[x] = NULL;

if (!AllocLines((LPPTR)&lpImageData, 1, dxSrc, depth))
{
	ProgressEnd();
	return(FALSE);
}

if (!AllocLines((LPPTR)&lpBuffer[0], 1, dxDest, depth))
{
	FreeUp( lpImageData );
	ProgressEnd();
	return( FALSE );
}

if (!AllocLines((LPPTR)&lpBuffer[1], 4, dxDest, 1))
{
	FreeUp(lpBuffer[0]);
	FreeUp( lpImageData );
	ProgressEnd();
	return( FALSE );
}

p1Buf  = lpBuffer[1];
p2Buf  = lpBuffer[2];
p3Buf  = lpBuffer[3];
p4Buf  = lpBuffer[4];

ystart  = ySrc;
yline   = -1;
yoffset = (long)yrate>>1;

for (y=0; y<dyDest; y++)
{
	if (AstralClockCursor( y, dyDest, YES ))
	{
		fAbortPrint = YES;
		break;
	}

	/* Check for user input to abort dialog box */
	(*lpAbortTest)(hPrinterDC, 0);
	if ( fAbortPrint )
		break;

	ylast = yline;
#ifdef WIN32
	yline = ystart + WHOLE( yoffset );
#else
	yline = ystart + HIWORD( yoffset );
#endif
	yoffset += yrate;
	if ( yline != ylast )
	{
		LFIXED rate;

		if (lpImage)
			ImgGetLine( lpImage, NULL, xSrc, yline, dxSrc, lpImageData );
		else
			copy(FramePointer(lpBaseFrame, xSrc, yline, NO), lpImageData, dxSrc*depth);
		rate = FGET( dxSrc, dxDest );

		FrameSample(
			lpBaseFrame,
			lpImageData,
			0,
			lpBuffer[0],
			0,
			dxDest,
			rate);
	}

	if ( cSep )
	{ // cSep is either 'C', 'M', 'Y', 'K', 'X'(gray) or NULL
		if (cSep != 'X')
		{
			LPTR lpOutBuf;
			int  iPlaneOffset;

			switch(cSep)
			{
				case 'C' : lpOutBuf = p1Buf; iPlaneOffset = 0; break;
				case 'M' : lpOutBuf = p2Buf; iPlaneOffset = 1; break;
				case 'Y' : lpOutBuf = p3Buf; iPlaneOffset = 2; break;
				case 'K' : lpOutBuf = p4Buf; iPlaneOffset = 3; break;
			}

			switch(depth)
			{
				case 0 :
				case 1 :
					lpOutBuf = (LPTR)lpBuffer[0];
				break;

				case 3 :
					ClrRGBtoCMYK( (LPRGB)lpBuffer[0],
						p1Buf, p2Buf, p3Buf,p4Buf,dxDest,YES);
				break;

				case 4 :
				{
					LPTR lpSrc  = (LPTR)lpBuffer[0];
					LPTR lpDst  = lpOutBuf;
					int  iCount = dxDest;

					lpSrc += iPlaneOffset;

					while(iCount-- > 0)
					{
						*lpDst++ = *lpSrc;
						lpSrc += 4;
					}
				}
				break;
			}

			if (Negative)
				negate(lpOutBuf, (long)dxDest);
			if ( !SendPSData( Asciize, lpOutBuf, dxDest ) )
				goto ErrorExit;
		}
		else
		{
			ConvertData( lpBuffer[0], depth, dxDest, p1Buf, 1 );
			if (Negative)
				negate(p1Buf, (long)dxDest);
			CorrectGray( p1Buf, dxDest, YES, YES );
			if ( !SendPSData( Asciize, p1Buf, dxDest ) )
				goto ErrorExit;
		}
	}
	else if ( Page.Type == IDC_PRINTER_IS_CMYK )
	{
		switch(depth)
		{
			case 0 :
			case 1 :
				copy( lpBuffer[0], p1Buf, dxDest );
				copy( lpBuffer[0], p2Buf, dxDest );
				copy( lpBuffer[0], p3Buf, dxDest );
				copy( lpBuffer[0], p4Buf, dxDest );
			break;

			case 3 :
				ClrRGBtoCMYK( (LPRGB)lpBuffer[0],
					p1Buf, p2Buf, p3Buf,p4Buf,dxDest,YES);
			break;

			case 4 :
			{
				LPTR lpSrc  = (LPTR)lpBuffer[0];
				LPTR lpDst1 = p1Buf;
				LPTR lpDst2 = p2Buf;
				LPTR lpDst3 = p3Buf;
				LPTR lpDst4 = p4Buf;
				int  iCount = dxDest;

				while(iCount-- > 0)
				{
					*lpDst1++ = *lpSrc++;
					*lpDst2++ = *lpSrc++;
					*lpDst3++ = *lpSrc++;
					*lpDst4++ = *lpSrc++;
				}
			}
			break;
		}

		if (Negative)
		{
			negate(p1Buf, (long)dxDest);
			negate(p2Buf, (long)dxDest);
			negate(p3Buf, (long)dxDest);
			negate(p4Buf, (long)dxDest);
		}

		if ( !SendPSData( Asciize, p1Buf, dxDest ) )
			goto ErrorExit;
		if ( !SendPSData( Asciize, p2Buf, dxDest ) )
			goto ErrorExit;
		if ( !SendPSData( Asciize, p3Buf, dxDest ) )
			goto ErrorExit;
		if ( !SendPSData( Asciize, p4Buf, dxDest ) )
			goto ErrorExit;

		if ( Page.OutputType == IDC_PRINT_COLORGRAY )
		{
			ConvertData( lpBuffer[0], depth, dxDest, p1Buf, 1 );

			if (Negative)
				negate(p1Buf, (long)dxDest);

			CorrectGray( p1Buf, dxDest, YES, YES);

			if ( !SendPSData( Asciize, p1Buf, dxDest ) )
				goto ErrorExit;
		}
	}
	else if ( Page.Type == IDC_PRINTER_IS_RGB )
	{
		switch(depth)
		{
			case 0 :
			case 1 :
				copy( lpBuffer[0], p1Buf, dxDest );
				copy( lpBuffer[0], p2Buf, dxDest );
				copy( lpBuffer[0], p3Buf, dxDest );
			break;

			case 3 :
				UnshuffleRGB( (LPRGB)lpBuffer[0],
					p1Buf, p2Buf, p3Buf, dxDest );
			break;

			case 4 :
			{
				LPCMYK lpCMYK = (LPCMYK)lpBuffer[0];
				LPTR lpDst1 = p1Buf;
				LPTR lpDst2 = p2Buf;
				LPTR lpDst3 = p3Buf;
				RGBS rgb;
				int  iCount = dxDest;

				while(iCount-- > 0)
				{
					CMYKtoRGB(lpCMYK->c, lpCMYK->m, lpCMYK->y, lpCMYK->k, &rgb);
					lpCMYK++;

					*lpDst1++ = rgb.red;
					*lpDst2++ = rgb.green;
					*lpDst3++ = rgb.blue;
				}
			}
			break;
		}

		if (Negative)
		{
			negate( p1Buf, dxDest );
			negate( p2Buf, dxDest );
			negate( p3Buf, dxDest );
		}

		if ( !SendPSData( Asciize, p1Buf, dxDest ) )
			goto ErrorExit;

		if ( !SendPSData( Asciize, p2Buf, dxDest ) )
			goto ErrorExit;

		if ( !SendPSData( Asciize, p3Buf, dxDest ) )
			goto ErrorExit;

		if ( Page.OutputType == IDC_PRINT_COLORGRAY )
		{
			ConvertData( (LPTR)lpBuffer[0], depth, dxDest, p1Buf, 1 );

			if (Negative)
				negate(p1Buf, (long)dxDest);

			CorrectGray( p1Buf, dxDest, YES, YES);

			if ( !SendPSData( Asciize, p1Buf, dxDest ) )
				goto ErrorExit;
		}
	}
}

if ( !Asciize )
{
	PS_ID( IDS_PS_ENDBINARY );
}

/* Send the save restore command */
PS_ID( IDS_PS_MYSAVERESTORE );
PS_ID( IDS_PS_END );

ErrorExit:

if ( lpBuffer[0] )
	FreeUp(lpBuffer[0]);
if ( lpBuffer[1] )
	FreeUp(lpBuffer[1]);
if ( lpImageData )
	FreeUp( lpImageData );
ProgressEnd();
return( TRUE );
}
示例#12
0
BOOL Palette_FillEntries( LPPALETTE lpHeadPalette, int iPalette, int iAfter,
                           LPCOLORINFO lpColor1, LPCOLORINFO lpColor2,
                           int iEntries, BOOL DoHSL )
/************************************************************************/
{
	LFIXED rate1, rate2;
	long range1, range2, range3;
	int  start1, start2, start3;

	int iNewColors, iColors;
	LPCOLORINFO lpNewColors, lpSrc, lpDst;
	int iBefore, i, n, iStart, j;
	LPPALETTE lpPalette;
	BOOL fDoHS, fDoSL, fDoHL, fDoRG, fDoGB, fDoRB;
	BYTE Value;

	lpPalette = Palette_Get(lpHeadPalette, NULL, iPalette);
	if (!lpPalette)
		return(FALSE);

	iStart = iAfter;

	if (DoHSL)
		{
		range1 = (long)lpColor2->hsl.hue - (long)lpColor1->hsl.hue;
		range2 = (long)lpColor2->hsl.sat - (long)lpColor1->hsl.sat;
		range3 = (long)lpColor2->hsl.lum - (long)lpColor1->hsl.lum;
		}
	else
		{
		range1 = (long)lpColor2->rgb.red   - (long)lpColor1->rgb.red;
		range2 = (long)lpColor2->rgb.green - (long)lpColor1->rgb.green;
		range3 = (long)lpColor2->rgb.blue  - (long)lpColor1->rgb.blue;
		}

	if (iEntries)
		iNewColors = iEntries;
	else
	{
		iNewColors = max(max(abs(range1), abs(range2)), abs(range3));
		iNewColors -= 2;
	}

	if (iNewColors <= 0)
		return(FALSE);

	fDoRG = iNewColors == 256 && !DoHSL && OPTION1;
	fDoGB = iNewColors == 256 && !DoHSL && OPTION2;
	fDoRB = iNewColors == 256 && !DoHSL && OPTION3;
	fDoHS = iNewColors == 256 && DoHSL && OPTION1;
	fDoSL = iNewColors == 256 && DoHSL && OPTION2;
	fDoHL = iNewColors == 256 && DoHSL && OPTION3;

	iColors     = lpPalette->iColors + iNewColors;
	lpNewColors = (LPCOLORINFO)Alloc((long)iColors*(long)sizeof(COLORINFO));

	if (!lpNewColors)
		return(FALSE);

	iBefore = iAfter + 1;
	lpSrc   = lpPalette->lpColorInfo;
	lpDst   = lpNewColors;

	if (lpPalette->iColors && iBefore > 0)
	{
		copy((LPTR)lpSrc, (LPTR)lpDst, iBefore*sizeof(COLORINFO));
		lpSrc += iBefore;
		lpDst += iBefore;
	}

	if (fDoHS || fDoSL || fDoHL)
	{
		if (fDoHS)
			Value = lpColor1->hsl.lum;
		else if (fDoSL)
			Value = lpColor1->hsl.hue;
		else
			Value = lpColor1->hsl.sat;

		rate1 = FGET(251, 15);
		rate2 = FGET(255, 15);
		for (i = 0; i < 16; ++i)
		{
			for (j = 0; j < 16; ++j)
			{
				if (fDoHL)
				{
					n = FMUL(i, rate1);
					lpDst->hsl.hue = mbound( n, 0, 251 );
					lpDst->hsl.sat = Value;
					n = FMUL(j, rate2);
					lpDst->hsl.lum = mbound( n, 0, 255 );
				}
				else
				if (fDoHS)
				{
					n = FMUL(i, rate1);
					lpDst->hsl.hue = mbound( n, 0, 251 );
					n = FMUL(j, rate2);
					lpDst->hsl.sat = mbound( n, 0, 255 );
					lpDst->hsl.lum = Value;
				}
				else  // fDoSL
				{
					lpDst->hsl.hue = Value;
					n = FMUL(i, rate2);
					lpDst->hsl.sat = mbound( n, 0, 255 );
					n = FMUL(j, rate2);
					lpDst->hsl.lum = mbound( n, 0, 255 );
				}

				SetColorInfo( lpDst, lpDst, CS_HSL );
				++lpDst;
			}
		}
	}
	else if (fDoRG || fDoGB || fDoRB)
	{
		if (fDoRG)
			Value = lpColor1->rgb.blue;
		else if (fDoGB)
			Value = lpColor1->rgb.red;
		else
			Value = lpColor1->rgb.green;
		rate1 = FGET(255, 15);
		for (i = 0; i < 16; ++i)
		{
			for (j = 0; j < 16; ++j)
			{
				if (fDoRG)
				{
					n = FMUL(i, rate1);
					lpDst->rgb.red = mbound( n, 0, 255 );
					n = FMUL(j, rate1);
					lpDst->rgb.green = mbound( n, 0, 255 );
					lpDst->rgb.blue = Value;
				}
				else
				if (fDoGB)
				{
					lpDst->rgb.red = Value;
					n = FMUL(i, rate1);
					lpDst->rgb.green = mbound( n, 0, 255 );
					n = FMUL(j, rate1);
					lpDst->rgb.blue = mbound( n, 0, 255 );
				}
				else  // fDoRB
				{
					n = FMUL(i, rate1);
					lpDst->rgb.red = mbound( n, 0, 255 );
					lpDst->rgb.green = Value;
					n = FMUL(j, rate1);
					lpDst->rgb.blue = mbound( n, 0, 255 );
				}

				SetColorInfo( lpDst, lpDst, CS_RGB );
				++lpDst;
			}
		}
	}
	else if (DoHSL)
	{
		start1 = lpColor1->hsl.hue;
		start2 = lpColor1->hsl.sat;
		start3 = lpColor1->hsl.lum;

		for (i = 0; i < iNewColors; ++i)
		{
			// range from 0 to 1
			rate1 = FGET(i+1, iNewColors+1);

			n = start1 + WHOLE(rate1*range1);
			lpDst->hsl.hue = mbound( n, 0, 255 );
			n = start2 + WHOLE(rate1*range2);
			lpDst->hsl.sat = mbound( n, 0, 255 );
			n = start3 + WHOLE(rate1*range3);
			lpDst->hsl.lum = mbound( n, 0, 255 );

			SetColorInfo( lpDst, lpDst, CS_HSL );
			++lpDst;
		}
	}
	else
	{
		start1 = lpColor1->rgb.red;
		start2 = lpColor1->rgb.green;
		start3 = lpColor1->rgb.blue;

		for (i = 0; i < iNewColors; ++i)
		{
			// range from 0 to 1
			rate1 = FGET(i+1, iNewColors+1);

			n = start1 + WHOLE(rate1*range1);
			lpDst->rgb.red   = mbound( n, 0, 255 );
			n = start2 + WHOLE(rate1*range2);
			lpDst->rgb.green = mbound( n, 0, 255 );
			n = start3 + WHOLE(rate1*range3);
			lpDst->rgb.blue  = mbound( n, 0, 255 );

			SetColorInfo( lpDst, lpDst, CS_RGB );
			++lpDst;
		}
	}

	iAfter = lpPalette->iColors-iAfter-1;

	if (lpPalette->iColors && iAfter > 0)
		copy((LPTR)lpSrc, (LPTR)lpDst, iAfter*sizeof(COLORINFO));

	if (lpPalette->lpColorInfo)
		FreeUp((LPTR)lpPalette->lpColorInfo);

	lpPalette->lpColorInfo = lpNewColors;
	lpPalette->iColors = iColors;

	Palette_AppendAdjustLabels(lpHeadPalette, iPalette, iStart, iNewColors);

	return(TRUE);
}