Add svgstat utility
This commit is contained in:
parent
06b5a6d917
commit
8f1dbeeb66
15
Makefile
15
Makefile
|
@ -1,38 +1,46 @@
|
|||
RM := rm -f
|
||||
CFLAGS := -O3 -Wall -Isrc -I/usr/include/ffmpeg
|
||||
LIBS := -lavformat -lavutil -lavcodec -lswscale
|
||||
LIBS := -lavformat -lavutil -lavcodec -lswscale -lrsvg-2
|
||||
LDFLAGS :=
|
||||
INSTALL ?= install
|
||||
PREFIX ?= /usr/local
|
||||
|
||||
COMMON_OBJECTS := build/validation.o build/png.o build/util.o
|
||||
MEDIASTAT_OBJECTS := build/stat.o
|
||||
SVGSTAT_OBJECTS := build/svgstat.o
|
||||
MEDIATHUMB_OBJECTS := build/thumb.o
|
||||
|
||||
# Phony rules
|
||||
.PHONY: all mediastat clean
|
||||
|
||||
all: mediastat mediathumb
|
||||
all: mediastat svgstat mediathumb
|
||||
|
||||
install: all
|
||||
$(INSTALL) build/mediastat $(PREFIX)/bin/mediastat
|
||||
$(INSTALL) build/svgstat $(PREFIX)/bin/svgstat
|
||||
$(INSTALL) build/mediathumb $(PREFIX)/bin/mediathumb
|
||||
|
||||
uninstall:
|
||||
$(RM) -rf $(PREFIX)/bin/mediastat
|
||||
$(RM) -rf $(PREFIX)/bin/svgstat
|
||||
$(RM) -rf $(PREFIX)/bin/mediathumb
|
||||
|
||||
mediastat: build/mediastat
|
||||
|
||||
svgstat: build/svgstat
|
||||
|
||||
mediathumb: build/mediathumb
|
||||
|
||||
clean:
|
||||
$(RM) $(COMMON_OBJECTS) $(MEDIASTAT_OBJECTS)$(MEDIATHUMB_OBJECTS)
|
||||
$(RM) $(COMMON_OBJECTS) $(MEDIASTAT_OBJECTS) $(SVGSTAT_OBJECTS) $(MEDIATHUMB_OBJECTS)
|
||||
|
||||
# Build rules
|
||||
build/mediastat: $(COMMON_OBJECTS) $(MEDIASTAT_OBJECTS)
|
||||
$(CC) $^ $(LDFLAGS) $(LIBS) -o $@
|
||||
|
||||
build/svgstat: $(COMMON_OBJECTS) $(SVGSTAT_OBJECTS)
|
||||
$(CC) $^ $(LDFLAGS) $(LIBS) -o $@
|
||||
|
||||
build/mediathumb: $(COMMON_OBJECTS) $(MEDIATHUMB_OBJECTS)
|
||||
$(CC) $^ $(LDFLAGS) $(LIBS) -o $@
|
||||
|
||||
|
@ -42,3 +50,4 @@ build/%.o: src/%.c
|
|||
# Declare dependencies
|
||||
-include $(COMMON_OBJECTS:.o=.d)
|
||||
-include $(MEDIASTAT_OBJECTS:.o=.d)
|
||||
-include $(SVGSTAT_OBJECTS:.o=.d)
|
||||
|
|
68
src/svgstat.c
Normal file
68
src/svgstat.c
Normal file
|
@ -0,0 +1,68 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "validation.h"
|
||||
#include "util.h"
|
||||
|
||||
typedef struct RsvgHandle RsvgHandle;
|
||||
typedef struct RsvgDimensionData {
|
||||
int width;
|
||||
int height;
|
||||
double em;
|
||||
double ex;
|
||||
} RsvgDimensionData;
|
||||
|
||||
extern RsvgHandle *
|
||||
rsvg_handle_new_from_file(const char *file_name, void **error);
|
||||
|
||||
extern void
|
||||
rsvg_handle_get_dimensions(RsvgHandle *handle, RsvgDimensionData *dimension_data);
|
||||
|
||||
// SVG is a special snowflake format that needs different treatment.
|
||||
//
|
||||
// Other tools will try to actually render the file just to get
|
||||
// the dimensions. librsvg allows getting the dimensions without
|
||||
// rendering, which important because the stat tools should run
|
||||
// quickly.
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
RsvgHandle *handle;
|
||||
RsvgDimensionData dimensions;
|
||||
struct stat statbuf;
|
||||
|
||||
if (argc != 2) {
|
||||
printf("No input specified\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (stat(argv[1], &statbuf) != 0) {
|
||||
printf("Couldn't read file\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
handle = rsvg_handle_new_from_file(argv[1], NULL);
|
||||
if (handle == NULL) {
|
||||
printf("Couldn't read file\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
rsvg_handle_get_dimensions(handle, &dimensions);
|
||||
|
||||
if (dimensions.width < 1 || dimensions.width > 32767) {
|
||||
printf("Invalid width %d\n", dimensions.width);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dimensions.height < 1 || dimensions.height > 32767) {
|
||||
printf("Invalid height %d\n", dimensions.height);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("%ld %lu %d %d %d %d\n", statbuf.st_size, 1ul, dimensions.width, dimensions.height, 1, 25);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue