<commit_before>/* ex: set ts=4 et: */
/*
 * Copyright 2011-2012 <NAME> <<EMAIL>>
 *
 * This program is designed to reduce image file size while preserving approximate
 * visual quality.
 *
 * Specifically, to intelligently perform transformations that reduce file size
 * while preserving visible image quality for casual human use (i.e. web page
 * photo galleries, personal photo collections, etc.)
 *
 * Example use:
 * ./imgmin original.jpg optimized.jpg
 * Read original.jpg and write an optimized version of it to optimized.jpg
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <math.h>
#include <float.h> /* DBL_EPSILON */
#include <wand/MagickWand.h>
#include "imgmin.h"

#ifndef IMGMIN_LIB /* not the Apache mopdule... (we assume cmdline) */
#define IMGMIN_STANDALONE
#endif

/* TODO: this is defined in the ImageMagick header magick/magick-type.h */
#ifndef CompositeChannels
#define CompositeChannels 0x2f
#endif

#ifndef MAX_PATH
#define MAX_PATH 256
#endif

/*
 * The most important threshold and the crux of the algorithm;
 * the amount of mean pixel change we're willing to accept.
 * conservative=0.5 safe=0.75 sweetspot=1.00 toohigh=1.25
 */
#define ERROR_THRESHOLD                 1.00
#define ERROR_THRESHOLD_CONSERVATIVE    0.75
#define ERROR_THRESHOLD_SAFE            0.50

#define xstr(s) str(s)
#define str(s) #s

/*
 * secondary check that prevents the total number of colors from changing
 * beyond a certain percent. helpful in a small number of cases.
 */
#define COLOR_DENSITY_RATIO        0.11

/*
 * if an image has fewer colors than this, leave it untouched.
 * low-color images like gradients, line-drawings, etc. produce unacceptable
 * artifacts that are currently undetectable
 */
#define MIN_UNIQUE_COLORS       4096

/*
 * default possible output quality range
 * QUALITY_OUT_MAX: maximum=100 conservative=95 aggressive=85
 * QUALITY_OUT_MIN: maximum=100 conservative=70 aggressive=50
 * override: --quality-out-max N
 *           --quality-out-min N
 */
#define QUALITY_OUT_MAX           95
#define QUALITY_OUT_MIN           70

/*
 * if input image quality is already lower than this, assume it has been
 * optimized already and leave it unchanged.
 * this prevents multiple invocations from degrading an image to quality=0
 *
 * override via: --quality-in-min N
 */
#define QUALITY_IN_MIN            82

/*
 * never perform more than this many steps.
 * each step transforms the entire image and whose cost is based on the size<commit_msg>Lower default quality range<commit_after>/* ex: set ts=4 et: */
/*
 * Copyright 2011-2012 <NAME> <<EMAIL>>
 *
 * This program is designed to reduce image file size while preserving approximate
 * visual quality.
 *
 * Specifically, to intelligently perform transformations that reduce file size
 * while preserving visible image quality for casual human use (i.e. web page
 * photo galleries, personal photo collections, etc.)
 *
 * Example use:
 * ./imgmin original.jpg optimized.jpg
 * Read original.jpg and write an optimized version of it to optimized.jpg
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <math.h>
#include <float.h> /* DBL_EPSILON */
#include <wand/MagickWand.h>
#include "imgmin.h"

#ifndef IMGMIN_LIB /* not the Apache mopdule... (we assume cmdline) */
#define IMGMIN_STANDALONE
#endif

/* TODO: this is defined in the ImageMagick header magick/magick-type.h */
#ifndef CompositeChannels
#define CompositeChannels 0x2f
#endif

#ifndef MAX_PATH
#define MAX_PATH 256
#endif

/*
 * The most important threshold and the crux of the algorithm;
 * the amount of mean pixel change we're willing to accept.
 * conservative=0.5 safe=0.75 sweetspot=1.00 toohigh=1.25
 */
#define ERROR_THRESHOLD                 1.00
#define ERROR_THRESHOLD_CONSERVATIVE    0.75
#define ERROR_THRESHOLD_SAFE            0.50

#define xstr(s) str(s)
#define str(s) #s

/*
 * secondary check that prevents the total number of colors from changing
 * beyond a certain percent. helpful in a small number of cases.
 */
#define COLOR_DENSITY_RATIO        0.11

/*
 * if an image has fewer colors than this, leave it untouched.
 * low-color images like gradients, line-drawings, etc. produce unacceptable
 * artifacts that are currently undetectable
 */
#define MIN_UNIQUE_COLORS       4096

/*
 * default possible output quality range
 * QUALITY_OUT_MAX: maximum=100 conservative=95 aggressive=85
 * QUALITY_OUT_MIN: maximum=100 conservative=70 aggressive=50
 * override: --quality-out-max N
 *           --quality-out-min N
 */
#define QUALITY_OUT_MAX           92
#define QUALITY_OUT_MIN           60

/*
 * if input image quality is already lower than this, assume it has been
 * optimized already and leave it unchanged.
 * this prevents multiple invocations from degrading an image to quality=0
 *
 * override via: --quality-in-min N
 */
#define QUALITY_IN_MIN            82

/*
 * never perform more than this many steps.
 * each step transforms the entire image and whose cost is based on the size
{'fraction_non_alphanumeric': 0.0920550038197097, 'fraction_numerical': 0.023682200152788387, 'mean_word_length': 3.6181657848324513, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '597621', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1587, 'n_words': 594}