Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
ex_icc.c File Reference
#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>
Include dependency graph for ex_icc.c:

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()

Macro Definition Documentation

◆ PROFILE_LEN

#define PROFILE_LEN   301

the test profile's length, odd so the WebP padding is exercised

Examples
ex_icc.c.

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().

Function Documentation

◆ add()

void add ( unsigned char * buf,
size_t * len,
const void * data,
size_t n )
static

Append bytes to a growing buffer.

Parameters
bufthe buffer
lenits length, updated
datawhat to add
nhow many
Examples
ex_icc.c.

Definition at line 76 of file ex_icc.c.

Referenced by make_jpeg(), make_png(), make_webp(), png_chunk(), and segment().

Here is the caller graph for this function:

◆ be32()

void be32 ( unsigned char * p,
size_t v )
static

A big endian 32 bit value.

Parameters
pwhere
vthe value
Examples
ex_icc.c.

Definition at line 144 of file ex_icc.c.

Referenced by make_tiff(), and png_chunk().

Here is the caller graph for this function:

◆ check()

void check ( const char * what,
int ok )
static

Count and print a failed condition.

Parameters
whatwhat was checked
okthe condition
Examples
ex_icc.c, and ex_tiff.c.

Definition at line 46 of file ex_icc.c.

References failures.

Referenced by expect(), main(), test_broken(), and test_order().

Here is the caller graph for this function:

◆ expect()

void expect ( const char * what,
const unsigned char * buf,
size_t len,
const unsigned char * want,
int expect_result )
static

Find a profile in a buffer, and in the same bytes as a file.

Parameters
whatthe case
bufthe bytes
lenhow many
wantthe profile expected, or NULL for none
expect_resultwhat 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.

Here is the call graph for this function:

◆ icc_chunk()

void icc_chunk ( unsigned char * buf,
size_t * len,
int seq,
int of,
const unsigned char * part,
size_t n )
static

One ICC chunk of a JPEG.

Parameters
bufthe buffer
lenits length, updated
seqits number
ofhow many
partits share of the profile
nthat share's length
Examples
ex_icc.c.

Definition at line 105 of file ex_icc.c.

References PROFILE_LEN, and segment().

Referenced by make_jpeg().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ le32()

void le32 ( unsigned char * p,
size_t v )
static

A little endian 32 bit value.

Parameters
pwhere
vthe value

Definition at line 197 of file ex_icc.c.

◆ main()

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.

Parameters
argcargument count
argvarguments
Returns
0 on success

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().

Here is the call graph for this function:

◆ make_jpeg()

size_t make_jpeg ( unsigned char * buf,
const unsigned char * profile,
int chunks,
int padding )
static

A JPEG shaped buffer: SOI, an APP0, padding segments, the profile in two chunks, second first, and a start of scan.

Parameters
bufreceives it
profilethe profile, or NULL for none
chunks2 for both chunks, 1 to leave the second out
paddingAPP1 segments of 60000 bytes before the profile
Returns
its length
Examples
ex_icc.c.

Definition at line 122 of file ex_icc.c.

References add(), icc_chunk(), PROFILE_LEN, and segment().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_png()

size_t make_png ( unsigned char * buf,
const unsigned char * profile,
int after )
static

A PNG shaped buffer with the profile in iCCP, before or after IDAT.

Parameters
bufreceives it
profilethe profile
afternon-zero to put the iCCP after the image data, where it no longer counts
Returns
its length

Definition at line 173 of file ex_icc.c.

References add(), png_chunk(), and PROFILE_LEN.

Here is the call graph for this function:

◆ make_profile()

void make_profile ( unsigned char * out,
int ok )
static

A profile shaped buffer: its size, "acsp" at 36, a pattern after.

Parameters
outreceives PROFILE_LEN bytes
okzero to leave the signature out
Examples
ex_icc.c.

Definition at line 59 of file ex_icc.c.

References PROFILE_LEN.

Referenced by main().

Here is the caller graph for this function:

◆ make_tiff()

size_t make_tiff ( unsigned char * buf,
const unsigned char * profile,
int be )
static

A TIFF shaped buffer with the profile in tag 34675.

Parameters
bufreceives it
profilethe profile
benon-zero for big endian
Returns
its length
Examples
ex_icc.c.

Definition at line 235 of file ex_icc.c.

References be32(), le32(), and PROFILE_LEN.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_webp()

size_t make_webp ( unsigned char * buf,
const unsigned char * profile )
static

A WebP shaped buffer: VP8X, ICCP (odd length, padded), VP8L.

Parameters
bufreceives it
profilethe profile
Returns
its length
Examples
ex_icc.c.

Definition at line 208 of file ex_icc.c.

References add(), le32(), and PROFILE_LEN.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ png_chunk()

void png_chunk ( unsigned char * buf,
size_t * len,
const char * type,
const unsigned char * body,
size_t n )
static

A PNG chunk, CRC left zero: nothing here checks it.

Parameters
bufthe buffer
lenits length, updated
typethe four letters
bodythe contents
ntheir length
Examples
ex_icc.c.

Definition at line 157 of file ex_icc.c.

References add(), be32(), and type().

Referenced by make_png().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ segment()

void segment ( unsigned char * buf,
size_t * len,
unsigned marker,
const unsigned char * body,
size_t n )
static

A JPEG APP segment.

Parameters
bufthe buffer
lenits length, updated
markerthe marker byte, 0xE0 to 0xEF
bodythe segment's contents
ntheir length
Examples
ex_icc.c.

Definition at line 87 of file ex_icc.c.

References add().

Referenced by icc_chunk(), and make_jpeg().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ failures

int failures = 0
static

failures counted by check()

Definition at line 41 of file ex_icc.c.