#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define COLUMNS 64
#define ROWS 48
typedef struct buffer
{
unsigned char *data;
size_t size;
size_t capacity;
} buffer;
static size_t append(void *user, const void *data, size_t size)
{
buffer *file = user;
if (size > file->capacity - file->size)
{
return 0;
}
memcpy(file->data + file->size, data, size);
file->size += size;
return size;
}
static float heights[ROWS * COLUMNS];
static void generate_heights(void)
{
for (size_t row = 0; row < ROWS; ++row)
{
const double row_factor = 1e-6 * sin(0.2 * (double)row);
float *line = heights + row * COLUMNS;
for (size_t column = 0; column < COLUMNS; ++column)
{
line[column] = (float)(row_factor * cos(0.2 * (double)column));
}
}
}
{
}
int main(void)
{
generate_heights();
init_header(header);
size_t capacity = 0;
? malloc(capacity)
: NULL,
0, capacity};
if (file.data == NULL)
{
fprintf(stderr, "the file does not fit in memory\n");
return EXIT_FAILURE;
}
{
}
{
}
{
}
else
{
printf("%zu bytes of file in a buffer of %zu bytes\n", file.size,
file.capacity);
}
free(file.data);
return status ==
SDFIO_OK ? EXIT_SUCCESS : EXIT_FAILURE;
}
const sdfio_layout * sdfio_layout_packed(sdfio_data_type type)
Returns the layout of a plain array: the elements follow each other and the rows follow each other.
Reading and writing of ISO 25178-71 SDF surface data files.
Callbacks that provide or accept the bytes of a file.
Definition types.h:213
@ SDFIO_ISO_2_0
Revision ISO-2.0.
Definition types.h:76
sdfio_status
Result of a function call.
Definition types.h:31
@ SDFIO_OK
The call succeeded.
Definition types.h:33
const sdfio_allocator * sdfio_default_allocator(void)
Returns the allocator that uses malloc() and free().
@ SDFIO_TYPE_FLOAT
float: IEEE 754 binary32.
Definition types.h:114
sdfio_status sdfio_writer_add_binary(sdfio_writer *writer)
Adds the binary format to the formats that the writer writes.
sdfio_status sdfio_writer_estimate_size(const sdfio_writer *writer, const sdfio_header *header, size_t *size)
Estimates the number of bytes that the writer writes for a header, without the trailer.
sdfio_status sdfio_writer_create(const sdfio_allocator *allocator, sdfio_writer **writer)
Creates a writer.
struct sdfio_writer sdfio_writer
Opaque handle of a writer.
Definition writer.h:69
const char * sdfio_writer_error_message(const sdfio_writer *writer)
Returns a description of the most recent failure of the writer, or an empty string if none occurred.
void sdfio_writer_free(sdfio_writer *writer)
Releases a writer.
sdfio_status sdfio_create_stream(sdfio_writer *writer, const sdfio_stream *stream, const sdfio_header *header)
Starts a file that the header describes, including the numbers of columns and rows.
sdfio_status sdfio_write_heights(sdfio_writer *writer, const sdfio_layout *layout, const void *src)
Writes the whole data area from a matrix of heights in metres that lies in memory as the layout descr...
sdfio_status sdfio_end_file(sdfio_writer *writer)
Ends the file: closes the trailer, the last record, flushes the stream and, for a file that sdfio_cre...