-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpbm.h
126 lines (110 loc) · 3.38 KB
/
pbm.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#ifndef NETPBM__PBM_H_
#define NETPBM__PBM_H_
#include <stdbool.h>
#include <stdint.h>
#include "types/pbm.h"
#include "types/pgm.h"
/**
* Allocate memory for a PBM image.
*
* @param width The width of the image.
* @param height The height of the image.
* @return A pointer to the PbmImage, or NULL if an error occurred.
*/
extern PbmImage *AllocatePbm(uint32_t width, uint32_t height);
/**
* Read a PBM image from a file.
*
* @param filename The name of the file to read.
* @return A pointer to the image data, or NULL if an error occurred.
*/
extern PbmImage *ReadPbm(const char *filename);
/**
* Normalizes pixel values from 0-255 to double 0-1.
*
* @param image Input PgmImage
* @return Normalized image data
*/
extern double *NormalizePgm(const PgmImage *image);
/**
* Threshold function that always returns 128.
*
* @param x Unused
* @param y Unused
* @return 128
*/
extern uint8_t MiddleThreshold(__attribute__((unused)) uint32_t x,
__attribute__((unused)) uint32_t y);
/**
* Threshold function that returns a random value between 0 and 255.
*
* @param x Unused
* @param y Unused
* @return Random value between 0 and 255
*/
extern uint8_t RandomThreshold(__attribute__((unused)) uint32_t x,
__attribute__((unused)) uint32_t y);
/**
* Threshold function based on IGN (Interleaved Gradient Noise)
*
* @param x X coordinate
* @param y Y coordinate
* @return Threshold value between 0 and 255
*/
extern uint8_t IgnThreshold(uint32_t x, uint32_t y);
/**
* Convert a PGM image to a PBM image.
*
* @param image The PGM image to convert.
* @param threshold The threshold function (0-255) to use for the conversion.
* @return A pointer to the new PBM image, or NULL if an error
* occurred.
*/
extern PbmImage *PgmToPbm(const PgmImage *image, ThresholdFn threshold);
/**
* Convert a PGM image to a PBM image using Atkinson dithering.
*
* @param image The PGM image to convert.
* @return A pointer to the new PBM image, or NULL if an error
* occurred.
*/
extern PbmImage *PgmToPbmAtkinson(const PgmImage *image);
/**
* Convert a PGM image to a PBM image using Bayer (Ordered) Dithering.
*
* @param image The PGM image to convert.
* @return A pointer to the new PBM image, or NULL if an error
* occurred.
*/
extern PbmImage *PgmToPbmOrdered(const PgmImage *image, const PgmImage *map);
/**
* Convert a PGM image to a PBM image using Floyd–Steinberg dithering.
*
* @param image The PGM image to convert.
* @return A pointer to the new PBM image, or NULL if an error
* occurred.
*/
extern PbmImage *PgmToPbmFloydSteinberg(const PgmImage *image);
/**
* Convert a PGM image to a PBM image using Jarvis, Judice, and Ninke dithering.
*
* @param image The PGM image to convert.
* @return A pointer to the new PBM image, or NULL if an error
* occurred.
*/
extern PbmImage *PgmToPbmJarvisJudiceNinke(const PgmImage *image);
/**
* Write a PBM image to a file.
*
* @param filename The name of the file to write.
* @param image The image data to write.
* @return True if successful, false otherwise.
*/
extern bool WritePbm(const PbmImage *image, const char *filename);
/**
* Free memory used by a PBM image
*
* @param image Image to free
*/
extern void FreePbm(PbmImage *image);
#endif// NETPBM__PBM_H_