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

[0.4.x] libvisual: Address some more warnings #375

Merged
merged 10 commits into from
Dec 24, 2024
4 changes: 2 additions & 2 deletions .github/workflows/linux_and_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ jobs:

- name: '[LV] Run "make"'
run: |-
make -C build_lv -j2 VERBOSE=1
make -C build_lv -j2 -k VERBOSE=1

- name: '[LV] Run "make install"'
run: |-
Expand Down Expand Up @@ -185,7 +185,7 @@ jobs:
run: |-
set -x -o pipefail

make -C build_plugins -j2 VERBOSE=1
make -C build_plugins -j2 -k VERBOSE=1

# Detect and deny underlinking
! find -name \*.so | sort | xargs ldd -r | grep -F 'undefined symbol'
Expand Down
2 changes: 1 addition & 1 deletion libvisual/libvisual/gettext.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
On pre-ANSI systems without 'const', the config.h file is supposed to
contain "#define const". */
# define gettext(Msgid) ((const char *) (Msgid))
# define gettext_noop(Msgid) ((const char *) (Msgid))
# define dgettext(Domainname, Msgid) ((const char *) (Msgid))
# define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid))
# define ngettext(Msgid1, Msgid2, N) \
Expand All @@ -68,6 +67,7 @@
and other string expressions won't work.
The macro's expansion is not parenthesized, so that it is suitable as
initializer for static 'char[]' or 'const char[]' variables. */
#undef gettext_noop
#define gettext_noop(String) String

#define N_(String) gettext_noop(String)
Expand Down
57 changes: 1 addition & 56 deletions libvisual/libvisual/lv_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ static int audio_samplepool_dtor (VisObject *object);
static int audio_samplepool_channel_dtor (VisObject *object);
static int audio_sample_dtor (VisObject *object);

static int audio_band_total (VisAudio *audio, int begin, int end);
static int audio_band_energy (VisAudio *audio, int band, int length);

/* Format transform functions */
static int transform_format_buffer_from_float (VisBuffer *dest, VisBuffer *src, int size, int sign);
static int transform_format_buffer_to_float (VisBuffer *dest, VisBuffer *src, int size, int sign);
Expand Down Expand Up @@ -112,34 +109,6 @@ static int audio_sample_dtor (VisObject *object)
}


static int audio_band_total (VisAudio *audio, int begin, int end)
{
int bpmtotal = 0;
int i;

// for (i = begin; i < end; i++)
// bpmtotal += audio->freq[2][i];

if (bpmtotal > 0)
return bpmtotal / (end - begin);
else
return 0;
}

static int audio_band_energy (VisAudio *audio, int band, int length)
{
int energytotal = 0;
int i;

// for (i = 0; i < length; i++)
// energytotal += audio->bpmhistory[i][band];

if (energytotal > 0)
return energytotal / length;
else
return 0;
}

/**
* @defgroup VisAudio VisAudio
* @{
Expand Down Expand Up @@ -311,30 +280,6 @@ int visual_audio_analyze (VisAudio *audio)
}
}

#endif
#if 0
/* BPM stuff, used for the audio energy only right now */
for (i = 1023; i > 0; i--) {
visual_mem_copy (&audio->bpmhistory[i], &audio->bpmhistory[i - 1], 6 * sizeof (short int));
visual_mem_copy (&audio->bpmdata[i], &audio->bpmdata[i - 1], 6 * sizeof (short int));
}

/* Calculate the audio energy */
audio->energy = 0;

for (i = 0; i < 6; i++) {
audio->bpmhistory[0][i] = audio_band_total (audio, i * 2, (i * 2) + 3);
audio->bpmenergy[i] = audio_band_energy (audio, i, 10);

audio->bpmdata[0][i] = audio->bpmhistory[0][i] - audio->bpmenergy[i];

audio->energy += audio_band_energy(audio, i, 50);
}

audio->energy >>= 7;

if (audio->energy > 100)
audio->energy = 100;
#endif

