예제 #1
0
int ScaleFilter_ARGB(void *inData, unsigned int inRowBytes, void *outData, unsigned int outRowBytes, unsigned int height, unsigned int width, void *kernel, unsigned int kernel_height, unsigned int kernel_width, int colorChannel, vImage_Flags flags )
{
    vImage_Buffer in = { inData, height, width, inRowBytes };
    vImage_Buffer out = { outData, 0, 0, outRowBytes };
    TransformInfo *info = kernel; 
    float newHeight = height * info->yScale;	//Our slider uses powers of 2
    float newWidth = width * info->xScale;		//Our slider uses powers of 2
    
    out.height = newHeight;
    out.width = newWidth;
    
    return vImageScale_ARGB8888( &in, &out, NULL, flags ); 
}
예제 #2
0
// resize the image to the desired output size (DEFAULT = 800px[max x or y length])
void resize_image (vImage_Buffer *vImage_source, img_prop o, args flags) {

	// create the output buffer for processing too
	vImage_Buffer *vImage_processed = (vImage_Buffer*) malloc (sizeof (vImage_Buffer));

	// Check for null
	if (NULL == vImage_processed) {
		printf ("Cannot malloc vImage_processed buffer\n");
		exit (0);
	}
	
	// Return error value for vImage functions
	vImage_Error error;
	
	// if both the width and height have been set
	if (flags->image_h != -1 && flags->image_w != -1) {
		o->image_h = flags->image_h;
		o->image_w = flags->image_w;
	}
	
	// If the output width has been set
	if (flags->image_w != -1 && flags->image_h == -1) {

		// calculate the required length or width to scale the image and apply them to the image destination attributes
		if (vImage_source->width < vImage_source->height) {
			o->image_w = flags->image_w;
			o->image_h = calcImageLongSide (flags->image_w, 
											 vImage_source->height, 
											 vImage_source->width);
		} else {
			o->image_w = flags->image_w;
			o->image_h = calcImageShortSide (flags->image_w, 
											  vImage_source->width, 
											  vImage_source->height);
		}
	}

	// If the output height has been set
	if (flags->image_h != -1 && flags->image_w == -1) {

		// calculate the required length or width to scale the image and apply them to the image destination attributes
		if (vImage_source->width < vImage_source->height) {
			o->image_h = flags->image_h;
			o->image_w = calcImageShortSide (flags->image_h, 
											  vImage_source->height, 
											  vImage_source->width);
		} else {
			o->image_h = flags->image_h;
			o->image_w = calcImageLongSide (flags->image_h, 
											 vImage_source->width, 
											 vImage_source->height);
		}
	}

	// if the max length has been set ** overides the width or height settings
	if (flags->image_l != -1) {
		
		// calculate the required length or width to scale the image and apply them to the image destination attributes
		if (vImage_source->width < vImage_source->height) {
			o->image_h = flags->image_l;
			o->image_w = calcImageShortSide (flags->image_l, 
											  vImage_source->height, 
											  vImage_source->width);
		} else {
			o->image_w = flags->image_l;
			o->image_h = calcImageShortSide (flags->image_l, 
											  vImage_source->width, 
											  vImage_source->height);
		}
	}
	
	// setup the vimage buffers
	setupBuffer (vImage_processed, o->image_h, o->image_w, o->image_w * 4);
	
	//	printf ("mallocing blank data are for the processed image buffer\n");
	vImage_processed->data = malloc (vImage_processed->rowBytes * vImage_processed->height);
	
	// Check for null
	if (NULL == vImage_processed->data) 
		printf ("Unable to get the vimage.data pointer\n");
	
	// Scale the image
	error = vImageScale_ARGB8888 (vImage_source, 
								 vImage_processed, 
								 NULL, 
								 kvImageHighQualityResampling);
	if (error) {
		printf ("Resize error: %d\n", (int) error);
	}

	// return the processed data to the sourcebuffer
	reset_vImage (vImage_source, vImage_processed, o);

	// free the processing buffer
	free (vImage_processed);
	vImage_processed = NULL;

} // resize_image