Skip to content

Commit 6f65a00

Browse files
committed
Resync
1 parent e3abd5d commit 6f65a00

12 files changed

Lines changed: 145 additions & 133 deletions

File tree

audio/conversion/float_to_s16.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ void convert_float_s16_asm(int16_t *out, const float *in, size_t samples);
5050
void convert_float_to_s16(int16_t *out,
5151
const float *in, size_t samples)
5252
{
53-
size_t i = 0;
53+
int16_t *out_ptr = NULL;
54+
const float *in_ptr = NULL;
55+
size_t i = 0;
5456
#if defined(__SSE2__)
5557
__m128 factor = _mm_set1_ps((float)0x8000);
5658

@@ -135,10 +137,13 @@ void convert_float_to_s16(int16_t *out,
135137

136138
#endif
137139

138-
for (; i < samples; i++)
140+
for (
141+
out_ptr = &out[i], in_ptr = &in[i]
142+
; i < samples
143+
; out_ptr++, in_ptr++, i++)
139144
{
140-
int32_t val = (int32_t)(in[i] * 0x8000);
141-
out[i] = (val > 0x7FFF) ? 0x7FFF :
145+
int32_t val = (int32_t)(*in_ptr * 0x8000);
146+
*out_ptr = (val > 0x7FFF) ? 0x7FFF :
142147
(val < -0x8000 ? -0x8000 : (int16_t)val);
143148
}
144149
}

audio/conversion/s16_to_float.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ void convert_s16_float_asm(float *out, const int16_t *in,
5050
void convert_s16_to_float(float *out,
5151
const int16_t *in, size_t samples, float gain)
5252
{
53-
unsigned i = 0;
53+
float *out_ptr = NULL;
54+
const int16_t *in_ptr = NULL;
55+
unsigned i = 0;
5456

5557
#if defined(__SSE2__)
5658
float fgain = gain / UINT32_C(0x80000000);
@@ -169,8 +171,11 @@ void convert_s16_to_float(float *out,
169171

170172
#endif
171173

172-
for (; i < samples; i++)
173-
out[i] = (float)in[i] * gain;
174+
for (
175+
out_ptr = &out[i], in_ptr = &in[i]
176+
; i < samples
177+
; out_ptr++, in_ptr++, i++)
178+
*out_ptr = (float)*in_ptr * gain;
174179
}
175180

176181
/**

encodings/encoding_crc32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ uint32_t file_crc32(uint32_t crc, const char *path)
117117
if (!buf)
118118
goto error;
119119

120-
for(i = 0; i < CRC32_MAX_MB; i++)
120+
for (i = 0; i < CRC32_MAX_MB; i++)
121121
{
122122
int64_t nread = filestream_read(file, buf, CRC32_BUFFER_SIZE);
123123
if (nread < 0)

formats/bmp/rbmp.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,40 +105,40 @@ static unsigned char *rbmp_convert_format(
105105
switch (((img_n)*8+(req_comp)))
106106
{
107107
case 10:
108-
for(i = x-1; i >= 0; --i, src += 1, dest += 2)
108+
for (i = x-1; i >= 0; --i, src += 1, dest += 2)
109109
{
110110
dest[0]=src[0];
111111
dest[1]=255;
112112
}
113113
break;
114114
case 11:
115-
for(i = x-1; i >= 0; --i, src += 1, dest += 3)
115+
for (i = x-1; i >= 0; --i, src += 1, dest += 3)
116116
dest[0]=dest[1]=dest[2]=src[0];
117117
break;
118118
case 12:
119-
for(i = x-1; i >= 0; --i, src += 1, dest += 4)
119+
for (i = x-1; i >= 0; --i, src += 1, dest += 4)
120120
{
121121
dest[0]=dest[1]=dest[2]=src[0];
122122
dest[3]=255;
123123
}
124124
break;
125125
case 17:
126-
for(i = x-1; i >= 0; --i, src += 2, dest += 1)
126+
for (i = x-1; i >= 0; --i, src += 2, dest += 1)
127127
dest[0]=src[0];
128128
break;
129129
case 19:
130-
for(i = x-1; i >= 0; --i, src += 2, dest += 3)
130+
for (i = x-1; i >= 0; --i, src += 2, dest += 3)
131131
dest[0]=dest[1]=dest[2]=src[0];
132132
break;
133133
case 20:
134-
for(i = x-1; i >= 0; --i, src += 2, dest += 4)
134+
for (i = x-1; i >= 0; --i, src += 2, dest += 4)
135135
{
136136
dest[0]=dest[1]=dest[2]=src[0];
137137
dest[3]=src[1];
138138
}
139139
break;
140140
case 28:
141-
for(i = x-1; i >= 0; --i, src += 3, dest += 4)
141+
for (i = x-1; i >= 0; --i, src += 3, dest += 4)
142142
{
143143
dest[0]=src[0];
144144
dest[1]=src[1];
@@ -147,29 +147,29 @@ static unsigned char *rbmp_convert_format(
147147
}
148148
break;
149149
case 25:
150-
for(i = x-1; i >= 0; --i, src += 3, dest += 1)
150+
for (i = x-1; i >= 0; --i, src += 3, dest += 1)
151151
dest[0] = RBMP_COMPUTE_Y(src[0],src[1],src[2]);
152152
break;
153153
case 26:
154-
for(i = x-1; i >= 0; --i, src += 3, dest += 2)
154+
for (i = x-1; i >= 0; --i, src += 3, dest += 2)
155155
{
156156
dest[0] = RBMP_COMPUTE_Y(src[0],src[1],src[2]);
157157
dest[1] = 255;
158158
}
159159
break;
160160
case 33:
161-
for(i = x-1; i >= 0; --i, src += 4, dest += 1)
161+
for (i = x-1; i >= 0; --i, src += 4, dest += 1)
162162
dest[0] = RBMP_COMPUTE_Y(src[0],src[1],src[2]);
163163
break;
164164
case 34:
165-
for(i = x-1; i >= 0; --i, src += 4, dest += 2)
165+
for (i = x-1; i >= 0; --i, src += 4, dest += 2)
166166
{
167167
dest[0] = RBMP_COMPUTE_Y(src[0],src[1],src[2]);
168168
dest[1] = src[3];
169169
}
170170
break;
171171
case 35:
172-
for(i = x-1; i >= 0; --i, src += 4, dest += 3)
172+
for (i = x-1; i >= 0; --i, src += 4, dest += 3)
173173
{
174174
dest[0]=src[0];
175175
dest[1]=src[1];

formats/png/rpng.c

Lines changed: 76 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -231,96 +231,76 @@ static bool png_process_ihdr(struct png_ihdr *ihdr)
231231
static void png_reverse_filter_copy_line_rgb(uint32_t *data,
232232
const uint8_t *decoded, unsigned width, unsigned bpp)
233233
{
234-
unsigned i;
234+
uint32_t *data_ptr = NULL;
235235

236236
bpp /= 8;
237237

238-
for (i = 0; i < width; i++)
238+
for (data_ptr = &data[0]; data_ptr < data + width; data_ptr++)
239239
{
240-
uint32_t r, g, b;
241-
242-
r = *decoded;
243-
decoded += bpp;
244-
g = *decoded;
245-
decoded += bpp;
246-
b = *decoded;
247-
decoded += bpp;
248-
data[i] = (0xffu << 24) | (r << 16) | (g << 8) | (b << 0);
240+
uint32_t r = *(decoded);
241+
uint32_t g = *(decoded + bpp);
242+
uint32_t b = *(decoded + bpp + bpp);
243+
decoded += (3 * bpp);
244+
*data_ptr = (0xffu << 24) | (r << 16) | (g << 8) | (b << 0);
249245
}
250246
}
251247

252248
static void png_reverse_filter_copy_line_rgba(uint32_t *data,
253249
const uint8_t *decoded, unsigned width, unsigned bpp)
254250
{
255-
unsigned i;
251+
uint32_t *data_ptr = NULL;
256252

257253
bpp /= 8;
258254

259-
for (i = 0; i < width; i++)
255+
for (data_ptr = &data[0]; data_ptr < data + width; data_ptr++)
260256
{
261-
uint32_t r, g, b, a;
262-
r = *decoded;
263-
decoded += bpp;
264-
g = *decoded;
265-
decoded += bpp;
266-
b = *decoded;
267-
decoded += bpp;
268-
a = *decoded;
269-
decoded += bpp;
270-
data[i] = (a << 24) | (r << 16) | (g << 8) | (b << 0);
257+
uint32_t r = *(decoded);
258+
uint32_t g = *(decoded + bpp);
259+
uint32_t b = *(decoded + bpp + bpp);
260+
uint32_t a = *(decoded + bpp + bpp + bpp);
261+
decoded += (4 * bpp);
262+
*data_ptr = (a << 24) | (r << 16) | (g << 8) | (b << 0);
271263
}
272264
}
273265

274266
static void png_reverse_filter_copy_line_bw(uint32_t *data,
275267
const uint8_t *decoded, unsigned width, unsigned depth)
276268
{
277-
unsigned i, bit;
278-
static const unsigned mul_table[] = { 0, 0xff, 0x55, 0, 0x11, 0, 0, 0, 0x01 };
279-
unsigned mul, mask;
280-
281-
if (depth == 16)
282-
{
283-
for (i = 0; i < width; i++)
284-
{
285-
uint32_t val = decoded[i << 1];
286-
data[i] = (val * 0x010101) | (0xffu << 24);
287-
}
288-
return;
289-
}
290-
291-
mul = mul_table[depth];
292-
mask = (1 << depth) - 1;
293-
bit = 0;
294-
295-
for (i = 0; i < width; i++, bit += depth)
269+
unsigned i;
270+
static const unsigned
271+
mul_table[] = { 0, 0xff, 0x55, 0, 0x11, 0, 0, 0, 0x01 };
272+
unsigned mul = mul_table[depth];
273+
unsigned mask = (1 << depth) - 1;
274+
unsigned bit = 0;
275+
uint32_t *data_ptr = NULL;
276+
277+
for ( i = 0, data_ptr = &data[0]
278+
; i < width
279+
; i++, data_ptr++, bit += depth)
296280
{
297281
unsigned byte = bit >> 3;
298282
unsigned val = decoded[byte] >> (8 - depth - (bit & 7));
299283

300284
val &= mask;
301285
val *= mul;
302-
data[i] = (val * 0x010101) | (0xffu << 24);
286+
*data_ptr = (val * 0x010101) | (0xffu << 24);
303287
}
304288
}
305289

306290
static void png_reverse_filter_copy_line_gray_alpha(uint32_t *data,
307291
const uint8_t *decoded, unsigned width,
308292
unsigned bpp)
309293
{
310-
unsigned i;
294+
uint32_t *data_ptr = NULL;
311295

312296
bpp /= 8;
313297

314-
for (i = 0; i < width; i++)
298+
for (data_ptr = &data[0]; data_ptr < data + width; data_ptr++)
315299
{
316-
uint32_t gray, alpha;
317-
318-
gray = *decoded;
319-
decoded += bpp;
320-
alpha = *decoded;
321-
decoded += bpp;
322-
323-
data[i] = (gray * 0x010101) | (alpha << 24);
300+
uint32_t gray = *(decoded);
301+
uint32_t alpha = *(decoded + bpp);
302+
decoded += (2 * bpp);
303+
*data_ptr = (gray * 0x010101) | (alpha << 24);
324304
}
325305
}
326306

@@ -480,10 +460,13 @@ static void png_reverse_filter_adam7_deinterlace_pass(uint32_t *data,
480460
for (y = 0; y < pass_height;
481461
y++, data += ihdr->width * pass->stride_y, input += pass_width)
482462
{
483-
uint32_t *out = data;
463+
uint32_t *out = data;
464+
const uint32_t *input_ptr = NULL;
484465

485-
for (x = 0; x < pass_width; x++, out += pass->stride_x)
486-
*out = input[x];
466+
for ( input_ptr = &input[0]
467+
; input_ptr < input + pass_width
468+
; input_ptr++, out += pass->stride_x)
469+
*out = *input_ptr;
487470
}
488471
}
489472

@@ -626,7 +609,23 @@ static int png_reverse_filter_copy_line(uint32_t *data, const struct png_ihdr *i
626609
switch (ihdr->color_type)
627610
{
628611
case PNG_IHDR_COLOR_GRAY:
629-
png_reverse_filter_copy_line_bw(data, pngp->decoded_scanline, ihdr->width, ihdr->depth);
612+
if (ihdr->depth == 16)
613+
{
614+
unsigned i;
615+
const uint8_t *decoded = pngp->decoded_scanline;
616+
unsigned width = ihdr->width;
617+
uint32_t *data_ptr = NULL;
618+
619+
for ( i = 0, data_ptr = &data[0]
620+
; i < width
621+
; data_ptr++, i++)
622+
{
623+
uint32_t val = decoded[i << 1];
624+
*data_ptr = (val * 0x010101) | (0xffu << 24);
625+
}
626+
}
627+
else
628+
png_reverse_filter_copy_line_bw(data, pngp->decoded_scanline, ihdr->width, ihdr->depth);
630629
break;
631630
case PNG_IHDR_COLOR_RGB:
632631
png_reverse_filter_copy_line_rgb(data, pngp->decoded_scanline, ihdr->width, ihdr->depth);
@@ -833,14 +832,17 @@ static int rpng_load_image_argb_process_inflate_init(rpng_t *rpng, uint32_t **da
833832
static bool png_read_plte(uint8_t *buf,
834833
uint32_t *buffer, unsigned entries)
835834
{
836-
unsigned i;
835+
uint8_t *buf_ptr = NULL;
836+
uint32_t *buffer_ptr = NULL;
837837

838-
for (i = 0; i < entries; i++)
838+
for ( buf_ptr = &buf[0], buffer_ptr = &buffer[0]
839+
; buffer_ptr < buffer + entries
840+
; buf_ptr += 3, buffer_ptr++)
839841
{
840-
uint32_t r = buf[3 * i + 0];
841-
uint32_t g = buf[3 * i + 1];
842-
uint32_t b = buf[3 * i + 2];
843-
buffer[i] = (r << 16) | (g << 8) | (b << 0) | (0xffu << 24);
842+
uint32_t r = *(buf_ptr);
843+
uint32_t g = *(buf_ptr + 1);
844+
uint32_t b = *(buf_ptr + 2);
845+
*buffer_ptr = (r << 16) | (g << 8) | (b << 0) | (0xffu << 24);
844846
}
845847

846848
return true;
@@ -956,16 +958,15 @@ static bool read_chunk_header(uint8_t *buf, uint8_t *buf_end,
956958
{
957959
unsigned i;
958960
uint8_t dword[4];
961+
uint8_t *dword_ptr = NULL;
962+
uint8_t *buf_ptr = NULL;
959963

960-
dword[0] = '\0';
964+
dword[0] = '\0';
961965

962-
/* Check whether reading the header will overflow
963-
* the data buffer */
964-
if (buf_end - buf < 8)
965-
return false;
966-
967-
for (i = 0; i < 4; i++)
968-
dword[i] = buf[i];
966+
for ( dword_ptr = &dword[0], buf_ptr = &buf[0]
967+
; dword_ptr < dword + 4
968+
; dword_ptr++, buf_ptr++)
969+
*dword_ptr = *buf_ptr;
969970

970971
chunk->size = dword_be(dword);
971972

@@ -1019,6 +1020,10 @@ bool rpng_iterate_image(rpng_t *rpng)
10191020
if (buf > rpng->buff_end)
10201021
return false;
10211022

1023+
/* Check whether reading the header will overflow
1024+
* the data buffer */
1025+
if (rpng->buff_end - buf < 8)
1026+
return false;
10221027
if (!read_chunk_header(buf, rpng->buff_end, &chunk))
10231028
return false;
10241029

0 commit comments

Comments
 (0)