From 70f77dbdf65cb1cfe9a3fabbd632c708126062e6 Mon Sep 17 00:00:00 2001 From: zvezdochiot Date: Fri, 18 Dec 2020 11:29:02 +0300 Subject: [PATCH] 1.02: fix allocator, @sandsmark --- Makefile | 14 ++-- README.md | 3 +- icon.ico | Bin man/man1/jpeg2png.1 | 62 ++++++++++++++++++ box.c => src/box.c | 0 box.h => src/box.h | 0 compute.c => src/compute.c | 5 +- compute.h => src/compute.h | 0 .../compute_simd_step.c | 0 fp_exceptions.c => src/fp_exceptions.c | 0 fp_exceptions.h => src/fp_exceptions.h | 0 {gopt => src/gopt}/gopt-usage.c | 0 {gopt => src/gopt}/gopt.c | 0 {gopt => src/gopt}/gopt.h | 0 jpeg.c => src/jpeg.c | 0 jpeg.h => src/jpeg.h | 0 jpeg2png.c => src/jpeg2png.c | 0 jpeg2png.h => src/jpeg2png.h | 0 logger.c => src/logger.c | 0 logger.h => src/logger.h | 0 {ooura => src/ooura}/dct.c | 0 {ooura => src/ooura}/dct.h | 0 png.c => src/png.c | 0 png.h => src/png.h | 0 progressbar.c => src/progressbar.c | 0 progressbar.h => src/progressbar.h | 0 utils.c => src/utils.c | 0 utils.h => src/utils.h | 5 +- 28 files changed, 82 insertions(+), 7 deletions(-) mode change 100755 => 100644 icon.ico create mode 100644 man/man1/jpeg2png.1 rename box.c => src/box.c (100%) rename box.h => src/box.h (100%) rename compute.c => src/compute.c (99%) rename compute.h => src/compute.h (100%) rename compute_simd_step.c => src/compute_simd_step.c (100%) rename fp_exceptions.c => src/fp_exceptions.c (100%) rename fp_exceptions.h => src/fp_exceptions.h (100%) rename {gopt => src/gopt}/gopt-usage.c (100%) rename {gopt => src/gopt}/gopt.c (100%) rename {gopt => src/gopt}/gopt.h (100%) rename jpeg.c => src/jpeg.c (100%) rename jpeg.h => src/jpeg.h (100%) rename jpeg2png.c => src/jpeg2png.c (100%) rename jpeg2png.h => src/jpeg2png.h (100%) rename logger.c => src/logger.c (100%) rename logger.h => src/logger.h (100%) rename {ooura => src/ooura}/dct.c (100%) rename {ooura => src/ooura}/dct.h (100%) rename png.c => src/png.c (100%) rename png.h => src/png.h (100%) rename progressbar.c => src/progressbar.c (100%) rename progressbar.h => src/progressbar.h (100%) rename utils.c => src/utils.c (100%) rename utils.h => src/utils.h (95%) diff --git a/Makefile b/Makefile index 5468312..6bf3f1a 100644 --- a/Makefile +++ b/Makefile @@ -18,11 +18,14 @@ SAVE_ASM=0 WINDOWS=0 # VARIABLES +PNAME=jpeg2png CFLAGS+=-std=c11 -pedantic CFLAGS+=-msse2 -mfpmath=sse CFLAGS+=-g WARN_FLAGS+=-Wall -Wextra -Winline -Wshadow NO_WARN_FLAGS+=-w +SRCS=src +RM=rm -f ifeq ($(CC),) CC=$(HOST)gcc endif @@ -30,7 +33,7 @@ ifeq ($(WINDRES),) WINDRES=$(HOST)windres endif LIBS+=-ljpeg -lpng -lm -lz -OBJS+=jpeg2png.o utils.o jpeg.o png.o box.o compute.o logger.o progressbar.o fp_exceptions.o gopt/gopt.o ooura/dct.o +OBJS+=$(SRCS)/jpeg2png.o $(SRCS)/utils.o $(SRCS)/jpeg.o $(SRCS)/png.o $(SRCS)/box.o $(SRCS)/compute.o $(SRCS)/logger.o $(SRCS)/progressbar.o $(SRCS)/fp_exceptions.o $(SRCS)/gopt/gopt.o $(SRCS)/ooura/dct.o HOST= EXE= @@ -68,6 +71,8 @@ EXE=.exe LDFLAGS+=-static -s CFLAGS+=-mstackrealign # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48659 RES+=icon.rc.o +else +CFLAGS+=-D_POSIX_C_SOURCE=200112 endif ifeq ($(SAVE_ASM),1) @@ -81,21 +86,22 @@ LDFLAGS+=$(BFLAGS) .PHONY: clean all install uninstall all: jpeg2png$(EXE) -jpeg2png$(EXE): $(OBJS) $(RES) Makefile +$(PNAME)$(EXE): $(OBJS) $(RES) $(CC) $(OBJS) $(RES) -o $@ $(LDFLAGS) $(LIBS) -include $(OBJS:.o=.d) -gopt/gopt.o: gopt/gopt.c gopt/gopt.h Makefile +$(SRCS)/gopt/gopt.o: $(SRCS)/gopt/gopt.c $(SRCS)/gopt/gopt.h $(CC) $< -c -o $@ $(CFLAGS) $(NO_WARN_FLAGS) -%.o: %.c Makefile +$(SRCS)/%.o: $(SRCS)/%.c $(CC) -MP -MMD $< -c -o $@ $(CFLAGS) $(WARN_FLAGS) %.rc.o: %.rc Makefile $(WINDRES) $< $@ clean: + $(RM) $(OBJS) $(PNAME)$(EXE) git clean -Xf install: all diff --git a/README.md b/README.md index 5e3388a..af38474 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,8 @@ This is the source for the DCT deviations model. Uniform distribution for the er ## Links -[qjpegrest](http://viric.name/soft/qjpegrest/) is a tool that lets you try many different JPEG restoration methods (TV based, band-pass based and Huber MRF based). I learned from the code. See notes/qjpegrest.txt for installation help. +* [qjpegrest](http://viric.name/soft/qjpegrest/) is a tool that lets you try many different JPEG restoration methods (TV based, band-pass based and Huber MRF based). I learned from the code. See notes/qjpegrest.txt for installation help. +* [jpeg-quantsmooth](https://github.com/ilyakurdyukov/jpeg-quantsmooth) is program tries to recreate lost precision of DCT coefficients based on quantization table from jpeg image. ## License diff --git a/icon.ico b/icon.ico old mode 100755 new mode 100644 diff --git a/man/man1/jpeg2png.1 b/man/man1/jpeg2png.1 new file mode 100644 index 0000000..0db31d1 --- /dev/null +++ b/man/man1/jpeg2png.1 @@ -0,0 +1,62 @@ +.TH "Jpeg2Png User Manual" 1 "1 Jul 2015" "Jpeg2Png documentation" + +.SH NAME +jpeg2png + +.SH DESCRIPTION +Silky smooth JPEG decoding + +.SH SYNOPSIS +jpeg2png picture.jpg ... [-o picture.png] ... [flags...] + +.SH OPTIONS +.TP +-o|--output picture.png +picture.png is the file name of the output filethe output file will be overwritten if this flag is used must be specified either zero times or once for every input file default value: original file name with the extension .png +.TP +-f|--force +overwrite output files even when not given explicit file names +.TP +-w|--second-order-weight weight[,weight_cb,weight_cr] +weight is a floating point number for TGV weight alpha_1 higher values give smoother transitions with less staircasing a value of 1.0 means equivalent weight to the first order weight a value of 0.0 means plain Total Variation, and gives a speed boost weights for the chroma components always default to 0. default value: 0.3 +.TP +-p|--probability-weight pweight[,pweight_cb,pweight_cr] +pweight is a floating point number for DCT coefficient distance weight higher values make the result more similar to the source JPEG a value of 1.0 means about equivalent weight to the first order weight a value of 0.0 means to ignore this and gives a speed boost weights for the chroma components default to the luma weight, default value: 0.001 +.TP +-i|--iterations iterations[,iterations_cb,iterations_cr] +iterations is an integer for the number of optimization steps higher values give better results but take more time iterations for the chroma components default to the luma iterations, default value: 50 +.TP +-q|--quiet +don't show the progress bar +.TP +-s|--separate-components +separately optimize components this is faster and makes multithreading more effective however the edges of different components can be different +.TP +-t|--threads threads +threads is a positive integer for the maximum number of threads used equivalent to setting the environment variable OMP_NUM_THREADS, default: number of CPUs +.TP +-1|--16-bits-png +output PNG with 16 bits color depth instead of the usual 8 bits you should use a high number of iterations when using this option +.TP +-c|--csv_log csv_log +csv_log is a file name for the optimization log, default: none +.TP +-h|--help +display this help text and exit +.TP +-V|--version +display version information and exit + +.SH EXAMPLE +jpeg2png -o sample.png sample.jpg + +.SH COPYRIGHT +Copyright 2015 victorvde. + All rights reserved. + +.SH SEE ALSO + imagemagick(1) + +.SH CONTACTS + Website: https://github.com/victorvde/jpeg2png + Autors: victorvde diff --git a/box.c b/src/box.c similarity index 100% rename from box.c rename to src/box.c diff --git a/box.h b/src/box.h similarity index 100% rename from box.h rename to src/box.h diff --git a/compute.c b/src/compute.c similarity index 99% rename from compute.c rename to src/compute.c index a3d6e47..f735cf2 100644 --- a/compute.c +++ b/src/compute.c @@ -12,7 +12,10 @@ #include "ooura/dct.h" -static_assert(FLT_EVAL_METHOD == 0, "to preserve identical output please disable excess precision"); +#if defined __USE_ISOC11 + static_assert(FLT_EVAL_METHOD == 0, "to preserve identical output please disable excess precision"); +#endif + #ifdef PRAGMA_FP_CONTRACT #pragma STDC FP_CONTRACT OFF #endif diff --git a/compute.h b/src/compute.h similarity index 100% rename from compute.h rename to src/compute.h diff --git a/compute_simd_step.c b/src/compute_simd_step.c similarity index 100% rename from compute_simd_step.c rename to src/compute_simd_step.c diff --git a/fp_exceptions.c b/src/fp_exceptions.c similarity index 100% rename from fp_exceptions.c rename to src/fp_exceptions.c diff --git a/fp_exceptions.h b/src/fp_exceptions.h similarity index 100% rename from fp_exceptions.h rename to src/fp_exceptions.h diff --git a/gopt/gopt-usage.c b/src/gopt/gopt-usage.c similarity index 100% rename from gopt/gopt-usage.c rename to src/gopt/gopt-usage.c diff --git a/gopt/gopt.c b/src/gopt/gopt.c similarity index 100% rename from gopt/gopt.c rename to src/gopt/gopt.c diff --git a/gopt/gopt.h b/src/gopt/gopt.h similarity index 100% rename from gopt/gopt.h rename to src/gopt/gopt.h diff --git a/jpeg.c b/src/jpeg.c similarity index 100% rename from jpeg.c rename to src/jpeg.c diff --git a/jpeg.h b/src/jpeg.h similarity index 100% rename from jpeg.h rename to src/jpeg.h diff --git a/jpeg2png.c b/src/jpeg2png.c similarity index 100% rename from jpeg2png.c rename to src/jpeg2png.c diff --git a/jpeg2png.h b/src/jpeg2png.h similarity index 100% rename from jpeg2png.h rename to src/jpeg2png.h diff --git a/logger.c b/src/logger.c similarity index 100% rename from logger.c rename to src/logger.c diff --git a/logger.h b/src/logger.h similarity index 100% rename from logger.h rename to src/logger.h diff --git a/ooura/dct.c b/src/ooura/dct.c similarity index 100% rename from ooura/dct.c rename to src/ooura/dct.c diff --git a/ooura/dct.h b/src/ooura/dct.h similarity index 100% rename from ooura/dct.h rename to src/ooura/dct.h diff --git a/png.c b/src/png.c similarity index 100% rename from png.c rename to src/png.c diff --git a/png.h b/src/png.h similarity index 100% rename from png.h rename to src/png.h diff --git a/progressbar.c b/src/progressbar.c similarity index 100% rename from progressbar.c rename to src/progressbar.c diff --git a/progressbar.h b/src/progressbar.h similarity index 100% rename from progressbar.h rename to src/progressbar.h diff --git a/utils.c b/src/utils.c similarity index 100% rename from utils.c rename to src/utils.c diff --git a/utils.h b/src/utils.h similarity index 95% rename from utils.h rename to src/utils.h index 2116fef..abb6c94 100644 --- a/utils.h +++ b/src/utils.h @@ -90,7 +90,10 @@ static inline void *alloc_simd(size_t n) { #if defined(_WIN32) void *p = _aligned_malloc(n, 16); #else - void *p = aligned_alloc(16, n); + void *p = NULL; + if (posix_memalign(&p, 16, n) != 0) { + die("aligned allocation error"); + } #endif if(!p) { die("allocation error"); } ASSUME_ALIGNED(p);