BRL-CAD
Loading...
Searching...
No Matches
io.h
Go to the documentation of this file.
1/* I O . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2011-2025 United States Government as represented by
5 * the U.S. Army Research Laboratory.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * version 2.1 as published by the Free Software Foundation.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this file; see the file named COPYING for more
18 * information.
19 */
20/** @addtogroup icv_io
21 *
22 * @brief
23 * Functions provided by the LIBICV image processing library for reading
24 * and writing of images.
25 *
26 */
27
28#ifndef ICV_IO_H
29#define ICV_IO_H
30
31#include <stddef.h> /* for size_t */
32
33#include "common.h"
34#include "vmath.h"
35#include "bu/mime.h"
36#include "icv/defines.h"
37
39
40/** @{ */
41/** @file icv/io.h */
42
43/**
44 * This function allocates memory for an image and returns the
45 * resultant image.
46 *
47 * @param width Width of the image to be created
48 * @param height Height of the image to be created
49 * @param color_space Color space of the image (RGB, grayscale)
50 * @return Image structure with allocated space and zeroed data array
51 */
52ICV_EXPORT extern icv_image_t *icv_create(size_t width, size_t height, ICV_COLOR_SPACE color_space);
53
54/**
55 * This function zeroes all the data entries of an image
56 * @param bif Image Structure
57 */
59
60/**
61 * This function frees the allocated memory for a ICV Structure and
62 * data.
63 */
65
66/**
67 * Function to calculate (or make an educated guess) about the
68 * dimensions of an image, when the image doesn't supply such
69 * information.
70 *
71 * Standard image sizes may be hinted using the label parameter. Many
72 * standard print and display sizes (e.g., "A4" and "SVGA") are
73 * recognized and used in concert with the dpi and data_size
74 * parameters.
75 *
76 * @param[in] label String hinting at a size (pass NULL if not using)
77 * @param[in] dpi Dots per inch of image (pass 0 if not using)
78 * @param[in] data_size Number of uncompressed image bytes (necessary if deducing an unspecified image size)
79 * @param[in] type Image type (necessary if deducing an unspecified image size)
80 *
81 * @param[out] widthp Pointer to variable that will hold image width
82 * @param[out] heightp Pointer to variable that will hold image height
83 *
84 * @return
85 * Returns 1 if an image size was identified, zero otherwise.
86 *
87 */
88ICV_EXPORT extern int icv_image_size(const char *label, size_t dpi, size_t data_size, bu_mime_image_t type, size_t *widthp, size_t *heightp);
89
90/**
91 * Load a file into an ICV struct. For most formats, this will be
92 * called with format=ICV_IMAGE_AUTO.
93 *
94 * The data is packed in icv_image struct in double format with varied
95 * channels as per the specification of image to be loaded.
96 *
97 * To read stream from stdin pass NULL pointer for filename.
98 *
99 * In case of bw and pix image if size is unknown pass 0 for width and
100 * height. This will read the image till EOF is reached. The image
101 * size of the output image will be : height = 1; width = size; where
102 * size = total bytes read
103 *
104 * @param filename File to read
105 * @param format Probable format of the file, typically
106 * ICV_IMAGE_AUTO
107 * @param width Width when passed as parameter from calling
108 * program.
109 * @param height Height when passed as parameter from calling
110 * program.
111 * @return A newly allocated struct holding the loaded image info.
112 */
113ICV_EXPORT extern icv_image_t *icv_read(const char *filename, bu_mime_image_t format, size_t width, size_t height);
114
115/**
116 * Saves Image to a file or streams to stdout in respective format
117 *
118 * To stream it to stdout pass NULL pointer for filename.
119 *
120 * @param bif Image structure of file.
121 * @param filename Filename of the file to be written.
122 * @param format Specific format of the file to be written.
123 * @return on success 0, on failure -1 with log messages.
124 */
125ICV_EXPORT extern int icv_write(icv_image_t *bif, const char*filename, bu_mime_image_t format);
126
127/**
128 * Write an image line to the data of ICV struct. Can handle unsigned
129 * char buffers.
130 *
131 * Note : This function requires memory allocation for ICV_UCHAR_DATA,
132 * which in turn acquires BU_SEM_SYSCALL semaphore.
133 *
134 * @param bif ICV struct where data is to be written
135 * @param y Index of the line at which data is to be written. 0 for
136 * the first line
137 * @param data Line Data to be written
138 * @param type Type of data, e.g., uint8 data specify ICV_DATA_UCHAR or 1
139 * @return on success 0, on failure -1
140 */
141ICV_EXPORT int icv_writeline(icv_image_t *bif, size_t y, void *data, ICV_DATA type);
142
143/**
144 * Writes a pixel to the specified coordinates in the data of ICV
145 * struct.
146 *
147 * @param bif ICV struct where data is to be written
148 * @param x x-dir coordinate of the pixel
149 * @param y y-dir coordinate of the pixel. (0,0) coordinate is taken
150 * as bottom left
151 * @param data Data to be written
152 * @return on success 0, on failure -1
153 */
154ICV_EXPORT int icv_writepixel(icv_image_t *bif, size_t x, size_t y, double *data);
155
156/**
157 * Converts double data of icv_image to unsigned char data.
158 * This function also does gamma correction using the gamma_corr
159 * parameter of the image structure.
160 *
161 * Gamma correction prevents bad color aliasing.
162 *
163 * @param bif ICV struct where data is to be read from
164 * @return array of unsigned char converted data, or NULL on failure
165 */
167
168/**
169 * Converts unsigned char array to double array.
170 * This function returns array of double data.
171 *
172 * Used to convert data from pix, bw, ppm type images for icv_image
173 * struct.
174 *
175 * This does not free the char data.
176 *
177 * @param data pointer to the array to be converted.
178 * @param size Size of the array.
179 * @return double array.
180 *
181 */
182ICV_EXPORT double *icv_uchar2double(unsigned char *data, size_t size);
183
184
185/**
186 * Options that can be passed to icv_ascii_art to modify its output.
187 */
193#define ICV_ASCII_ART_PARAMS_DEFAULT {0, 0, 1.0}
194
195/**
196 * Converts the image to an ASCII art text string. This function returns a
197 * char array - it is the caller's responsibility to free it.
198 *
199 * Note that this function does not attempt to correct for the aspect ratio
200 * problem (character printing in terminals often will result in the image
201 * being "stretched" in height.) If the use case calls for that, the
202 * application should use icv_resize to adjust the image before calling
203 * icv_ascii_art. (See the ascii libicv test code for an example.)
204 *
205 * @param i ICV image data.
206 * @param p ASCII text generation parameters.
207 * @return char array.
208 *
209 */
211
212/** @} */
213
215
216#endif /* ICV_IO_H */
217
218/*
219 * Local Variables:
220 * tab-width: 8
221 * mode: C
222 * indent-tabs-mode: t
223 * c-file-style: "stroustrup"
224 * End:
225 * ex: shiftwidth=4 tabstop=8
226 */
Definition dvec.h:74
Header file for the BRL-CAD common definitions.
void float float * y
Definition tig.h:73
void float float int int int int float * size
Definition tig.h:132
void float * x
Definition tig.h:72
ICV_COLOR_SPACE
Definition defines.h:50
ICV_DATA
Definition defines.h:56
double * icv_uchar2double(unsigned char *data, size_t size)
char * icv_ascii_art(icv_image_t *i, struct icv_ascii_art_params *p)
int icv_image_size(const char *label, size_t dpi, size_t data_size, bu_mime_image_t type, size_t *widthp, size_t *heightp)
int icv_destroy(icv_image_t *bif)
icv_image_t * icv_read(const char *filename, bu_mime_image_t format, size_t width, size_t height)
int icv_writeline(icv_image_t *bif, size_t y, void *data, ICV_DATA type)
unsigned char * icv_data2uchar(const icv_image_t *bif)
int icv_writepixel(icv_image_t *bif, size_t x, size_t y, double *data)
int icv_write(icv_image_t *bif, const char *filename, bu_mime_image_t format)
icv_image_t * icv_zero(icv_image_t *bif)
icv_image_t * icv_create(size_t width, size_t height, ICV_COLOR_SPACE color_space)
fastf_t brightness_multiplier
Definition io.h:191
fundamental vector, matrix, quaternion math macros