how to copy part of an image

Does anyone have any tips on how to efficiently copy a part of an image to another, something like copyPixels with a source and target rect? I’m currently using getPixels() and ofRect() to copy pixels one by one, and I’m almost sure there is a more efficient way, I just haven’t found it.

im using this function

unsigned char* testApp::grab(int x, int y, int w, int h) {  
	y = CLAMP(y, 0, orig_h);  
	for(int i=x; i<x+w; i++) {  
		for(int j=y; j<y+h; j++) {  
			pix[(i-x+(j-y)*w)*3] = pixels[(i+j* orig_w)*3];  
			pix[(i-x+(j-y)*w)*3+1] = pixels[(i+j* orig_w)*3+1];  
			pix[(i-x+(j-y)*w)*3+2] = pixels[(i+j* orig_w)*3+2];  
	return pix;  

greetings ascorbin