Skip to content

Commit

Permalink
Format C files according to google style
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbyttow committed Jan 17, 2021
1 parent 1af0700 commit acd555e
Show file tree
Hide file tree
Showing 19 changed files with 206 additions and 189 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{c,h,cpp,hpp,cc}]
indent_style = space
indent_size = 2
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
all: deps build test

deps:
deps: FORCE
CGO_CFLAGS_ALLOW=-Xpreprocessor go get ./...

build:
build: FORCE
CGO_CFLAGS_ALLOW=-Xpreprocessor go build ./vips

test:
test: FORCE
CGO_CFLAGS_ALLOW=-Xpreprocessor go test -v ./...

FORCE:
12 changes: 6 additions & 6 deletions vips/arithmetic.c
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#include "arithmetic.h"

int add(VipsImage *left, VipsImage *right, VipsImage **out) {
return vips_add(left, right, out, NULL);
return vips_add(left, right, out, NULL);
}

int multiply(VipsImage *left, VipsImage *right, VipsImage **out) {
return vips_multiply(left, right, out, NULL);
return vips_multiply(left, right, out, NULL);
}

int divide(VipsImage *left, VipsImage *right, VipsImage **out) {
return vips_divide(left, right, out, NULL);
return vips_divide(left, right, out, NULL);
}

int linear(VipsImage *in, VipsImage **out, double *a, double *b, int n) {
return vips_linear(in, out, a, b, n, NULL);
return vips_linear(in, out, a, b, n, NULL);
}

int linear1(VipsImage *in, VipsImage **out, double a, double b) {
return vips_linear1(in, out, a, b, NULL);
return vips_linear1(in, out, a, b, NULL);
}

int invert_image(VipsImage *in, VipsImage **out) {
return vips_invert(in, out, NULL);
return vips_invert(in, out, NULL);
}
78 changes: 37 additions & 41 deletions vips/color.c
Original file line number Diff line number Diff line change
@@ -1,50 +1,46 @@
#include "color.h"

#include <unistd.h>

