Skip to content

Commit

Permalink
pixmap_scale: Don't make assumptions about inputs
Browse files Browse the repository at this point in the history
Fixes #244.

Signed-off-by: Abe Wieland <[email protected]>
  • Loading branch information
abewieland authored and artemsen committed Jan 26, 2025
1 parent e1509c3 commit 94acab8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/pixmap_scale.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,12 @@ void pixmap_scale(enum pixmap_aa_mode scaler, const struct pixmap* src,
struct pixmap* dst, ssize_t x, ssize_t y, float scale,
bool alpha)
{
// Do nothing if the scaled image won't appear on the destination pixmap
if (x >= (ssize_t)dst->width || (ssize_t)(x + src->width * scale) <= 0 ||
y >= (ssize_t)dst->height || (ssize_t)(y + src->height * scale) <= 0) {
return;
}

// TODO in some cases (especially when scaling to small outputs), using
// threads is actually slower - it may be worth implementing some better
// heuristics here to avoid using as many (or any) threads in those cases.
Expand Down
3 changes: 0 additions & 3 deletions src/pixmap_scale.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ extern const char* pixmap_aa_names[5];
* @param x,y destination left top coordinates
* @param scale scale of source pixmap
* @param alpha flag to use alpha blending
* Note that this function assumes -(src->width * scale) <= x < dst->width and
* -(src->height * scale) <= y < dst->height (i.e. that at least some part of
* the scaled image will appear on the destination)
*/
void pixmap_scale(enum pixmap_aa_mode scaler, const struct pixmap* src,
struct pixmap* dst, ssize_t x, ssize_t y, float scale,
Expand Down

0 comments on commit 94acab8

Please sign in to comment.