Examples/ArenaC/C_Save_Ply/C_Save_Ply.c
AC_ERROR SaveImage(acBuffer hBuffer, const char* filename)
{
	// AC_ERROR and SC_ERROR values are equivalent
	AC_ERROR acErr = AC_ERR_SUCCESS;
	SC_ERROR saveErr = SC_ERR_SUCCESS;

	// Prepare image parameters
	//    An image's width, height, and bits per pixel are required to save to
	//    disk.
	printf("%sPrepare image parameters\n", TAB1);

	// get width
	size_t width = 0;

	acErr = acImageGetWidth(hBuffer, &width);
	if (acErr != AC_ERR_SUCCESS)
		return acErr;

	// get height
	size_t height = 0;

	acErr = acImageGetHeight(hBuffer, &height);
	if (acErr != AC_ERR_SUCCESS)
		return acErr;

	// get bits per pixel
	size_t bpp = 0;

	acErr = acImageGetBitsPerPixel(hBuffer, &bpp);
	if (acErr != AC_ERR_SUCCESS)
		return acErr;

	// Prepare image writer
	//    The image writer requires the image's parameters, a specified file name
	//    or pattern, and the image data to save. Providing these should result
	//    in a successfully saved file on the disk. Because an image's parameters
	//    and file name pattern may repeat, they can be passed into the image
	//    writer's constructor.
	printf("%sPrepare image writer\n", TAB1);
	saveWriter hWriter = NULL;

	saveErr = saveWriterCreate(width, height, bpp, &hWriter);
	if (saveErr != SC_ERR_SUCCESS)
		return saveErr;

	saveErr = saveWriterSetFileNamePattern(hWriter, filename);
	if (saveErr != SC_ERR_SUCCESS)
		return saveErr;

	// parameters for saveWriterSetPlyAndConfigExtended
	savePlyParams params =
	{
		true,			// filterPoints default
		isSignedPixelFormat,			
		0.25f,			// scale default
		0.0f,			// offsetA default
		0.0f,			// offsetB default
		0.0f			// offsetC default
	};

	saveErr = saveWriterSetPlyAndConfigExtended(hWriter, params);
	if (saveErr != AC_ERR_SUCCESS)
		return saveErr;

	// Save image
	//    Get and save the image. Notice that pointers to the beginning of the
	//    image data stay valid for the life cycle of the object, and do not
	//    require memory allocation or object destruction.
	printf("%sSave image\n", TAB1);

	// get image
	uint8_t* pData = NULL;

	acErr = acImageGetData(hBuffer, &pData);
	if (acErr != AC_ERR_SUCCESS)
		return acErr;

	// save image
	saveErr = saveWriterSave(hWriter, pData);
	if (saveErr != SC_ERR_SUCCESS)
		return saveErr;

	// destroy image writer
	saveErr = saveWriterDestroy(hWriter);
	if (saveErr != SC_ERR_SUCCESS)
		return saveErr;

	return SC_ERR_SUCCESS;	
}
// demonstrates saving an image
// (1) converts image to a displayable pixel format
// (2) prepares image parameters
// (3) prepares image writer
// (4) saves image
// (5) destroys converted image
demonstrates saving an image
(1) converts image to a displayable pixel format
(2) prepares image parameters
(3) prepares image writer
(4) saves image
(5) destroys converted image
demonstrates saving an image ( 1 ) converts image to a displayable pixel format ( 2 ) prepares image parameters ( 3 ) prepares image writer ( 4 ) saves image ( 5 ) destroys converted image
AC_ERROR SaveImage(acBuffer hBuffer, const char* filename)
{
	AC_ERROR acErr = AC_ERR_SUCCESS;
	SC_ERROR saveErr = SC_ERR_SUCCESS;
	printf("%sPrepare image parameters\n", TAB1);
	size_t width = 0;
	acErr = acImageGetWidth(hBuffer, &width);
	if (acErr != AC_ERR_SUCCESS)
		return acErr;
	size_t height = 0;
	acErr = acImageGetHeight(hBuffer, &height);
	if (acErr != AC_ERR_SUCCESS)
		return acErr;
	size_t bpp = 0;
	acErr = acImageGetBitsPerPixel(hBuffer, &bpp);
	if (acErr != AC_ERR_SUCCESS)
		return acErr;
	printf("%sPrepare image writer\n", TAB1);
	saveWriter hWriter = NULL;
	saveErr = saveWriterCreate(width, height, bpp, &hWriter);
	if (saveErr != SC_ERR_SUCCESS)
		return saveErr;
	saveErr = saveWriterSetFileNamePattern(hWriter, filename);
	if (saveErr != SC_ERR_SUCCESS)
		return saveErr;
	savePlyParams params =
	{
		true,			
		isSignedPixelFormat,			
		0.25f,			
		0.0f,			
		0.0f,			
		0.0f			
	};
	saveErr = saveWriterSetPlyAndConfigExtended(hWriter, params);
	if (saveErr != AC_ERR_SUCCESS)
		return saveErr;
	printf("%sSave image\n", TAB1);
	uint8_t* pData = NULL;
	acErr = acImageGetData(hBuffer, &pData);
	if (acErr != AC_ERR_SUCCESS)
		return acErr;
	saveErr = saveWriterSave(hWriter, pData);
	if (saveErr != SC_ERR_SUCCESS)
		return saveErr;
	saveErr = saveWriterDestroy(hWriter);
	if (saveErr != SC_ERR_SUCCESS)
		return saveErr;
	return SC_ERR_SUCCESS;	
}
AC_ERROR SaveImage ( acBuffer hBuffer , const char * filename ) { AC_ERROR acErr = AC_ERR_SUCCESS ; SC_ERROR saveErr = SC_ERR_SUCCESS ; printf ( " \n " , TAB1 ) ; size_t width = 0 ; acErr = acImageGetWidth ( hBuffer , & width ) ; if ( acErr != AC_ERR_SUCCESS ) return acErr ; size_t height = 0 ; acErr = acImageGetHeight ( hBuffer , & height ) ; if ( acErr != AC_ERR_SUCCESS ) return acErr ; size_t bpp = 0 ; acErr = acImageGetBitsPerPixel ( hBuffer , & bpp ) ; if ( acErr != AC_ERR_SUCCESS ) return acErr ; printf ( " \n " , TAB1 ) ; saveWriter hWriter = NULL ; saveErr = saveWriterCreate ( width , height , bpp , & hWriter ) ; if ( saveErr != SC_ERR_SUCCESS ) return saveErr ; saveErr = saveWriterSetFileNamePattern ( hWriter , filename ) ; if ( saveErr != SC_ERR_SUCCESS ) return saveErr ; savePlyParams params = { true , isSignedPixelFormat , 0.25f , 0.0f , 0.0f , 0.0f } ; saveErr = saveWriterSetPlyAndConfigExtended ( hWriter , params ) ; if ( saveErr != AC_ERR_SUCCESS ) return saveErr ; printf ( " \n " , TAB1 ) ; uint8_t * pData = NULL ; acErr = acImageGetData ( hBuffer , & pData ) ; if ( acErr != AC_ERR_SUCCESS ) return acErr ; saveErr = saveWriterSave ( hWriter , pData ) ; if ( saveErr != SC_ERR_SUCCESS ) return saveErr ; saveErr = saveWriterDestroy ( hWriter ) ; if ( saveErr != SC_ERR_SUCCESS ) return saveErr ; return SC_ERR_SUCCESS ; }
demonstrates saving an image
(1) converts image to a displayable pixel format
(2) prepares image parameters
(3) prepares image writer
(4) saves image
(5) destroys converted image
demonstrates saving an image ( 1 ) converts image to a displayable pixel format ( 2 ) prepares image parameters ( 3 ) prepares image writer ( 4 ) saves image ( 5 ) destroys converted image
// AC_ERROR and SC_ERROR values are equivalent // Prepare image parameters //    An image's width, height, and bits per pixel are required to save to //    disk. // get width // get height // get bits per pixel // Prepare image writer //    The image writer requires the image's parameters, a specified file name //    or pattern, and the image data to save. Providing these should result //    in a successfully saved file on the disk. Because an image's parameters //    and file name pattern may repeat, they can be passed into the image //    writer's constructor. // parameters for saveWriterSetPlyAndConfigExtended // filterPoints default // scale default // offsetA default // offsetB default // offsetC default // Save image //    Get and save the image. Notice that pointers to the beginning of the //    image data stay valid for the life cycle of the object, and do not //    require memory allocation or object destruction. // get image // save image // destroy image writer