-
Notifications
You must be signed in to change notification settings - Fork 4
/
smolscale.h
88 lines (64 loc) · 3.19 KB
/
smolscale.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* Copyright © 2019-2023 Hans Petter Jansson. See COPYING for details. */
#include <stdint.h>
#ifndef _SMOLSCALE_H_
#define _SMOLSCALE_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef enum
{
/* 32 bits per pixel */
SMOL_PIXEL_RGBA8_PREMULTIPLIED,
SMOL_PIXEL_BGRA8_PREMULTIPLIED,
SMOL_PIXEL_ARGB8_PREMULTIPLIED,
SMOL_PIXEL_ABGR8_PREMULTIPLIED,
SMOL_PIXEL_RGBA8_UNASSOCIATED,
SMOL_PIXEL_BGRA8_UNASSOCIATED,
SMOL_PIXEL_ARGB8_UNASSOCIATED,
SMOL_PIXEL_ABGR8_UNASSOCIATED,
/* 24 bits per pixel */
SMOL_PIXEL_RGB8,
SMOL_PIXEL_BGR8,
SMOL_PIXEL_MAX
}
SmolPixelType;
typedef void (SmolPostRowFunc) (uint32_t *row_inout,
int width,
void *user_data);
typedef struct SmolScaleCtx SmolScaleCtx;
/* Simple API: Scales an entire image in one shot. You must provide pointers to
* the source memory and an existing allocation to receive the output data.
* This interface can only be used from a single thread. */
void smol_scale_simple (const void *pixels_in, SmolPixelType pixel_type_in,
uint32_t width_in, uint32_t height_in, uint32_t rowstride_in,
void *pixels_out, SmolPixelType pixel_type_out,
uint32_t width_out, uint32_t height_out, uint32_t rowstride_out,
uint8_t with_srgb);
/* Batch API: Allows scaling a few rows at a time. Suitable for multithreading. */
SmolScaleCtx *smol_scale_new (const void *pixels_in, SmolPixelType pixel_type_in,
uint32_t width_in, uint32_t height_in, uint32_t rowstride_in,
void *pixels_out, SmolPixelType pixel_type_out,
uint32_t width_out, uint32_t height_out, uint32_t rowstride_out,
uint8_t with_srgb);
SmolScaleCtx *smol_scale_new_full (const void *pixels_in, SmolPixelType pixel_type_in,
uint32_t width_in, uint32_t height_in, uint32_t rowstride_in,
void *pixels_out, SmolPixelType pixel_type_out,
uint32_t width_out, uint32_t height_out, uint32_t rowstride_out,
uint8_t with_srgb,
SmolPostRowFunc post_row_func, void *user_data);
void smol_scale_destroy (SmolScaleCtx *scale_ctx);
/* It's ok to call smol_scale_batch() without locking from multiple concurrent
* threads, as long as the outrows do not overlap. Make sure all workers are
* finished before you call smol_scale_destroy(). */
void smol_scale_batch (const SmolScaleCtx *scale_ctx, uint32_t first_outrow, uint32_t n_outrows);
/* Like smol_scale_batch(), but will write the output rows to outrows_dest
* instead of relative to pixels_out address handed to smol_scale_new(). The
* other parameters from init (size, rowstride, etc) will still be used. */
void smol_scale_batch_full (const SmolScaleCtx *scale_ctx,
void *outrows_dest,
uint32_t first_outrow, uint32_t n_outrows);
#ifdef __cplusplus
}
#endif
#endif