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

Pull request Issue #35 nanosleep #46

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ Makefile
bin/
cmake_install.cmake
*.gif
.vscode
25 changes: 19 additions & 6 deletions src/catimg.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "sh_image.h"
#include "sh_utils.h"
#include <unistd.h>
Expand All @@ -19,7 +20,6 @@

// Transparency threshold -- all pixels with alpha below 25%.
#define TRANSP_ALPHA 64

extern char *optarg;
extern int optind;
extern int optopt;
Expand All @@ -35,6 +35,14 @@ void intHandler() {
stop = 1;
}

/**
* struct which is passed into nanosleep.
* See Issue # 35 */
struct timespec {
zakgilbert marked this conversation as resolved.
Show resolved Hide resolved
time_t tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
};

int getopt(int argc, char * const argv[], const char *optstring);

uint32_t pixelToInt(const color_t *pixel) {
Expand Down Expand Up @@ -65,8 +73,10 @@ int main(int argc, char *argv[])
char *file;
char *num;
int c;
struct timespec req;

req.tv_sec = 0;
opterr = 0;

uint32_t cols = 0, precision = 0;
uint8_t convert = 0;
uint8_t true_color = 1;
Expand Down Expand Up @@ -139,10 +149,13 @@ int main(int argc, char *argv[])
uint32_t offset = 0;
for (uint32_t frame = 0; frame < img.frames; frame++) {
if (frame > 0 || loop > 0) {
if (frame > 0)
usleep(img.delays[frame - 1] * 10000);
else
usleep(img.delays[img.frames - 1] * 10000);
if (frame > 0) {
req.tv_nsec = (long)(img.delays[frame - 1] * 1000000L);
nanosleep(&req, (struct timespec *)NULL);
} else {
/* req.tv_nsec = (long)(img.delays[img.frames - 1] * 10000000L);
nanosleep(&req, (struct timespec *)NULL); */
}
printf("\e[u");
}
uint32_t index, x, y;
Expand Down