Skip to content

Commit bc44313

Browse files
committed
Resync
1 parent 6f65a00 commit bc44313

3 files changed

Lines changed: 78 additions & 93 deletions

File tree

audio/conversion/float_to_s16.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ 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-
int16_t *out_ptr = NULL;
54-
const float *in_ptr = NULL;
55-
size_t i = 0;
53+
size_t i = 0;
5654
#if defined(__SSE2__)
5755
__m128 factor = _mm_set1_ps((float)0x8000);
5856

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

138136
#endif
139137

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

audio/conversion/s16_to_float.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ 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-
float *out_ptr = NULL;
54-
const int16_t *in_ptr = NULL;
55-
unsigned i = 0;
53+
unsigned i = 0;
5654

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

172170
#endif
173171

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;
172+
for (; i < samples; i++)
173+
out[i] = (float)in[i] * gain;
179174
}
180175

181176
/**

formats/png/rpng.c

Lines changed: 71 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -231,76 +231,96 @@ 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-
uint32_t *data_ptr = NULL;
234+
unsigned i;
235235

236236
bpp /= 8;
237237

238-
for (data_ptr = &data[0]; data_ptr < data + width; data_ptr++)
238+
for (i = 0; i < width; i++)
239239
{
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);
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);
245249
}
246250
}
247251

248252
static void png_reverse_filter_copy_line_rgba(uint32_t *data,
249253
const uint8_t *decoded, unsigned width, unsigned bpp)
250254
{
251-
uint32_t *data_ptr = NULL;
255+
unsigned i;
252256

253257
bpp /= 8;
254258

255-
for (data_ptr = &data[0]; data_ptr < data + width; data_ptr++)
259+
for (i = 0; i < width; i++)
256260
{
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);
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);
263271
}
264272
}
265273

266274
static void png_reverse_filter_copy_line_bw(uint32_t *data,
267275
const uint8_t *decoded, unsigned width, unsigned depth)
268276
{
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)
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)
280296
{
281297
unsigned byte = bit >> 3;
282298
unsigned val = decoded[byte] >> (8 - depth - (bit & 7));
283299

284300
val &= mask;
285301
val *= mul;
286-
*data_ptr = (val * 0x010101) | (0xffu << 24);
302+
data[i] = (val * 0x010101) | (0xffu << 24);
287303
}
288304
}
289305

290306
static void png_reverse_filter_copy_line_gray_alpha(uint32_t *data,
291307
const uint8_t *decoded, unsigned width,
292308
unsigned bpp)
293309
{
294-
uint32_t *data_ptr = NULL;
310+
unsigned i;
295311

296312
bpp /= 8;
297313

298-
for (data_ptr = &data[0]; data_ptr < data + width; data_ptr++)
314+
for (i = 0; i < width; i++)
299315
{
300-
uint32_t gray = *(decoded);
301-
uint32_t alpha = *(decoded + bpp);
302-
decoded += (2 * bpp);
303-
*data_ptr = (gray * 0x010101) | (alpha << 24);
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);
304324
}
305325
}
306326

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

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

@@ -609,23 +626,7 @@ static int png_reverse_filter_copy_line(uint32_t *data, const struct png_ihdr *i
609626
switch (ihdr->color_type)
610627
{
611628
case PNG_IHDR_COLOR_GRAY:
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);
629+
png_reverse_filter_copy_line_bw(data, pngp->decoded_scanline, ihdr->width, ihdr->depth);
629630
break;
630631
case PNG_IHDR_COLOR_RGB:
631632
png_reverse_filter_copy_line_rgb(data, pngp->decoded_scanline, ihdr->width, ihdr->depth);
@@ -832,17 +833,14 @@ static int rpng_load_image_argb_process_inflate_init(rpng_t *rpng, uint32_t **da
832833
static bool png_read_plte(uint8_t *buf,
833834
uint32_t *buffer, unsigned entries)
834835
{
835-
uint8_t *buf_ptr = NULL;
836-
uint32_t *buffer_ptr = NULL;
836+
unsigned i;
837837

838-
for ( buf_ptr = &buf[0], buffer_ptr = &buffer[0]
839-
; buffer_ptr < buffer + entries
840-
; buf_ptr += 3, buffer_ptr++)
838+
for (i = 0; i < entries; i++)
841839
{
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);
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);
846844
}
847845

848846
return true;
@@ -958,15 +956,16 @@ static bool read_chunk_header(uint8_t *buf, uint8_t *buf_end,
958956
{
959957
unsigned i;
960958
uint8_t dword[4];
961-
uint8_t *dword_ptr = NULL;
962-
uint8_t *buf_ptr = NULL;
963959

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

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;
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];
970969

971970
chunk->size = dword_be(dword);
972971

@@ -1020,10 +1019,6 @@ bool rpng_iterate_image(rpng_t *rpng)
10201019
if (buf > rpng->buff_end)
10211020
return false;
10221021

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

0 commit comments

Comments
 (0)