Skip to content
This repository was archived by the owner on Oct 25, 2023. It is now read-only.

Commit 94bdce4

Browse files
committed
Use initializer lists instead of parentheses
Signed-off-by: Quentin Guidée <[email protected]>
1 parent 990a176 commit 94bdce4

28 files changed

+106
-101
lines changed

.clang-format

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ ConstructorInitializerAllOnOneLineOrOnePerLine: false
2121
ColumnLimit: 0
2222

2323
FixNamespaceComments: false
24+
25+
Cpp11BracedListStyle: false
26+
SpaceBeforeCpp11BracedList: true

benchmarks/common.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
template <typename Decoder>
2121
RawImage decode(const std::string& filename)
2222
{
23-
InputFileStream in(TEST_IMAGES_PATH + filename);
23+
InputFileStream in { TEST_IMAGES_PATH + filename };
2424

25-
RawImage image = RawImage();
25+
RawImage image;
2626
Decoder(in, image).decode();
2727

2828
return image;
@@ -31,7 +31,7 @@ RawImage decode(const std::string& filename)
3131
template <typename Encoder>
3232
Encoder encode(const std::string& filename, RawImage& image)
3333
{
34-
OutputFileStream out(TEST_IMAGES_PATH + filename);
34+
OutputFileStream out { TEST_IMAGES_PATH + filename };
3535
Encoder encoder(out, image);
3636
encoder.encode();
3737

@@ -48,7 +48,7 @@ void BM_decode(benchmark::State& state, const std::string& filename)
4848
template <typename Decoder, typename Encoder>
4949
void BM_encode(benchmark::State& state, const std::string& filename)
5050
{
51-
std::string output_filename = "temp_" + filename;
51+
std::string output_filename { "temp_" + filename };
5252

5353
RawImage image = decode<Decoder>(filename);
5454

src/bmp/bmp_common.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ uint32_t BMP::float2_30_to_uint32(BMP::float2_30_t value)
1717
}
1818

1919
BMP::Bitmask::Bitmask(uint32_t value) :
20-
value(value),
21-
offset(first_bit_set(value)),
22-
divider(generate_bitmask<double>(count_set_bits(value)))
20+
value{ value },
21+
offset{ first_bit_set(value) },
22+
divider{ generate_bitmask<double>(count_set_bits(value)) }
2323
{
2424
}

src/bmp/bmp_decoder.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void BMP::Decoder::decode()
4141
decode_info_header_v5();
4242
break;
4343
default:
44-
throw UnsupportedVersionException("Cannot decode headers of size " + std::to_string(header_size) + ".");
44+
throw UnsupportedVersionException { "Cannot decode headers of size " + std::to_string(header_size) + "." };
4545
}
4646

4747
decode_color_table();
@@ -221,10 +221,10 @@ void BMP::Decoder::decode_pixel_array_16_bpp()
221221
{
222222
if (settings.compression == Compression::RGB)
223223
{
224-
settings.bitmask_a = Bitmask(0b0000000000000000);
225-
settings.bitmask_r = Bitmask(0b0000000000111110);
226-
settings.bitmask_g = Bitmask(0b0000011111000000);
227-
settings.bitmask_b = Bitmask(0b1111100000000000);
224+
settings.bitmask_a = { 0b0000000000000000 };
225+
settings.bitmask_r = { 0b0000000000111110 };
226+
settings.bitmask_g = { 0b0000011111000000 };
227+
settings.bitmask_b = { 0b1111100000000000 };
228228
}
229229

230230
for (uint32_t y = 0; y < image.height; ++y)
@@ -240,7 +240,7 @@ void BMP::Decoder::decode_pixel_array_16_bpp()
240240
void BMP::Decoder::decode_pixel_array_24_bpp()
241241
{
242242
if (settings.compression == Compression::BITFIELDS)
243-
throw DecodeException("The bitfields compression method is not allowed for 24bpp images.");
243+
throw DecodeException { "The bitfields compression method is not allowed for 24bpp images." };
244244

245245
for (uint32_t y = 0; y < image.height; ++y)
246246
{
@@ -256,10 +256,10 @@ void BMP::Decoder::decode_pixel_array_32_bpp()
256256
{
257257
if (settings.compression == Compression::RGB)
258258
{
259-
settings.bitmask_a = Bitmask(0x00000000);
260-
settings.bitmask_r = Bitmask(0x0000ff00);
261-
settings.bitmask_g = Bitmask(0x00ff0000);
262-
settings.bitmask_b = Bitmask(0xff000000);
259+
settings.bitmask_a = { 0x00000000 };
260+
settings.bitmask_r = { 0x0000ff00 };
261+
settings.bitmask_g = { 0x00ff0000 };
262+
settings.bitmask_b = { 0xff000000 };
263263
}
264264

265265
for (uint32_t i = 0; i < image.width * image.height; ++i)
@@ -268,10 +268,11 @@ void BMP::Decoder::decode_pixel_array_32_bpp()
268268

269269
void BMP::Decoder::decode_one_pixel_bitmask(uint32_t value)
270270
{
271-
Pixel pixel(
272-
((value & settings.bitmask_r.value) >> settings.bitmask_r.offset) * (255 / settings.bitmask_r.divider),
273-
((value & settings.bitmask_g.value) >> settings.bitmask_g.offset) * (255 / settings.bitmask_g.divider),
274-
((value & settings.bitmask_b.value) >> settings.bitmask_b.offset) * (255 / settings.bitmask_b.divider));
271+
Pixel pixel {
272+
(uint8_t)(((value & settings.bitmask_r.value) >> settings.bitmask_r.offset) * (255 / settings.bitmask_r.divider)),
273+
(uint8_t)(((value & settings.bitmask_g.value) >> settings.bitmask_g.offset) * (255 / settings.bitmask_g.divider)),
274+
(uint8_t)(((value & settings.bitmask_b.value) >> settings.bitmask_b.offset) * (255 / settings.bitmask_b.divider)),
275+
};
275276

276277
if (settings.bitmask_a.value != 0)
277278
pixel.a = ((value & settings.bitmask_a.value) >> settings.bitmask_a.offset) * (255 / settings.bitmask_a.divider);

src/bmp/bmp_decoder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Decoder final : public BaseDecoder
1717

1818
public:
1919
Decoder(InputStream &in, RawImage &image) :
20-
BaseDecoder(in, image) {}
20+
BaseDecoder { in, image } {}
2121

2222
static bool can_decode(InputStream &in);
2323

src/bmp/bmp_encoder.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void BMP::Encoder::encode()
4141
encode_info_header_v5();
4242
break;
4343
default:
44-
throw UnsupportedVersionException("Cannot encode headers of size " + std::to_string(header_size) + ".");
44+
throw UnsupportedVersionException { "Cannot encode headers of size " + std::to_string(header_size) + "." };
4545
}
4646

4747
encode_color_table();
@@ -224,10 +224,10 @@ void BMP::Encoder::encode_pixel_array_16_bpp()
224224
{
225225
if (settings.compression == Compression::RGB)
226226
{
227-
settings.bitmask_a = Bitmask(0b0000000000000000);
228-
settings.bitmask_r = Bitmask(0b0000000000111110);
229-
settings.bitmask_g = Bitmask(0b0000011111000000);
230-
settings.bitmask_b = Bitmask(0b1111100000000000);
227+
settings.bitmask_a = { 0b0000000000000000 };
228+
settings.bitmask_r = { 0b0000000000111110 };
229+
settings.bitmask_g = { 0b0000011111000000 };
230+
settings.bitmask_b = { 0b1111100000000000 };
231231
}
232232

233233
for (uint32_t y = 0; y < image.height; ++y)
@@ -252,7 +252,7 @@ void BMP::Encoder::encode_pixel_array_16_bpp()
252252
void BMP::Encoder::encode_pixel_array_24_bpp()
253253
{
254254
if (settings.compression == Compression::BITFIELDS)
255-
throw std::runtime_error("The bitfields compression method is not allowed for 24bpp images.");
255+
throw std::runtime_error { "The bitfields compression method is not allowed for 24bpp images." };
256256

257257
for (uint32_t y = 0; y < image.height; ++y)
258258
{
@@ -268,10 +268,10 @@ void BMP::Encoder::encode_pixel_array_32_bpp()
268268
{
269269
if (settings.compression == Compression::RGB)
270270
{
271-
settings.bitmask_a = Bitmask(0x00000000);
272-
settings.bitmask_r = Bitmask(0x0000ff00);
273-
settings.bitmask_g = Bitmask(0x00ff0000);
274-
settings.bitmask_b = Bitmask(0xff000000);
271+
settings.bitmask_a = { 0x00000000 };
272+
settings.bitmask_r = { 0x0000ff00 };
273+
settings.bitmask_g = { 0x00ff0000 };
274+
settings.bitmask_b = { 0xff000000 };
275275
}
276276

277277
for (uint32_t i = 0; i < image.width * image.height; ++i)
@@ -326,6 +326,6 @@ void BMP::Encoder::generate_colors_table_indexes()
326326
{
327327
const Pixel& pixel = settings.colors_table[i];
328328
const uint32_t hash = (pixel.r) + (pixel.g * 255) + (pixel.b * 255 * 255);
329-
colors_table_indexes.insert({hash, i});
329+
colors_table_indexes.insert({ hash, i });
330330
}
331331
}

src/bmp/bmp_encoder.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ namespace BMP {
1313
class Encoder final : public BaseEncoder
1414
{
1515
private:
16-
Settings settings;
16+
Settings settings {};
1717

1818
// r + 255 g + 255^2 b => colors_table index
19-
std::unordered_map<uint32_t, uint32_t> colors_table_indexes;
19+
std::unordered_map<uint32_t, uint32_t> colors_table_indexes {};
2020

2121
public:
2222
Encoder(OutputStream &out, RawImage &image) :
23-
BaseEncoder(out, image) {}
23+
BaseEncoder { out, image } {}
2424

2525
void encode() override;
2626

src/bmp/bmp_format.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
#include "format.hpp"
44

5-
static const Format BMP_FORMAT{
5+
static const Format BMP_FORMAT {
66
"bmp",
77
"Bitmap",
8-
{"bmp"},
8+
{ "bmp" },
99
};

src/bmp/bmp_settings.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ namespace BMP {
1111
struct Settings
1212
{
1313
// Header
14-
HeaderVersion header_version = HeaderVersion::INFO_HEADER_V5;
15-
Signature signature = Signature::BM;
14+
HeaderVersion header_version { HeaderVersion::INFO_HEADER_V5 };
15+
Signature signature { Signature::BM };
1616
uint32_t starting_address;
1717

1818
// Header core + info v1
19-
StartDecodingPosition start_decoding_position = StartDecodingPosition::TopLeft;
20-
BitCount bit_count = BitCount::BITCOUNT_6;
21-
Compression compression = Compression::RGB;
19+
StartDecodingPosition start_decoding_position { StartDecodingPosition::TopLeft };
20+
BitCount bit_count { BitCount::BITCOUNT_6 };
21+
Compression compression { Compression::RGB };
2222
int32_t x_pixels_per_meter, y_pixels_per_meter;
23-
uint32_t colors_count = 0;
24-
uint32_t important_colors_count = 0;
23+
uint32_t colors_count { 0 };
24+
uint32_t important_colors_count { 0 };
2525

2626
// Header info v2
2727
Bitmask bitmask_r, bitmask_g, bitmask_b;
@@ -30,7 +30,7 @@ struct Settings
3030
Bitmask bitmask_a;
3131

3232
// Header info v4
33-
LogicalColorSpace color_space_type = LogicalColorSpace::SRGB;
33+
LogicalColorSpace color_space_type { LogicalColorSpace::SRGB };
3434
CIEXYZTriple endpoints;
3535
float gamma_r, gamma_g, gamma_b;
3636

@@ -40,7 +40,7 @@ struct Settings
4040
uint32_t profile_size;
4141

4242
// Color table
43-
std::vector<Pixel> colors_table;
43+
std::vector<Pixel> colors_table {};
4444
};
4545

4646
}

src/common/decoder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class BaseDecoder
1313

1414
public:
1515
BaseDecoder(InputStream& in, RawImage& image) :
16-
in(in), image(image) {}
16+
in { in }, image { image } {}
1717

1818
virtual ~BaseDecoder() = default;
1919

0 commit comments

Comments
 (0)