Skip to content

Commit

Permalink
update imagine with more module implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfriend99 committed Sep 24, 2024
1 parent ae8a586 commit eac79fd
Show file tree
Hide file tree
Showing 5 changed files with 488 additions and 7 deletions.
22 changes: 18 additions & 4 deletions packages/imagine/imagine.c
Original file line number Diff line number Diff line change
Expand Up @@ -1204,8 +1204,8 @@ DECLARE_MODULE_METHOD(imagine__clone) {
gdImagePtr image = (gdImagePtr)AS_PTR(args[0])->pointer;
CHECK_IMAGE_PTR(image);

gdImageClone(image);
RETURN;
gdImagePtr clone = gdImageClone(image);
RETURN_CLOSABLE_NAMED_PTR(clone, IMAGINE_IMAGE_PTR_NAME, imagine_free_image_ptrs);
}

DECLARE_MODULE_METHOD(imagine__setbrush) {
Expand Down Expand Up @@ -1565,15 +1565,22 @@ DECLARE_MODULE_METHOD(imagine__cropauto) {
}

DECLARE_MODULE_METHOD(imagine__scale) {
ENFORCE_ARG_COUNT(scale, 2);
ENFORCE_ARG_COUNT(scale, 4);
ENFORCE_ARG_TYPE(scale, 0, IS_PTR);
ENFORCE_ARG_TYPE(scale, 1, IS_NUMBER);
ENFORCE_ARG_TYPE(scale, 2, IS_NUMBER);
ENFORCE_ARG_TYPE(scale, 3, IS_NUMBER);

gdImagePtr image = (gdImagePtr)AS_PTR(args[0])->pointer;
CHECK_IMAGE_PTR(image);

gdInterpolationMethod originalMethod = gdImageGetInterpolationMethod(image); // cache the original method
gdImageSetInterpolationMethod(image, AS_NUMBER(args[3])); // use the give method

gdImagePtr new_image = gdImageScale(image, AS_NUMBER(args[1]), AS_NUMBER(args[2]));

gdImageSetInterpolationMethod(image, originalMethod); // restore the original the method

if(NULL == new_image) {
RETURN_ERROR("Failed to scale image to (%d, %d).", (int)AS_NUMBER(args[1]), (int)AS_NUMBER(args[2]));
}
Expand All @@ -1582,15 +1589,22 @@ DECLARE_MODULE_METHOD(imagine__scale) {
}

DECLARE_MODULE_METHOD(imagine__rotate) {
ENFORCE_ARG_COUNT(rotate, 2);
ENFORCE_ARG_COUNT(rotate, 4);
ENFORCE_ARG_TYPE(rotate, 0, IS_PTR);
ENFORCE_ARG_TYPE(rotate, 1, IS_NUMBER);
ENFORCE_ARG_TYPE(rotate, 2, IS_NUMBER);
ENFORCE_ARG_TYPE(rotate, 3, IS_NUMBER);

gdImagePtr image = (gdImagePtr)AS_PTR(args[0])->pointer;
CHECK_IMAGE_PTR(image);

gdInterpolationMethod originalMethod = gdImageGetInterpolationMethod(image); // cache the original method
gdImageSetInterpolationMethod(image, AS_NUMBER(args[3])); // use the give method

gdImagePtr new_image = gdImageRotateInterpolated(image, AS_NUMBER(args[1]), AS_NUMBER(args[2]));

gdImageSetInterpolationMethod(image, originalMethod); // restore the original the method

if(NULL == new_image) {
RETURN_ERROR("Failed to rotate image to angle %.16g.", AS_NUMBER(args[1]));
}
Expand Down
32 changes: 32 additions & 0 deletions packages/imagine/imagine/colors.b
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# SPECIAL COLORS

/**
* Use the current style, see `set_style()`
*/
var COLOR_STYLED = -2

/**
* Use the current brush, see `set_brush()`
*/
var COLOR_BRUSHED = -3

/**
* Use the current style and brush
*/
var COLOR_STYLED_BRUSHED = -4

/**
* Use the current tile, see `set_tile()`
*/
var COLOR_TILED = -5

/**
* Indicate transparency, what is not the same as the transparent
* color index; used for lines only
*/
var COLOR_TRANSPARENT = -6

/**
* Draw anti aliased
*/
var COLOR_ANTI_ALISED = -7
16 changes: 16 additions & 0 deletions packages/imagine/imagine/flips.b
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Image flip directions

/**
* Flip an image vertically and horizontally
*/
var FLIP_BOTH = 1

/**
* Flip an image horizontally
*/
var FLIP_HORIZONTAL = 2

/**
* Flip an image vertically
*/
var FLIP_VERTICAL = 3
1 change: 1 addition & 0 deletions packages/imagine/imagine/index.b
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ import .interpolations { * }
import .quants { * }
import .crops { * }
import .arcs { * }
import .colors { * }
import .image { * }
Loading

0 comments on commit eac79fd

Please sign in to comment.