From 924ca70a4006abbffc8f43f27c4f64c8fc517a08 Mon Sep 17 00:00:00 2001 From: foswret Date: Fri, 22 May 2026 11:52:34 -0500 Subject: draw_month_grid() doesn't use dimension struct anymore. create generate extents structs for month, paper, and day --- src/image.c | 173 ++++-------------------------------------------------------- 1 file changed, 10 insertions(+), 163 deletions(-) (limited to 'src/image.c') diff --git a/src/image.c b/src/image.c index 4295ab1..6180631 100644 --- a/src/image.c +++ b/src/image.c @@ -2,26 +2,9 @@ #include #include #include -#include #include "draw.h" -// Used for MagickWand -#define ThrowWandException(wand) \ -{ \ - char \ - *description; \ - \ - ExceptionType \ - severity; \ - \ - description=MagickGetException(wand,&severity); \ - (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \ - description=(char *) MagickRelinquishMemory(description); \ - exit(-1); \ -} - - // Draw an image at a specific point int draw_image(cairo_t *c, char *path, double x, double y) { @@ -42,163 +25,27 @@ int draw_image(cairo_t *c, char *path, double x, double y) { } image = cairo_image_surface_create_from_png(path); - cairo_set_source_surface(c, image, x, y); - cairo_paint(c); - - cairo_surface_destroy (image); - return 0; -} - - - - - - -unsigned long get_image_width(char *path) { - MagickBooleanType status; - MagickWand *wand; - - MagickWandGenesis(); - wand = NewMagickWand(); - status = MagickReadImage(wand, path); - - if (status == MagickFalse) { - ThrowWandException(wand); - } - - unsigned long width = MagickGetImageWidth(wand); - - wand = DestroyMagickWand(wand); - MagickWandTerminus(); - return width; -} - - - -unsigned long get_image_height(char *path) { - MagickBooleanType status; - MagickWand *wand; - - MagickWandGenesis(); - wand = NewMagickWand(); - status = MagickReadImage(wand, path); - - if (status == MagickFalse) { - ThrowWandException(wand); - } - - unsigned long height = MagickGetImageHeight(wand); - - wand = DestroyMagickWand(wand); - MagickWandTerminus(); - return height; -} + double width = cairo_image_surface_get_width(image); + double height = cairo_image_surface_get_height(image); + double fake_width = 100; + double fake_height = 100; + double width_scale = fake_width / width; + double height_scale = fake_height / height; + cairo_scale(c, width_scale, height_scale); -// Resize an image to a specific width and height. -// Optionally create a new file to preserve the source image. -int resize_image(char *path, double width, double height, bool create_new) { - MagickBooleanType status; - MagickWand *wand; - MagickWandGenesis(); - wand = NewMagickWand(); - status = MagickReadImage(wand, path); - - if (status == MagickFalse) { - ThrowWandException(wand); - } - - MagickResetIterator(wand); - - MagickResizeImage(wand, width, height, LanczosFilter, 1.0); - - if (create_new == true) { - char new_path[30]; - snprintf(new_path, sizeof(new_path), "%s.tmp", path); - status = MagickWriteImages(wand, new_path, MagickTrue); - } else { - status = MagickWriteImages(wand, path, MagickTrue); - } - - if (status == MagickFalse) { - ThrowWandException(wand); - } - wand = DestroyMagickWand(wand); - MagickWandTerminus(); - return 0; -} - - -// Create a cropped version of an image to a certain dimensions and position. -// Optionally create a new file to preserve the source image. -int crop_image(char *path, double width, double height, double x, double y, bool create_new) { - MagickBooleanType status; - MagickWand *wand; - - MagickWandGenesis(); - wand = NewMagickWand(); - status = MagickReadImage(wand, path); - - if (status == MagickFalse) { - ThrowWandException(wand); - } - - MagickResetIterator(wand); - - MagickCropImage(wand, width, height, x, y); - - if (create_new == true) { - char new_path[30]; - snprintf(new_path, sizeof(new_path), "%s.tmp", path); - status = MagickWriteImages(wand, new_path, MagickTrue); - } else { - status = MagickWriteImages(wand, path, MagickTrue); - } + cairo_set_source_surface(c, image, x, y); + cairo_paint(c); - if (status == MagickFalse) { - ThrowWandException(wand); - } - wand = DestroyMagickWand(wand); - MagickWandTerminus(); + cairo_surface_destroy (image); return 0; } -int prepare_month_art(char *path, struct dimensions *d) { - if (!d->header_width || !d->header_height) { - printf("Error: header_width and header_height unknown.\n"); - return 1; - } - - double desired_ratio = d->header_width / d->header_height; - - unsigned long width = get_image_width(path); - unsigned long height = get_image_height(path); - //double original_ratio = width / height; - - - // Landscape - if (desired_ratio > 1.0) { - } - - // Portrait - if (desired_ratio < 1.0) { - } - - - - printf("%lu x %lu\n", width, height); - - - return 0; - -} - - // Draw month art -- cgit v1.2.3