2 * libid3tag - ID3 tag manipulation library
3 * Copyright (C) 2000-2004 Underbit Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * $Id: render.c,v 1.11 2004/01/23 09:41:32 rob Exp $
42 id3_length_t
id3_render_immediate(id3_byte_t
**ptr
,
43 char const *value
, unsigned int bytes
)
46 assert(bytes
== 8 || bytes
== 4 || bytes
== 3);
50 case 8: *(*ptr
)++ = *value
++;
54 case 4: *(*ptr
)++ = *value
++;
55 case 3: *(*ptr
)++ = *value
++;
64 id3_length_t
id3_render_syncsafe(id3_byte_t
**ptr
,
65 unsigned long num
, unsigned int bytes
)
67 assert(bytes
== 4 || bytes
== 5);
71 case 5: *(*ptr
)++ = (num
>> 28) & 0x0f;
72 case 4: *(*ptr
)++ = (num
>> 21) & 0x7f;
73 *(*ptr
)++ = (num
>> 14) & 0x7f;
74 *(*ptr
)++ = (num
>> 7) & 0x7f;
75 *(*ptr
)++ = (num
>> 0) & 0x7f;
82 id3_length_t
id3_render_int(id3_byte_t
**ptr
,
83 signed long num
, unsigned int bytes
)
85 assert(bytes
>= 1 && bytes
<= 4);
89 case 4: *(*ptr
)++ = num
>> 24;
90 case 3: *(*ptr
)++ = num
>> 16;
91 case 2: *(*ptr
)++ = num
>> 8;
92 case 1: *(*ptr
)++ = num
>> 0;
99 id3_length_t
id3_render_binary(id3_byte_t
**ptr
,
100 id3_byte_t
const *data
, id3_length_t length
)
106 memcpy(*ptr
, data
, length
);
113 id3_length_t
id3_render_latin1(id3_byte_t
**ptr
,
114 id3_latin1_t
const *latin1
, int terminate
)
121 size
= id3_latin1_size(latin1
);
126 memcpy(*ptr
, latin1
, size
);
133 id3_length_t
id3_render_string(id3_byte_t
**ptr
, id3_ucs4_t
const *ucs4
,
134 enum id3_field_textencoding encoding
,
137 enum id3_utf16_byteorder byteorder
= ID3_UTF16_BYTEORDER_ANY
;
140 ucs4
= id3_ucs4_empty
;
143 case ID3_FIELD_TEXTENCODING_ISO_8859_1
:
144 return id3_latin1_serialize(ptr
, ucs4
, terminate
);
146 case ID3_FIELD_TEXTENCODING_UTF_16BE
:
147 byteorder
= ID3_UTF16_BYTEORDER_BE
;
148 case ID3_FIELD_TEXTENCODING_UTF_16
:
149 return id3_utf16_serialize(ptr
, ucs4
, byteorder
, terminate
);
151 case ID3_FIELD_TEXTENCODING_UTF_8
:
152 return id3_utf8_serialize(ptr
, ucs4
, terminate
);
158 id3_length_t
id3_render_padding(id3_byte_t
**ptr
, id3_byte_t value
,
162 memset(*ptr
, value
, length
);
170 * NAME: render->paddedstring()
171 * DESCRIPTION: render a space-padded string using latin1 encoding
173 id3_length_t
id3_render_paddedstring(id3_byte_t
**ptr
, id3_ucs4_t
const *ucs4
,
176 id3_ucs4_t padded
[31], *data
, *end
;
178 /* latin1 encoding only (this is used for ID3v1 fields) */
180 assert(length
<= 30);
186 while (*ucs4
&& end
- data
> 0) {
189 if (data
[-1] == '\n')
194 while (end
- data
> 0)
199 return id3_latin1_serialize(ptr
, padded
, 0);