int is_colorspace_supported(VipsImage *in)
{
return vips_colourspace_issupported(in) ? 1 : 0;
int is_colorspace_supported(VipsImage *in) {
return vips_colourspace_issupported(in) ? 1 : 0;
}

int to_colorspace(VipsImage *in, VipsImage **out, VipsInterpretation space)
{
return vips_colourspace(in, out, space, NULL);
int to_colorspace(VipsImage *in, VipsImage **out, VipsInterpretation space) {
return vips_colourspace(in, out, space, NULL);
}

// https://libvips.github.io/libvips/API/8.6/libvips-colour.html#vips-icc-transform
int optimize_icc_profile(VipsImage *in, VipsImage **out, int isCmyk, char *srgb_profile_path, char *gray_profile_path)
{
// todo: check current embedded profile, and skip if already set

int channels = vips_image_get_bands(in);
int result;

if (vips_icc_present() == 0)
{
return 1;
}

if (channels > 2)
{
if (isCmyk == 1)
{
result = vips_icc_transform(in, out, srgb_profile_path, "input_profile", "cmyk", "intent", VIPS_INTENT_PERCEPTUAL, NULL);
}
else
{
result = vips_icc_transform(in, out, srgb_profile_path, "embedded", TRUE, "intent", VIPS_INTENT_PERCEPTUAL, NULL);
// ignore embedded errors
if (result != 0)
{
result = 0;
*out = in;
}
}
}
else
{
result = vips_icc_transform(in, out, gray_profile_path, "input_profile", gray_profile_path, "embedded", TRUE, "intent", VIPS_INTENT_PERCEPTUAL, NULL);
}

return result;
int optimize_icc_profile(VipsImage *in, VipsImage **out, int isCmyk,
char *srgb_profile_path, char *gray_profile_path) {
// todo: check current embedded profile, and skip if already set

int channels = vips_image_get_bands(in);
int result;

if (vips_icc_present() == 0) {
return 1;
}

if (channels > 2) {
if (isCmyk == 1) {
result =
vips_icc_transform(in, out, srgb_profile_path, "input_profile",
"cmyk", "intent", VIPS_INTENT_PERCEPTUAL, NULL);
} else {
result = vips_icc_transform(in, out, srgb_profile_path, "embedded", TRUE,
"intent", VIPS_INTENT_PERCEPTUAL, NULL);
// ignore embedded errors
if (result != 0) {
result = 0;
*out = in;
}
}
} else {
result = vips_icc_transform(in, out, gray_profile_path, "input_profile",
gray_profile_path, "embedded", TRUE, "intent",
VIPS_INTENT_PERCEPTUAL, NULL);
}

return result;
}
7 changes: 4 additions & 3 deletions vips/convolution.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "convolution.h"

int gaussian_blur_image(VipsImage *in, VipsImage **out, double sigma) {
return vips_gaussblur(in, out, sigma, NULL);
return vips_gaussblur(in, out, sigma, NULL);
}

int sharpen_image(VipsImage *in, VipsImage **out, double sigma, double x1, double m2) {
return vips_sharpen(in, out, "sigma", sigma, "x1", x1, "m2", m2, NULL);
int sharpen_image(VipsImage *in, VipsImage **out, double sigma, double x1,
double m2) {
return vips_sharpen(in, out, "sigma", sigma, "x1", x1, "m2", m2, NULL);
}
4 changes: 2 additions & 2 deletions vips/convolution.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
#include <stdlib.h>
#include <vips/vips.h>


int gaussian_blur_image(VipsImage *in, VipsImage **out, double sigma);
int sharpen_image(VipsImage *in, VipsImage **out, double sigma, double x1, double m2);
int sharpen_image(VipsImage *in, VipsImage **out, double sigma, double x1,
double m2);
19 changes: 11 additions & 8 deletions vips/create.c
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
// clang-format off
// include order matters
#include "lang.h"
#include "create.h"
// clang-format on

// https://libvips.github.io/libvips/API/current/libvips-create.html#vips-xyz
int xyz(VipsImage **out, int width, int height){
return vips_xyz(out, width, height, NULL);
int xyz(VipsImage **out, int width, int height) {
return vips_xyz(out, width, height, NULL);
}

// http://libvips.github.io/libvips/API/current/libvips-create.html#vips-black
int black(VipsImage **out, int width, int height) {
return vips_black(out, width, height, NULL);
return vips_black(out, width, height, NULL);
}

// https://libvips.github.io/libvips/API/current/libvips-create.html#vips-identity
int identity(VipsImage **out, int ushort) {
if (ushort > 0){
return vips_identity(out, "ushort", TRUE, NULL);
} else {
return vips_identity(out, NULL);
}
if (ushort > 0) {
return vips_identity(out, "ushort", TRUE, NULL);
} else {
return vips_identity(out, NULL);
}
}
3 changes: 3 additions & 0 deletions vips/create.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// https://libvips.github.io/libvips/API/current/libvips-create.html

// clang-format off
// include order matters
#include <stdlib.h>
#include <vips/vips.h>
#include <vips/foreign.h>
// clang-format on

int xyz(VipsImage **out, int width, int height);
int black(VipsImage **out, int width, int height);
Expand Down
32 changes: 18 additions & 14 deletions vips/draw.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
#include "draw.h"

#include "conversion.h"

int draw_rect(VipsImage *in, double r, double g, double b, double a, int left, int top, int width, int height, int fill) {
if (is_16bit(in->Type)) {
r = 65535 * r / 255;
g = 65535 * g / 255;
b = 65535 * b / 255;
a = 65535 * a / 255;
}
int draw_rect(VipsImage *in, double r, double g, double b, double a, int left,
int top, int width, int height, int fill) {
if (is_16bit(in->Type)) {
r = 65535 * r / 255;
g = 65535 * g / 255;
b = 65535 * b / 255;
a = 65535 * a / 255;
}

double background[3] = {r, g, b};
double backgroundRGBA[4] = {r, g, b, a};
double background[3] = {r, g, b};
double backgroundRGBA[4] = {r, g, b, a};

if (in->Bands <= 3) {
return vips_draw_rect(in, background, 3, left, top, width, height, "fill", fill, NULL);
} else {
return vips_draw_rect(in, backgroundRGBA, 4, left, top, width, height, "fill", fill, NULL);
}
if (in->Bands <= 3) {
return vips_draw_rect(in, background, 3, left, top, width, height, "fill",
fill, NULL);
} else {
return vips_draw_rect(in, backgroundRGBA, 4, left, top, width, height,
"fill", fill, NULL);
}
}
3 changes: 2 additions & 1 deletion vips/draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
#include <stdlib.h>
#include <vips/vips.h>

int draw_rect(VipsImage *in, double r, double g, double b, double a, int left, int top, int width, int height, int fill);
int draw_rect(VipsImage *in, double r, double g, double b, double a, int left,
int top, int width, int height, int fill);
27 changes: 11 additions & 16 deletions vips/govips.c
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
#include "govips.h"

static void govips_logging_handler(
const gchar *log_domain, GLogLevelFlags log_level,
const gchar *message, gpointer user_data)
{
static void govips_logging_handler(const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message, gpointer user_data) {
govipsLoggingHandler((char *)log_domain, (int)log_level, (char *)message);
}

static void null_logging_handler(
const gchar *log_domain, GLogLevelFlags log_level,
const gchar *message, gpointer user_data)
{
}
static void null_logging_handler(const gchar *log_domain,
GLogLevelFlags log_level, const gchar *message,
gpointer user_data) {}

void vips_set_logging_handler(void)
{
void vips_set_logging_handler(void) {
g_log_set_default_handler(govips_logging_handler, NULL);
}

void vips_unset_logging_handler(void)
{
void vips_unset_logging_handler(void) {
g_log_set_default_handler(null_logging_handler, NULL);
}

/* This function skips the Govips logging handler and logs
directly to stdout. To be used only for testing and debugging.
Needed for CI because of a Go macOS bug which doesn't clean cgo callbacks on exit. */
void vips_default_logging_handler(void)
{
Needed for CI because of a Go macOS bug which doesn't clean cgo callbacks on
exit. */
void vips_default_logging_handler(void) {
g_log_set_default_handler(g_log_default_handler, NULL);
}
16 changes: 10 additions & 6 deletions vips/govips.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

// clang-format off
// include order matters
#include <stdlib.h>
#include <glib.h>
#include <vips/vips.h>
// clang-format on

#if (VIPS_MAJOR_VERSION < 8)
error_requires_version_8
Expand All @@ -9,13 +13,13 @@ error_requires_version_8
extern void
govipsLoggingHandler(char *log_domain, int log_level, char *message);

static void govips_logging_handler(
const gchar *log_domain, GLogLevelFlags log_level,
const gchar *message, gpointer user_data);
static void govips_logging_handler(const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message, gpointer user_data);

static void null_logging_handler(
const gchar *log_domain, GLogLevelFlags log_level,
const gchar *message, gpointer user_data);
static void null_logging_handler(const gchar *log_domain,
GLogLevelFlags log_level, const gchar *message,
gpointer user_data);

void vips_set_logging_handler(void);
void vips_unset_logging_handler(void);
Expand Down
Loading

0 comments on commit acd555e

Please sign in to comment.