Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated formatting and style checker tool #48

Merged
merged 3 commits into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# SPDX-License-Identifier: GPL-2.0-only
#
# clang-format configuration file. Intended for clang-format >= 7.
#
# For more information, see:
#
# Documentation/process/clang-format.rst
# https://clang.llvm.org/docs/ClangFormat.html
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
#
---
Language: Cpp
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortLambdasOnASingleLine: Inline
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BreakBeforeBraces: Allman
BraceWrapping:
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: false
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- 'udev_list_entry_foreach'
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(_test)?$'
IndentCaseLabels: false
IndentPPDirectives: None
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 8
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true

# Taken from git's rules
PenaltyBreakAssignment: 10
PenaltyBreakBeforeFirstCallParameter: 30
PenaltyBreakComment: 10
PenaltyBreakFirstLessLess: 0
PenaltyBreakString: 10
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 100
PenaltyReturnTypeOnItsOwnLine: 60

PointerAlignment: Right
ReflowComments: false
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceAfterLogicalNot: false
#SpaceBeforeCaseColon: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: c++17
IndentWidth: 4
TabWidth: 4
UseTab: Always
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
ColumnLimit: 120
...
16 changes: 7 additions & 9 deletions bmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* bmp.cpp - Encode image as bmp and write to file.
*/

#include <string>
#include <cstdio>
#include <string>

#include <libcamera/formats.h>

Expand All @@ -30,7 +30,7 @@ static_assert(sizeof(ImageHeader) == 40, "ImageHeader size wrong");

struct FileHeader
{
uint16_t dummy; // 2 dummy bytes so that our uint32_ts line up
uint16_t dummy; // 2 dummy bytes so that our uint32_ts line up
uint8_t type1 = 'B';
uint8_t type2 = 'M';
uint32_t filesize;
Expand All @@ -40,17 +40,15 @@ struct FileHeader
};
static_assert(sizeof(FileHeader) == 16, "FileHeader size wrong");

void bmp_save(std::vector<void *> const &mem, int w, int h, int stride,
libcamera::PixelFormat const &pixel_format,
std::string const &filename,
StillOptions const *options)
void bmp_save(std::vector<void *> const &mem, int w, int h, int stride, libcamera::PixelFormat const &pixel_format,
std::string const &filename, StillOptions const *options)
{
if (pixel_format != libcamera::formats::RGB888)
throw std::runtime_error("pixel format for bmp should be RGB");

FILE *fp = fopen(filename.c_str(), "wb");
FILE *fp = fopen(filename.c_str(), "wb");

if (fp == NULL)
if (fp == NULL)
throw std::runtime_error("failed to open file " + filename);

try
Expand All @@ -60,7 +58,7 @@ void bmp_save(std::vector<void *> const &mem, int w, int h, int stride,
unsigned int pad = pitch - line;
uint8_t padding[3] = {};
uint8_t *ptr = (uint8_t *)mem[0];

FileHeader file_header;
ImageHeader image_header;
file_header.filesize = file_header.offset + h * pitch;
Expand Down
Loading