13 int keyword_length = strlen(keyword);
14 int text_length = strlen(text);
15 int data_length = keyword_length + 5 + text_length;
16 int chunk_length = 8 + data_length + 4;
20 bool png_iTXt(
const char *keyword,
const char *text,
unsigned char *chunk,
int length) {
21 #define INT(l) { l >> 24 & 0xff, l >> 16 & 0xff, l >> 8 & 0xff, l & 0xff }
22 int keyword_length = strlen(keyword);
23 int text_length = strlen(text);
24 int data_length = keyword_length + 5 + text_length;
25 int chunk_length = 8 + data_length + 4;
26 if (length < chunk_length) {
30 unsigned char len[4] =
INT(data_length);
35 const unsigned char iTXt[4] = { 105, 84, 88, 116 };
40 memcpy(chunk + k, keyword, keyword_length);
49 memcpy(chunk + k, text, text_length);
51 unsigned long crc_data =
crc(chunk + 4, data_length + 4);
52 unsigned char cyclic[4] =
INT(crc_data);
53 chunk[k++] = cyclic[0];
54 chunk[k++] = cyclic[1];
55 chunk[k++] = cyclic[2];
56 chunk[k++] = cyclic[3];
57 assert(k == chunk_length);