mirror of
https://git.sr.ht/~calebccff/pbsplash
synced 2026-01-12 20:48:40 -09:00
clang-format
This commit is contained in:
parent
4410f12762
commit
86b7c8f1c3
3 changed files with 411 additions and 288 deletions
119
.clang-format
Normal file
119
.clang-format
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
#
|
||||
# clang-format configuration file.
|
||||
#
|
||||
# For more information, see:
|
||||
#
|
||||
# Documentation/process/clang-format.rst
|
||||
# https://clang.llvm.org/docs/ClangFormat.html
|
||||
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
|
||||
#
|
||||
# Copied from Linux @ 5.18.0
|
||||
---
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignConsecutiveMacros: AcrossEmptyLines
|
||||
#AlignEscapedNewlines: Left # Unknown to clang-format-4.0
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: false
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: false
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BraceWrapping:
|
||||
AfterClass: false
|
||||
AfterControlStatement: false
|
||||
AfterEnum: false
|
||||
AfterFunction: true
|
||||
AfterNamespace: true
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
#AfterExternBlock: false # Unknown to clang-format-5.0
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
IndentBraces: false
|
||||
#SplitEmptyFunction: true # Unknown to clang-format-4.0
|
||||
#SplitEmptyRecord: true # Unknown to clang-format-4.0
|
||||
#SplitEmptyNamespace: true # Unknown to clang-format-4.0
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Custom
|
||||
#BreakBeforeInheritanceComma: false # Unknown to clang-format-4.0
|
||||
BreakBeforeTernaryOperators: false
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
#BreakConstructorInitializers: BeforeComma # Unknown to clang-format-4.0
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: false
|
||||
ColumnLimit: 80
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
#CompactNamespaces: false # Unknown to clang-format-4.0
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 8
|
||||
ContinuationIndentWidth: 8
|
||||
Cpp11BracedListStyle: false
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
#FixNamespaceComments: false # Unknown to clang-format-4.0
|
||||
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IndentCaseLabels: false
|
||||
#IndentPPDirectives: None # Unknown to clang-format-5.0
|
||||
IndentWidth: 8
|
||||
IndentWrappedFunctionNames: false
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
#ObjCBinPackProtocolList: Auto # Unknown to clang-format-5.0
|
||||
ObjCBlockIndentWidth: 8
|
||||
ObjCSpaceAfterProperty: true
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
|
||||
# Taken from git's rules
|
||||
#PenaltyBreakAssignment: 10 # Unknown to clang-format-4.0
|
||||
PenaltyBreakBeforeFirstCallParameter: 30
|
||||
PenaltyBreakComment: 10
|
||||
PenaltyBreakFirstLessLess: 0
|
||||
PenaltyBreakString: 10
|
||||
PenaltyExcessCharacter: 100
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
|
||||
PointerAlignment: Right
|
||||
ReflowComments: false
|
||||
SortIncludes: false
|
||||
#SortUsingDeclarations: false # Unknown to clang-format-4.0
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
#SpaceBeforeCtorInitializerColon: true # Unknown to clang-format-5.0
|
||||
#SpaceBeforeInheritanceColon: true # Unknown to clang-format-5.0
|
||||
SpaceBeforeParens: ControlStatements
|
||||
#SpaceBeforeRangeBasedForLoopColon: true # Unknown to clang-format-5.0
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInContainerLiterals: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Cpp03
|
||||
TabWidth: 8
|
||||
UseTab: Always
|
||||
...
|
||||
|
|
@ -12,7 +12,8 @@ struct col color = {.r = 255, .g = 255, .b = 255, .a = 255};
|
|||
|
||||
#define speed 3
|
||||
|
||||
void circles_wave(int frame, int w, int y_off, long dpi) {
|
||||
void circles_wave(int frame, int w, int y_off, long dpi)
|
||||
{
|
||||
unsigned int t_col = tfb_make_color(color.r, color.g, color.b);
|
||||
int f = frame * speed;
|
||||
|
||||
|
|
@ -21,12 +22,12 @@ void circles_wave(int frame, int w, int y_off, long dpi) {
|
|||
int amplitude = rad * 2;
|
||||
|
||||
int left = (w / 2) - (dist * (n_circles - 1) / 2.0);
|
||||
for (unsigned int i = 0; i < n_circles; i++)
|
||||
{
|
||||
for (unsigned int i = 0; i < n_circles; i++) {
|
||||
int x = left + (i * dist);
|
||||
double offset = sin(f / 60.0 * PI + i);
|
||||
int y = y_off + offset * amplitude;
|
||||
tfb_fill_rect(x - rad- 1, y_off - amplitude - rad, rad* 2 + 2, 400 +rad* 2, tfb_black);
|
||||
tfb_fill_rect(x - rad - 1, y_off - amplitude - rad, rad * 2 + 2,
|
||||
400 + rad * 2, tfb_black);
|
||||
tfb_fill_circle(x, y, rad, t_col);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
151
src/pbsplash.c
151
src/pbsplash.c
|
|
@ -37,14 +37,14 @@ bool debug = false;
|
|||
struct col background_color = { .r = 0, .g = 0, .b = 0, .a = 255 };
|
||||
|
||||
#define LOG(fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
do { \
|
||||
if (debug) \
|
||||
fprintf(stdout, fmt, ##__VA_ARGS__); \
|
||||
printf(fmt, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
int usage()
|
||||
{
|
||||
// clang-format off
|
||||
fprintf(stderr, "pbsplash: postmarketOS bootsplash generator\n");
|
||||
fprintf(stderr, "-------------------------------------------\n");
|
||||
fprintf(stderr, "pbsplash [-h] [-d] [-f font] [-s splash image] [-m message]\n\n");
|
||||
|
|
@ -55,6 +55,7 @@ int usage()
|
|||
fprintf(stderr, " -m message to show under the splash image\n");
|
||||
fprintf(stderr, " -p font size in pt (default: %d)\n", FONT_SIZE_PT);
|
||||
fprintf(stderr, " -d custom DPI (for testing)\n");
|
||||
// clang-format on
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -64,32 +65,40 @@ void term(int signum)
|
|||
terminate = 1;
|
||||
}
|
||||
|
||||
static void blit_buf(unsigned char *buf, int x, int y, int w, int h, bool vflip, bool redraw)
|
||||
static void blit_buf(unsigned char *buf, int x, int y, int w, int h, bool vflip,
|
||||
bool redraw)
|
||||
{
|
||||
struct col prev_col = { .r = 0, .g = 0, .b = 0, .a = 0 };
|
||||
unsigned int col = tfb_make_color(background_color.r, background_color.g, background_color.b);
|
||||
unsigned int col = tfb_make_color(
|
||||
background_color.r, background_color.g, background_color.b);
|
||||
|
||||
for (size_t i = 0; i < w; i++)
|
||||
{
|
||||
for (size_t j = 0; j < h; j++)
|
||||
{
|
||||
for (size_t i = 0; i < w; i++) {
|
||||
for (size_t j = 0; j < h; j++) {
|
||||
#if DEBUGRENDER == 1
|
||||
if (i == 0 || i == w - 1 || j == 0 || j == h - 1)
|
||||
{
|
||||
if (i == 0 || i == w - 1 || j == 0 || j == h - 1) {
|
||||
tfb_draw_pixel(x + i, y + h - j, tfb_red);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
struct col rgba = *(struct col *)(buf + (j * w + i) * 4);
|
||||
struct col rgba =
|
||||
*(struct col *)(buf + (j * w + i) * 4);
|
||||
if (rgba.a == 0 || rgba.rgba == background_color.rgba)
|
||||
continue;
|
||||
|
||||
// Alpha blending
|
||||
if (rgba.a != 255)
|
||||
{
|
||||
rgba.r = (rgba.r * rgba.a + background_color.r * (255 - rgba.a)) >> 8;
|
||||
rgba.g = (rgba.g * rgba.a + background_color.g * (255 - rgba.a)) >> 8;
|
||||
rgba.b = (rgba.b * rgba.a + background_color.b * (255 - rgba.a)) >> 8;
|
||||
if (rgba.a != 255) {
|
||||
rgba.r =
|
||||
(rgba.r * rgba.a +
|
||||
background_color.r * (255 - rgba.a)) >>
|
||||
8;
|
||||
rgba.g =
|
||||
(rgba.g * rgba.a +
|
||||
background_color.g * (255 - rgba.a)) >>
|
||||
8;
|
||||
rgba.b =
|
||||
(rgba.b * rgba.a +
|
||||
background_color.b * (255 - rgba.a)) >>
|
||||
8;
|
||||
}
|
||||
|
||||
// No need to generate the colour again if it's the same as the previous one
|
||||
|
|
@ -119,7 +128,8 @@ static void draw_svg(NSVGimage *image, int x, int y, int w, int h)
|
|||
nsvgDeleteRasterizer(rast);
|
||||
}
|
||||
|
||||
static void draw_text(NSVGimage *font, char *text, int x, int y, int width, int height, float scale, unsigned int tfb_col)
|
||||
static void draw_text(NSVGimage *font, char *text, int x, int y, int width,
|
||||
int height, float scale, unsigned int tfb_col)
|
||||
{
|
||||
LOG("text '%s': fontsz=%f, x=%d, y=%d, dimensions: %d x %d\n", text,
|
||||
scale, x, y, width, height);
|
||||
|
|
@ -127,7 +137,8 @@ static void draw_text(NSVGimage *font, char *text, int x, int y, int width, int
|
|||
unsigned char *img = malloc(width * height * 4);
|
||||
NSVGrasterizer *rast = nsvgCreateRasterizer();
|
||||
|
||||
nsvgRasterizeText(rast, font, 0, 0, scale, img, width, height, width * 4, text);
|
||||
nsvgRasterizeText(rast, font, 0, 0, scale, img, width, height,
|
||||
width * 4, text);
|
||||
|
||||
blit_buf(img, x, y, width, height, true, false);
|
||||
|
||||
|
|
@ -140,7 +151,8 @@ static void draw_text(NSVGimage *font, char *text, int x, int y, int width, int
|
|||
* Get the dimensions of a string in pixels.
|
||||
* based on the font size and the font SVG file.
|
||||
*/
|
||||
static void getTextDimensions(NSVGimage *font, char *text, float scale, int *width, int *height)
|
||||
static void getTextDimensions(NSVGimage *font, char *text, float scale,
|
||||
int *width, int *height)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
|
|
@ -152,15 +164,11 @@ static void getTextDimensions(NSVGimage *font, char *text, float scale, int *wid
|
|||
|
||||
NSVGshape **shapes = nsvgGetTextShapes(font, text, strlen(text));
|
||||
// Iterate over every glyph in the string to get the total width
|
||||
for (i = 0; i < strlen(text); i++)
|
||||
{
|
||||
for (i = 0; i < strlen(text); i++) {
|
||||
NSVGshape *shape = shapes[i];
|
||||
if (shape)
|
||||
{
|
||||
if (shape) {
|
||||
*width += (float)shapes[i]->horizAdvX * scale + 0.5;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
*width += font->defaultHorizAdv * scale;
|
||||
}
|
||||
}
|
||||
|
|
@ -190,11 +198,9 @@ int main(int argc, char **argv)
|
|||
sigaction(SIGTERM, &action, NULL);
|
||||
sigaction(SIGINT, &action, NULL);
|
||||
|
||||
while ((optflag = getopt(argc, argv, "hvf:s:m:p:d:")) != -1)
|
||||
{
|
||||
while ((optflag = getopt(argc, argv, "hvf:s:m:p:d:")) != -1) {
|
||||
char *end = NULL;
|
||||
switch (optflag)
|
||||
{
|
||||
switch (optflag) {
|
||||
case 'h':
|
||||
return usage();
|
||||
case 'v':
|
||||
|
|
@ -211,22 +217,21 @@ int main(int argc, char **argv)
|
|||
break;
|
||||
case 'p':
|
||||
font_size = strtof(optarg, &end);
|
||||
if (end == optarg)
|
||||
{
|
||||
fprintf(stderr, "Invalid font size: %s\n", optarg);
|
||||
if (end == optarg) {
|
||||
fprintf(stderr, "Invalid font size: %s\n",
|
||||
optarg);
|
||||
return usage();
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
if (!optarg)
|
||||
{
|
||||
if (!optarg) {
|
||||
fprintf(stderr, "--dpi requires an argument\n");
|
||||
return usage();
|
||||
}
|
||||
dpi = strtol(optarg, &end, 10);
|
||||
if (end == optarg)
|
||||
{
|
||||
fprintf(stderr, "Invalid font size: %s\n", optarg);
|
||||
if (end == optarg) {
|
||||
fprintf(stderr, "Invalid font size: %s\n",
|
||||
optarg);
|
||||
return usage();
|
||||
}
|
||||
break;
|
||||
|
|
@ -239,8 +244,7 @@ int main(int argc, char **argv)
|
|||
FILE *fp = fopen("/sys/devices/virtual/tty/tty0/active", "r");
|
||||
int len = strlen(active_tty);
|
||||
char *ptr = active_tty + len;
|
||||
if (fp != NULL)
|
||||
{
|
||||
if (fp != NULL) {
|
||||
fgets(ptr, TTY_PATH_LEN - len, fp);
|
||||
*(ptr + strlen(ptr) - 1) = '\0';
|
||||
fclose(fp);
|
||||
|
|
@ -249,9 +253,10 @@ int main(int argc, char **argv)
|
|||
|
||||
LOG("active tty: '%s'\n", active_tty);
|
||||
|
||||
if ((rc = tfb_acquire_fb(/*TFB_FL_USE_DOUBLE_BUFFER*/ 0, "/dev/fb0", active_tty)) != TFB_SUCCESS)
|
||||
{
|
||||
fprintf(stderr, "tfb_acquire_fb() failed with error code: %d\n", rc);
|
||||
if ((rc = tfb_acquire_fb(/*TFB_FL_USE_DOUBLE_BUFFER*/ 0, "/dev/fb0",
|
||||
active_tty)) != TFB_SUCCESS) {
|
||||
fprintf(stderr, "tfb_acquire_fb() failed with error code: %d\n",
|
||||
rc);
|
||||
rc = 1;
|
||||
return rc;
|
||||
}
|
||||
|
|
@ -263,43 +268,40 @@ int main(int argc, char **argv)
|
|||
int h_mm = tfb_screen_height_mm();
|
||||
// If DPI is specified on cmdline then calculate display size from it
|
||||
// otherwise calculate the dpi based on the display size.
|
||||
if (dpi > 0)
|
||||
{
|
||||
if (dpi > 0) {
|
||||
w_mm = w / (float)dpi * 25.4;
|
||||
h_mm = h / (float)dpi * 25.4;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dpi = (float)w / (float)w_mm * 25.4;
|
||||
}
|
||||
int pixels_per_milli = (float)w / (float)w_mm;
|
||||
|
||||
float logo_size_px = (float)(w < h ? w : h) * 0.75f;
|
||||
if (w_mm > 0 && h_mm > 0)
|
||||
{
|
||||
if (w_mm < h_mm)
|
||||
{
|
||||
if (w_mm > 0 && h_mm > 0) {
|
||||
if (w_mm < h_mm) {
|
||||
if (w_mm > (float)LOGO_SIZE_MAX_MM * 1.2f)
|
||||
logo_size_px = (float)LOGO_SIZE_MAX_MM * pixels_per_milli;
|
||||
}
|
||||
else
|
||||
{
|
||||
logo_size_px = (float)LOGO_SIZE_MAX_MM *
|
||||
pixels_per_milli;
|
||||
} else {
|
||||
if (h_mm > (float)LOGO_SIZE_MAX_MM * 1.2f)
|
||||
logo_size_px = (float)LOGO_SIZE_MAX_MM * pixels_per_milli;
|
||||
logo_size_px = (float)LOGO_SIZE_MAX_MM *
|
||||
pixels_per_milli;
|
||||
}
|
||||
}
|
||||
|
||||
LOG("%dx%d @ %dx%dmm, dpi=%ld, logo_size_px=%f\n", w, h, w_mm, h_mm, dpi, logo_size_px);
|
||||
LOG("%dx%d @ %dx%dmm, dpi=%ld, logo_size_px=%f\n", w, h, w_mm, h_mm,
|
||||
dpi, logo_size_px);
|
||||
|
||||
image = nsvgParseFromFile(splash_image, "", logo_size_px);
|
||||
if (!image)
|
||||
{
|
||||
if (!image) {
|
||||
fprintf(stderr, "failed to load SVG image\n");
|
||||
rc = 1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
float sz = (float)logo_size_px / (image->width > image->height ? image->width : image->height);
|
||||
float sz =
|
||||
(float)logo_size_px /
|
||||
(image->width > image->height ? image->width : image->height);
|
||||
int image_w = image->width * sz + 0.5;
|
||||
int image_h = image->height * sz + 0.5;
|
||||
float x = (float)w / 2;
|
||||
|
|
@ -308,30 +310,33 @@ int main(int argc, char **argv)
|
|||
x -= image_w * 0.5f;
|
||||
y -= image_h * 0.5f;
|
||||
|
||||
tfb_clear_screen(tfb_make_color(background_color.r, background_color.g, background_color.b));
|
||||
tfb_clear_screen(tfb_make_color(background_color.r, background_color.g,
|
||||
background_color.b));
|
||||
|
||||
draw_svg(image, x, y, image_w, image_h);
|
||||
|
||||
if (message)
|
||||
{
|
||||
if (message) {
|
||||
int textWidth, textHeight;
|
||||
|
||||
font = nsvgParseFromFile(font_path, "px", 512);
|
||||
if (!font || !font->shapes)
|
||||
{
|
||||
if (!font || !font->shapes) {
|
||||
fprintf(stderr, "failed to load SVG font\n");
|
||||
rc = 1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
float fontsz = ((float)font_size * PT_TO_MM) / (font->fontAscent - font->fontDescent) * pixels_per_milli;
|
||||
float fontsz = ((float)font_size * PT_TO_MM) /
|
||||
(font->fontAscent - font->fontDescent) *
|
||||
pixels_per_milli;
|
||||
|
||||
getTextDimensions(font, message, fontsz, &textWidth, &textHeight);
|
||||
getTextDimensions(font, message, fontsz, &textWidth,
|
||||
&textHeight);
|
||||
|
||||
int tx = w / 2.f - textWidth / 2.f;
|
||||
int ty = y + image_h + textHeight * 0.5f + MM_TO_PX(dpi, 2);
|
||||
|
||||
draw_text(font, message, tx, ty, textWidth, textHeight, fontsz, tfb_gray);
|
||||
draw_text(font, message, tx, ty, textWidth, textHeight, fontsz,
|
||||
tfb_gray);
|
||||
}
|
||||
|
||||
tfb_flush_window();
|
||||
|
|
@ -340,14 +345,12 @@ int main(int argc, char **argv)
|
|||
int frame = 0;
|
||||
int tty = open(active_tty, O_RDWR);
|
||||
int tty_mode = 0;
|
||||
while (!terminate)
|
||||
{
|
||||
while (!terminate) {
|
||||
animate_frame(frame++, w, h, dpi);
|
||||
tfb_flush_fb();
|
||||
ioctl(tty, KDGETMODE, &tty_mode);
|
||||
// Login started and has reset the TTY back to text mode
|
||||
if (tty_mode == KD_TEXT)
|
||||
{
|
||||
if (tty_mode == KD_TEXT) {
|
||||
// tfb_flush_window();
|
||||
draw_svg(image, x, y, image_w, image_h);
|
||||
goto out;
|
||||
|
|
|
|||
Loading…
Reference in a new issue