return VISUAL_OK;
Expand Down Expand Up @@ -1108,7 +1053,7 @@ static int transform_format_buffer_from_float (VisBuffer *dest, VisBuffer *src,
int signedcorr;
int i;

signedcorr += byte_max_numeric (size) / 2;
signedcorr = byte_max_numeric (size) / 2;

if (size == 1)
FORMAT_BUFFER_FROM_FLOAT(int8_t, uint8_t)
Expand Down
53 changes: 39 additions & 14 deletions libvisual/libvisual/lv_bmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <string.h>
#include <math.h>
#include <gettext.h>
#include <stdint.h>

#include <sys/stat.h>
#include <fcntl.h>
Expand Down Expand Up @@ -72,7 +73,7 @@ static int load_uncompressed (FILE *fp, VisVideo *video, int depth)
while (data > (uint8_t *) visual_video_get_pixels (video)) {
/* Unpack 4 bpp pixels aka 2 pixels per byte */
uint8_t *col = data - video->pitch;
uint8_t *end = (uint8_t *) ((int)data & ~1);
uint8_t *end = (uint8_t *) ((uintptr_t)data & ~1);
Copy link
Member

@kaixiong kaixiong Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, this is atrocious. This arithmetic trick also depends on the memory alignment of the data pointer to be 8 bytes or more, but this assumption seems to be relatively safe.

data = col;

while (col < end) {
Expand All @@ -93,7 +94,7 @@ static int load_uncompressed (FILE *fp, VisVideo *video, int depth)
while (data > (uint8_t *) visual_video_get_pixels (video)) {
/* Unpack 1 bpp pixels aka 8 pixels per byte */
uint8_t *col = data - video->pitch;
uint8_t *end = (uint8_t *) ((int)data & ~7);
uint8_t *end = (uint8_t *) ((uintptr_t)data & ~7);
data = col;

while (col < end) {
Expand Down Expand Up @@ -282,65 +283,89 @@ int visual_bitmap_load (VisVideo *video, const char *filename)
}

/* Read the magic string */
fread (magic, 2, 1, fp);
if (fread (magic, 2, 1, fp) != 1) {
return -VISUAL_ERROR_BMP_NO_BMP;
}
if (strncmp (magic, "BM", 2) != 0) {
visual_log (VISUAL_LOG_WARNING, _("Not a bitmap file"));
fclose (fp);
return -VISUAL_ERROR_BMP_NO_BMP;
}

/* Read the file size */
fread (&bf_size, 4, 1, fp);
if (fread (&bf_size, 4, 1, fp) != 1) {
return -VISUAL_ERROR_BMP_CORRUPTED;
}
bf_size = VISUAL_ENDIAN_LEI32 (bf_size);

/* Skip past the reserved bits */
fseek (fp, 4, SEEK_CUR);

/* Read the offset bits */
fread (&bf_bits, 4, 1, fp);
if (fread (&bf_bits, 4, 1, fp) != 1) {
return -VISUAL_ERROR_BMP_CORRUPTED;
}
bf_bits = VISUAL_ENDIAN_LEI32 (bf_bits);

/* Read the info structure size */
fread (&bi_size, 4, 1, fp);
if (fread (&bi_size, 4, 1, fp) != 1) {
return -VISUAL_ERROR_BMP_CORRUPTED;
}
bi_size = VISUAL_ENDIAN_LEI32 (bi_size);

if (bi_size == 12) {
/* And read the width, height */
fread (&bi_width, 2, 1, fp);
fread (&bi_height, 2, 1, fp);
if (fread (&bi_width, 2, 1, fp) != 1) {
return -VISUAL_ERROR_BMP_CORRUPTED;
}
if (fread (&bi_height, 2, 1, fp) != 1) {
return -VISUAL_ERROR_BMP_CORRUPTED;
}
bi_width = VISUAL_ENDIAN_LEI16 (bi_width);
bi_height = VISUAL_ENDIAN_LEI16 (bi_height);

/* Skip over the planet */
fseek (fp, 2, SEEK_CUR);

/* Read the bits per pixel */
fread (&bi_bitcount, 2, 1, fp);
if (fread (&bi_bitcount, 2, 1, fp) != 1) {
return -VISUAL_ERROR_BMP_CORRUPTED;
}
bi_bitcount = VISUAL_ENDIAN_LEI16 (bi_bitcount);
bi_compression = BI_RGB;
} else {
/* And read the width, height */
fread (&bi_width, 4, 1, fp);
fread (&bi_height, 4, 1, fp);
if (fread (&bi_width, 4, 1, fp) != 1) {
return -VISUAL_ERROR_BMP_CORRUPTED;
}
if (fread (&bi_height, 4, 1, fp) != 1) {
return -VISUAL_ERROR_BMP_CORRUPTED;
}
bi_width = VISUAL_ENDIAN_LEI32 (bi_width);
bi_height = VISUAL_ENDIAN_LEI32 (bi_height);

/* Skip over the planet */
fseek (fp, 2, SEEK_CUR);

/* Read the bits per pixel */
fread (&bi_bitcount, 2, 1, fp);
if (fread (&bi_bitcount, 2, 1, fp) != 1) {
return -VISUAL_ERROR_BMP_CORRUPTED;
}
bi_bitcount = VISUAL_ENDIAN_LEI16 (bi_bitcount);

/* Read the compression flag */
fread (&bi_compression, 4, 1, fp);
if (fread (&bi_compression, 4, 1, fp) != 1) {
return -VISUAL_ERROR_BMP_CORRUPTED;
}
bi_compression = VISUAL_ENDIAN_LEI32 (bi_compression);

/* Skip over the nonsense we don't want to know */
fseek (fp, 12, SEEK_CUR);

/* Number of colors in palette */
fread (&bi_clrused, 4, 1, fp);
if (fread (&bi_clrused, 4, 1, fp) != 1) {
return -VISUAL_ERROR_BMP_CORRUPTED;
}
bi_clrused = VISUAL_ENDIAN_LEI32 (bi_clrused);

/* Skip over the other nonsense */
Expand Down
24 changes: 0 additions & 24 deletions libvisual/libvisual/lv_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,18 @@ static void *mem_copy_c (void *dest, const void *src, visual_size_t n);
static void *mem_copy_mmx (void *dest, const void *src, visual_size_t n);
static void *mem_copy_mmx2 (void *dest, const void *src, visual_size_t n);
static void *mem_copy_3dnow (void *dest, const void *src, visual_size_t n);
static void *mem_copy_altivec (void *dest, const void *src, visual_size_t n);

static void *mem_set8_c (void *dest, int c, visual_size_t n);
static void *mem_set8_mmx (void *dest, int c, visual_size_t n);
static void *mem_set8_mmx2 (void *dest, int c, visual_size_t n);
static void *mem_set8_altivec (void *dest, int c, visual_size_t n);

static void *mem_set16_c (void *dest, int c, visual_size_t n);
static void *mem_set16_mmx (void *dest, int c, visual_size_t n);
static void *mem_set16_mmx2 (void *dest, int c, visual_size_t n);
static void *mem_set16_altivec (void *dest, int c, visual_size_t n);

static void *mem_set32_c (void *dest, int c, visual_size_t n);
static void *mem_set32_mmx (void *dest, int c, visual_size_t n);
static void *mem_set32_mmx2 (void *dest, int c, visual_size_t n);
static void *mem_set32_altivec (void *dest, int c, visual_size_t n);

/* Optimal performance functions set by visual_mem_initialize(). */
VisMemCopyFunc visual_mem_copy = mem_copy_c;
Expand Down Expand Up @@ -373,11 +369,6 @@ static void *mem_copy_3dnow (void *dest, const void *src, visual_size_t n)
return dest;
}

static void *mem_copy_altivec (void *dest, const void *src, visual_size_t n)
{

}

/* Memset functions, 1 byte memset */
static void *mem_set8_c (void *dest, int c, visual_size_t n)
{
Expand Down Expand Up @@ -523,11 +514,6 @@ static void *mem_set8_mmx2 (void *dest, int c, visual_size_t n)
return dest;
}

static void *mem_set8_altivec (void *dest, int c, visual_size_t n)
{

}

/* Memset functions, 2 byte memset */
static void *mem_set16_c (void *dest, int c, visual_size_t n)
{
Expand Down Expand Up @@ -667,11 +653,6 @@ static void *mem_set16_mmx2 (void *dest, int c, visual_size_t n)
return dest;
}

static void *mem_set16_altivec (void *dest, int c, visual_size_t n)
{

}

/* Memset functions, 4 byte memset */
static void *mem_set32_c (void *dest, int c, visual_size_t n)
{
Expand Down Expand Up @@ -778,11 +759,6 @@ static void *mem_set32_mmx2 (void *dest, int c, visual_size_t n)
return dest;
}

static void *mem_set32_altivec (void *dest, int c, visual_size_t n)
{

}

/**
* @}
*/
Expand Down
6 changes: 3 additions & 3 deletions libvisual/libvisual/lv_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ const char *visual_plugin_get_prev_by_name (VisList *list, const char *name)
static int plugin_add_dir_to_list (VisList *list, const char *dir)
{
VisPluginRef **ref;
char temp[FILENAME_MAX];
char temp[FILENAME_MAX + 1 + FILENAME_MAX + 1];
int i, j, n;
size_t len;
int cnt = 0;
Expand Down Expand Up @@ -562,7 +562,7 @@ static int plugin_add_dir_to_list (VisList *list, const char *dir)

if (!(FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {

snprintf (temp, 1023, "%s\\%s", dir, FileData.cFileName);
snprintf (temp, sizeof (temp), "%s\\%s", dir, FileData.cFileName);

len = strlen (temp);
if (len > 5 && (strncmp (&temp[len - 5], ".dll", 5) == 0))
Expand Down Expand Up @@ -602,7 +602,7 @@ static int plugin_add_dir_to_list (VisList *list, const char *dir)
for (i = 2; i < n; i++) {
ref = NULL;

snprintf (temp, 1023, "%s/%s", dir, namelist[i]->d_name);
snprintf (temp, sizeof (temp), "%s/%s", dir, namelist[i]->d_name);

len = strlen (temp);
if (len > 3 && (strncmp (&temp[len - 3], ".so", 3) == 0))
Expand Down
1 change: 0 additions & 1 deletion libvisual/libvisual/lv_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -1763,7 +1763,6 @@ int visual_video_fill_color_rectangle (VisVideo *video, VisColor *color, VisRect

errret = visual_video_fill_color (&svid, color);

out:
visual_object_unref (VISUAL_OBJECT (&svid));

return errret;
Expand Down
Loading
Loading