Exemple #1
0
//-------------------------------------------------------------------------------
//
// SetupFilterRecordForProxy
//
// Called by the UI routine to set up the gFilterRecord with the proxy view
// information. CalcProxyScaleFactor sizes the proxy rectangle and calculates the
// scale factor. Then set up gFilterRecord and call advanceState() to init the
// inData with the pixel data for the display.
//
// Global Inputs and Outputs:
//		FilterRecord *gFilterRecord		inRect, inRowBytes, maskRect, etc. has all
//										the information needed to call 
//										advanceState so inData points to the proxy
//										pixel data and maskRect points to the 
//										selection data
//			
//-------------------------------------------------------------------------------
void SetupFilterRecordForProxy(void)
{
	CalcProxyScaleFactor();

	SetInRect(GetFilterRect()); // gFilterRecord->inRect = gFilterRecord->filterRect;
	
	VRect tempRect = GetInRect();
	
	ScaleRect(tempRect, 1, (int16)gData->scaleFactor);

	SetInRect(tempRect);
	
	SetMaskRect(GetInRect()); // gFilterRecord->maskRect = gFilterRecord->inRect;

	// Fixed numbers are 16.16 values 
	// the first 16 bits represent the whole number
	// the last 16 bits represent the fraction
	gFilterRecord->inputRate = (int32)gData->scaleFactor << 16;
	gFilterRecord->maskRate = (int32)gData->scaleFactor << 16;
 
	gFilterRecord->inputPadding = 255;
	gFilterRecord->maskPadding = gFilterRecord->inputPadding;
	
	gData->proxyWidth = gData->proxyRect.right - gData->proxyRect.left;
	gData->proxyHeight = gData->proxyRect.bottom - gData->proxyRect.top;
	gData->proxyPlaneSize = gData->proxyWidth * gData->proxyHeight;
}
int main(int argc,char* argv[])
{

	if (SDL_Init(SDL_INIT_VIDEO) < 0)
	{
		return -1;
	}

	atexit(SDL_Quit);

	SDL_Surface *screen = SDL_SetVideoMode(480, 272, 0, SDL_ASYNCBLIT|SDL_FULLSCREEN);

	if (screen == NULL)
	{
		printf("Video setmode fail\n");
		return -1;
	}

	SetPlayCallBack(&DispPlay);
	SetPlayUser(screen);

	if(OpenFile(argv[1]) < 0)
	{
		printf("Open File fail\n");
		return -1;
	}

	SDL_Event event;

	double pos = 20;

	while(SDL_WaitEvent(&event))
	{
		if(event.type == SDL_MOUSEBUTTONDOWN)
		{
			int type = GetInRect(event.button.x,event.button.y);

			switch(type)
			{
			case 0:
				Pause();
				break;
			case 1:
				Play();
				break;
			case 2:
				Seek(pos);
				pos += 20;
				break;
			case 3:
				Stop();
				goto end;
				break;
			}
		}
		SDL_Delay(10);
	}
end:
	SDL_FreeSurface(screen);
	SDL_Quit();
	return 0;
}
Exemple #3
0
//-------------------------------------------------------------------------------
//
// PaintProxy
//
// Paint the proxy rectangle using the displayPixels() call back in the
// gFilterRecord.
//
// NOTE:
// 16 bit pixel data does not work for the current version of Photoshop. You
// scale all of the pixel data down to 8 bit values and then display. I din't go
// through that exercise.
// 
//-------------------------------------------------------------------------------
void PaintProxy(HWND hDlg)
{
	PSPixelMap pixels;
	PSPixelMask mask;
	PAINTSTRUCT  ps;
	VRect  itemBounds;
	RECT  wRect;
	POINT	mapOrigin; 
	HDC		hDC;

	// find the proxy in screen cordinates and center the
	// proxy rectangle
	GetWindowRect(GetDlgItem(hDlg, kDProxyItem), &wRect);
	mapOrigin.x = 0;
	mapOrigin.y = 0;
	ClientToScreen(hDlg, &mapOrigin);

	VRect inRect = GetInRect();

	itemBounds.left = (((wRect.right + wRect.left - 
		                        inRect.right + 
								inRect.left) / 
								2) - mapOrigin.x);
	itemBounds.top = (((wRect.bottom + wRect.top - 
		                       inRect.bottom + 
							   inRect.top) / 
							   2) - mapOrigin.y);
	itemBounds.right = (itemBounds.left + 
		                       (inRect.right - 
							   inRect.left));
	itemBounds.bottom = (itemBounds.top + 
		                        (inRect.bottom - 
								inRect.top));
	
	hDC = BeginPaint(hDlg, &ps);	

	wRect.left = itemBounds.left;
	wRect.top = itemBounds.top;
	wRect.right = itemBounds.right;
	wRect.bottom = itemBounds.bottom;

	// paint the black frame with a one pixel space
	// between the image and the frame
	InflateRect(&wRect, 2, 2);
	FrameRect(hDC, &wRect, (HBRUSH)GetStockObject(BLACK_BRUSH));	
	InflateRect(&wRect, -2, -2);
	
	// init the PSPixel map
	pixels.version = 1;
	pixels.bounds.top = inRect.top;
	pixels.bounds.left = inRect.left;
	pixels.bounds.bottom = inRect.bottom;
	pixels.bounds.right = inRect.right;
	pixels.imageMode = DisplayPixelsMode(gFilterRecord->imageMode);
	pixels.rowBytes = gData->proxyWidth;
	pixels.colBytes = 1;
	pixels.planeBytes = gData->proxyPlaneSize;
	pixels.baseAddr = gData->proxyBuffer;

	pixels.mat = NULL;
	pixels.masks = NULL;
	pixels.maskPhaseRow = 0;
	pixels.maskPhaseCol = 0;

	// display the transparency information if it exists
	if (gFilterRecord->isFloating != NULL) 
	{
		mask.next = NULL;
		mask.maskData = gFilterRecord->maskData;
		mask.rowBytes = gFilterRecord->maskRowBytes;
		mask.colBytes = 1;
		mask.maskDescription = kSimplePSMask;
	
		pixels.masks = &mask;
	} 
	else if ((gFilterRecord->inLayerPlanes != 0) && 
		       (gFilterRecord->inTransparencyMask != 0)) 
	{
		mask.next = NULL;
		mask.maskData = ((int8 *) gData->proxyBuffer) + 
			            gData->proxyPlaneSize *
						CSPlanesFromMode(gFilterRecord->imageMode, 0);
		mask.rowBytes = gData->proxyWidth;
		mask.colBytes = 1;
		mask.maskDescription = kSimplePSMask;
	
		pixels.masks = &mask;
	}

	(gFilterRecord->displayPixels)(&pixels, 
		                           &pixels.bounds, 
								   itemBounds.top, 
								   itemBounds.left, 
								   (void*)hDC);

	EndPaint(hDlg, (LPPAINTSTRUCT) &ps);
}
Exemple #4
0
//-------------------------------------------------------------------------------
//
// DoFilter
//
// Randomly change the pixel values based on the parameters the user gave us from
// our dialog box or scripting. We do this a tile at a time making sure the rect.
// we ask for is in the bounds of the filterRect.
//
//-------------------------------------------------------------------------------
void DoFilter(void)
{
	// make the random number generated trully random
	srand((unsigned)time(NULL));

	int32 tileHeight = gFilterRecord->outTileHeight;
	int32 tileWidth = gFilterRecord->outTileWidth;

	if (tileWidth == 0 || tileHeight == 0)
	{
		*gResult = filterBadParameters;
		return;
	}

	VRect filterRect = GetFilterRect();
	int32 rectWidth = filterRect.right - filterRect.left;
	int32 rectHeight = filterRect.bottom - filterRect.top;

	CreateDissolveBuffer(tileWidth, tileHeight);

	// round up to the nearest horizontal and vertical tile count
	int32 tilesVert = (tileHeight - 1 + rectHeight) / tileHeight;
	int32 tilesHoriz = (tileWidth - 1 + rectWidth) / tileWidth;

	// Fixed numbers are 16.16 values 
	// the first 16 bits represent the whole number
	// the last 16 bits represent the fraction
	gFilterRecord->inputRate = (int32)1 << 16;
	gFilterRecord->maskRate = (int32)1 << 16;
 
	// variables for the progress bar, our plug in is so fast
	// we probably don't need these
	int32 progressTotal = tilesVert * tilesHoriz;
	int32 progressDone = 0;

	// loop through each tile makeing sure we don't go over the bounds
	// of the rectHeight or rectWidth
	for (int32 vertTile = 0; vertTile < tilesVert; vertTile++)
	{
		for (int32 horizTile = 0; horizTile < tilesHoriz; horizTile++)
		{
			UpdateDissolveBuffer(tileWidth, tileHeight);

			VRect filterRect = GetFilterRect();
			VRect inRect = GetInRect();

			inRect.top = vertTile * tileHeight + filterRect.top;
			inRect.left = horizTile * tileWidth + filterRect.left;
			inRect.bottom = inRect.top + tileHeight;
			inRect.right = inRect.left + tileWidth;

			if (inRect.bottom > rectHeight)
				inRect.bottom = rectHeight;
			if (inRect.right > rectWidth)
				inRect.right = rectWidth;

			SetInRect(inRect);

			// duplicate what's in the inData with the outData
			SetOutRect(inRect);
			
			// get the maskRect if the user has given us a selection
			if (gFilterRecord->haveMask)
			{
				SetMaskRect(inRect);
			}

			for (int16 plane = 0; plane < gFilterRecord->planes; plane++)
			{
				// we want one plane at a time, small memory foot print is good
				gFilterRecord->outLoPlane = gFilterRecord->inLoPlane = plane;
				gFilterRecord->outHiPlane = gFilterRecord->inHiPlane = plane;
	
				// update the gFilterRecord with our latest request
				*gResult = gFilterRecord->advanceState();
				if (*gResult != noErr) return;

				// muck with the pixels in the outData buffer
				uint8 color = 255;
				int16 expectedPlanes = CSPlanesFromMode(gFilterRecord->imageMode,
					                                    0);

				if (plane < expectedPlanes)
					color = gData->color[plane];

				DissolveRectangle(gFilterRecord->outData,
								  gFilterRecord->outRowBytes,
								  gFilterRecord->maskData,
								  gFilterRecord->maskRowBytes,
								  GetOutRect(), 
								  color,
								  gFilterRecord->depth);
			}

			// uh, update the progress bar
			gFilterRecord->progressProc(++progressDone, progressTotal);
			
			// see if the user is impatient or didn't mean to do that
			if (gFilterRecord->abortProc())
			{
				*gResult = userCanceledErr;
				return;
			}
		}
	}
	DeleteDissolveBuffer();
}