![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
#include "nilorea/n_common.h"#include "nilorea/n_icc.h"#include "nilorea/n_log.h"#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <zlib.h>Go to the source code of this file.
Macros | |
| #define | PROFILE_LEN 301 |
| the test profile's length, odd so the WebP padding is exercised | |
Functions | |
| static void | add (unsigned char *buf, size_t *len, const void *data, size_t n) |
| Append bytes to a growing buffer. | |
| static void | be32 (unsigned char *p, size_t v) |
| A big endian 32 bit value. | |
| static void | check (const char *what, int ok) |
| Count and print a failed condition. | |
| static void | expect (const char *what, const unsigned char *buf, size_t len, const unsigned char *want, int expect_result) |
| Find a profile in a buffer, and in the same bytes as a file. | |
| static void | icc_chunk (unsigned char *buf, size_t *len, int seq, int of, const unsigned char *part, size_t n) |
| One ICC chunk of a JPEG. | |
| static void | le32 (unsigned char *p, size_t v) |
| A little endian 32 bit value. | |
| int | main (int argc, char **argv) |
| run the checks, or report a file's profile | |
| static size_t | make_jpeg (unsigned char *buf, const unsigned char *profile, int chunks, int padding) |
| A JPEG shaped buffer: SOI, an APP0, padding segments, the profile in two chunks, second first, and a start of scan. | |
| static size_t | make_png (unsigned char *buf, const unsigned char *profile, int after) |
| A PNG shaped buffer with the profile in iCCP, before or after IDAT. | |
| static void | make_profile (unsigned char *out, int ok) |
| A profile shaped buffer: its size, "acsp" at 36, a pattern after. | |
| static size_t | make_tiff (unsigned char *buf, const unsigned char *profile, int be) |
| A TIFF shaped buffer with the profile in tag 34675. | |
| static size_t | make_webp (unsigned char *buf, const unsigned char *profile) |
| A WebP shaped buffer: VP8X, ICCP (odd length, padded), VP8L. | |
| static void | png_chunk (unsigned char *buf, size_t *len, const char *type, const unsigned char *body, size_t n) |
| A PNG chunk, CRC left zero: nothing here checks it. | |
| static void | segment (unsigned char *buf, size_t *len, unsigned marker, const unsigned char *body, size_t n) |
| A JPEG APP segment. | |
Variables | |
| static int | failures = 0 |
| failures counted by check() | |
| #define PROFILE_LEN 301 |
the test profile's length, odd so the WebP padding is exercised
Definition at line 54 of file ex_icc.c.
Referenced by expect(), icc_chunk(), main(), make_jpeg(), make_png(), make_profile(), make_tiff(), and make_webp().
|
static |
Append bytes to a growing buffer.
| buf | the buffer |
| len | its length, updated |
| data | what to add |
| n | how many |
Definition at line 76 of file ex_icc.c.
Referenced by make_jpeg(), make_png(), make_webp(), png_chunk(), and segment().
|
static |
A big endian 32 bit value.
| p | where |
| v | the value |
Definition at line 144 of file ex_icc.c.
Referenced by make_tiff(), and png_chunk().
|
static |
Count and print a failed condition.
| what | what was checked |
| ok | the condition |
Definition at line 46 of file ex_icc.c.
References failures.
Referenced by expect(), main(), test_broken(), and test_order().
|
static |
Find a profile in a buffer, and in the same bytes as a file.
| what | the case |
| buf | the bytes |
| len | how many |
| want | the profile expected, or NULL for none |
| expect_result | what n_icc_from_buffer() should answer |
Definition at line 272 of file ex_icc.c.
References check(), n_icc_from_buffer(), n_icc_from_file(), and PROFILE_LEN.
|
static |
One ICC chunk of a JPEG.
| buf | the buffer |
| len | its length, updated |
| seq | its number |
| of | how many |
| part | its share of the profile |
| n | that share's length |
Definition at line 105 of file ex_icc.c.
References PROFILE_LEN, and segment().
Referenced by make_jpeg().
|
static |
| int main | ( | int | argc, |
| char ** | argv ) |
run the checks, or report a file's profile
-V LEVEL is accepted and ignored, as run_tests.sh passes it to every example; it used to be taken for the name of a file.
| argc | argument count |
| argv | arguments |
Definition at line 306 of file ex_icc.c.
References check(), expect(), failures, LOG_NULL, make_jpeg(), make_png(), make_profile(), make_tiff(), make_webp(), n_icc_from_buffer(), n_icc_from_file(), n_icc_is_profile(), PROFILE_LEN, and set_log_level().
|
static |
A JPEG shaped buffer: SOI, an APP0, padding segments, the profile in two chunks, second first, and a start of scan.
| buf | receives it |
| profile | the profile, or NULL for none |
| chunks | 2 for both chunks, 1 to leave the second out |
| padding | APP1 segments of 60000 bytes before the profile |
Definition at line 122 of file ex_icc.c.
References add(), icc_chunk(), PROFILE_LEN, and segment().
Referenced by main().
|
static |
A PNG shaped buffer with the profile in iCCP, before or after IDAT.
| buf | receives it |
| profile | the profile |
| after | non-zero to put the iCCP after the image data, where it no longer counts |
Definition at line 173 of file ex_icc.c.
References add(), png_chunk(), and PROFILE_LEN.
|
static |
A profile shaped buffer: its size, "acsp" at 36, a pattern after.
| out | receives PROFILE_LEN bytes |
| ok | zero to leave the signature out |
Definition at line 59 of file ex_icc.c.
References PROFILE_LEN.
Referenced by main().
|
static |
A TIFF shaped buffer with the profile in tag 34675.
| buf | receives it |
| profile | the profile |
| be | non-zero for big endian |
Definition at line 235 of file ex_icc.c.
References be32(), le32(), and PROFILE_LEN.
Referenced by main().
|
static |
A WebP shaped buffer: VP8X, ICCP (odd length, padded), VP8L.
| buf | receives it |
| profile | the profile |
Definition at line 208 of file ex_icc.c.
References add(), le32(), and PROFILE_LEN.
Referenced by main().
|
static |
A PNG chunk, CRC left zero: nothing here checks it.
| buf | the buffer |
| len | its length, updated |
| type | the four letters |
| body | the contents |
| n | their length |
Definition at line 157 of file ex_icc.c.
References add(), be32(), and type().
Referenced by make_png().
|
static |
A JPEG APP segment.
| buf | the buffer |
| len | its length, updated |
| marker | the marker byte, 0xE0 to 0xEF |
| body | the segment's contents |
| n | their length |
Definition at line 87 of file ex_icc.c.
References add().
Referenced by icc_chunk(), and make_jpeg().