26 image->
Resize(height, width, channels);
27 for (
int y = 0, a = 0;
y < height;
y++) {
28 for (
int x = 0;
x < width;
x++) {
29 for (
int k = 0; k < channels; k++) {
30 (*image)(
y,
x, k) = (
float)buffer[a++] / 255.0f;
41 image->
Resize(height, width, channels);
42 for (
int y = 0, a = 0;
y < height;
y++) {
43 for (
int x = 0;
x < width;
x++) {
44 for (
int k = 0; k < channels; k++) {
45 (*image)(
y,
x, k) = buffer[a++];
52 for (
int y = 0, a = 0;
y < image.
Height();
y++) {
53 for (
int x = 0;
x < image.
Width();
x++) {
54 for (
int k = 0; k < image.
Depth(); k++) {
55 buffer[a++] = image(
y,
x, k);
62 unsigned char* buffer) {
63 for (
int y = 0, a = 0;
y < image.
Height();
y++) {
64 for (
int x = 0;
x < image.
Width();
x++) {
65 for (
int k = 0; k < image.
Depth(); k++) {
66 buffer[a++] = image(
y,
x, k) * 255.0f;
77 const char* file_name) {
80 FILE* fp = fopen(file_name,
"wb");
87 png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
88 info_ptr = png_create_info_struct(png_ptr);
90 if (setjmp(png_jmpbuf(png_ptr))) {
95 png_init_io(png_ptr, fp);
98 if (setjmp(png_jmpbuf(png_ptr))) {
103 png_set_IHDR(png_ptr,
110 PNG_COMPRESSION_TYPE_BASE,
111 PNG_FILTER_TYPE_BASE);
113 png_write_info(png_ptr, info_ptr);
116 if (setjmp(png_jmpbuf(png_ptr))) {
121 png_write_image(png_ptr, row_pointers);
124 if (setjmp(png_jmpbuf(png_ptr))) {
129 png_write_end(png_ptr, NULL);
140 png_bytep* row_pointers;
144 row_pointers =
new png_bytep[image.
Height()];
147 row_pointers[
y] =
new png_byte[4 * image.
Width()];
149 for (
x = 0;
x < image.
Width();
x++) {
150 if (x0 ==
x && image.
Height() - y0 - 1 ==
y) {
151 row_pointers[
y][
x * 4 + 0] = 255;
152 row_pointers[
y][
x * 4 + 1] = 0;
153 row_pointers[
y][
x * 4 + 2] = 0;
154 row_pointers[
y][
x * 4 + 3] = 255;
156 float pixel = image(image.
Height() -
y - 1,
x, 0);
157 row_pointers[
y][
x * 4 + 0] = pixel * 255;
158 row_pointers[
y][
x * 4 + 1] = pixel * 255;
159 row_pointers[
y][
x * 4 + 2] = pixel * 255;
160 row_pointers[
y][
x * 4 + 3] = 255;
165 static int image_counter = 0;
168 file_name,
sizeof(file_name),
"%s_%02d.png", prefix, ++image_counter);
177 delete[] row_pointers[
y];
179 delete[] row_pointers;
194 double* warped_position_x,
195 double* warped_position_y) {
196 FloatImage libmv_image, libmv_patch, libmv_mask;
203 libmv_mask_for_sample = &libmv_mask;
211 libmv_mask_for_sample,
228 unsigned char* patch,
229 double* warped_position_x,
230 double* warped_position_y) {
238 libmv_mask_for_sample = &libmv_mask;
246 libmv_mask_for_sample,
void Resize(int height, int width, int depth=1)
#define assert(assertion)
bool libmv_saveImage(const FloatImage &image, const char *prefix, int x0, int y0)
static bool savePNGImage(png_bytep *row_pointers, int width, int height, int depth, int color_type, const char *file_name)
void libmv_floatBufferToFloatImage(const float *buffer, int width, int height, int channels, FloatImage *image)
void libmv_samplePlanarPatchFloat(const float *image, int width, int height, int channels, const double *xs, const double *ys, int num_samples_x, int num_samples_y, const float *mask, float *patch, double *warped_position_x, double *warped_position_y)
void libmv_samplePlanarPatchByte(const unsigned char *image, int width, int height, int channels, const double *xs, const double *ys, int num_samples_x, int num_samples_y, const float *mask, unsigned char *patch, double *warped_position_x, double *warped_position_y)
void libmv_floatImageToFloatBuffer(const FloatImage &image, float *buffer)
void libmv_floatImageDestroy(libmv_FloatImage *image)
bool SamplePlanarPatch(const FloatImage &image, const double *xs, const double *ys, int num_samples_x, int num_samples_y, FloatImage *mask, FloatImage *patch, double *warped_position_x, double *warped_position_y)
void libmv_floatImageToByteBuffer(const libmv::FloatImage &image, unsigned char *buffer)
void libmv_byteBufferToFloatImage(const unsigned char *buffer, int width, int height, int channels, FloatImage *image)
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
bool SamplePlanarPatch(const FloatImage &image, const double *xs, const double *ys, int num_samples_x, int num_samples_y, FloatImage *mask, FloatImage *patch, double *warped_position_x, double *warped_position_y)