void init_ppm(struct mandelbrot_param* param) { if(param->picture->data != NULL) { free(param->picture->data); param->picture->data = NULL; } param->picture->data = malloc(ppm_align(sizeof(color_t) * param->width, PPM_ALIGNMENT) * param->height); param->picture->height = param->height; param->picture->width = param->width; }
struct ppm * ppm_alloc(int width, int height) { struct ppm * picture; picture = malloc(sizeof(struct ppm)); if (picture != NULL) { picture->height = height; picture->width = width; picture->data = malloc(ppm_align(sizeof(color_t) * width, PPM_ALIGNMENT) * height); } return picture; }
/** * Converts an xy coordinate to the index of an unidimensional * array according to the size of the picture given */ color_t* coord_to_ptr(struct ppm * picture, int x, int y) { return (color_t*)(((char*)picture->data) + ppm_align(picture->width * sizeof(color_t), PPM_ALIGNMENT) * y + sizeof(color_t) * x); }