Skip to content

Commit

Permalink
0.1.1: neat summary
Browse files Browse the repository at this point in the history
  • Loading branch information
zvezdochiot committed Dec 14, 2022
1 parent 92f3938 commit 353fc2e
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 44 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
libsmallfry.

0.1.1

Neat Version:
metric_cor
metric_corsharp
correct:
metric_nhw
2022, zvezdochiot

0.1.0

Expand Version:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RMDIR = @rm -frv
PLIB = lib$(PNAME)
VERSION_MAJOR = 0
VERSION_MINOR = 1
VERSION_RELEASE = 0
VERSION_RELEASE = 1
PREFIX = /usr/local
INCPREFIX = $(PREFIX)/include
LIBPREFIX = $(PREFIX)/lib
Expand Down
2 changes: 1 addition & 1 deletion smallfry.pc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ includedir=${prefix}/include

Name: smallfry
Description: Library Smallfry metric for JPEG Optimization
Version: 0.1.0
Version: 0.1.1
Libs: -L${libdir} -lsmallfry -lm
Cflags: -I${includedir}
133 changes: 91 additions & 42 deletions src/smallfry.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,22 +188,26 @@ float metric_sharpenbad (uint8_t *inbuf, uint8_t *outbuf, int width, int height)
uint8_t *old, *new;
float sharpenbad, exp1n, k332, k255p;
float im1, im2, imf1, imf2, ims1, ims2, imd, imd1, imd2, imdc;
float sumd, sumd1, sumd2, sumdc;
float sumd, sumd1, sumd2, sumdc, sumdl, sumd1l, sumd2l, sumdcl;
int i, j, i0, j0, i1, j1, i2, j2, k, ki0, ki, kj, n;

old = inbuf;
new = outbuf;
sumd = 0.0;
sumd1 = 0.0f;
sumd2 = 0.0f;
sumdc = 0.0f;
exp1n = exp(-1);
k332 = (3.0f * 3.0f * 2.0f + 1.0f) / (3.0f * 3.0f * 2.0f - 1.0f);
k255p = 1.0f / 255.0f;

k = 0;
sumd = 0.0f;
sumd1 = 0.0f;
sumd2 = 0.0f;
sumdc = 0.0f;
for (i = 0; i < height; i++)
{
sumdl = 0.0f;
sumd1l = 0.0f;
sumd2l = 0.0f;
sumdcl = 0.0f;
i0 = i - 1;
if (i0 < 0) {i0 = 0;}
i2 = i + 2;
Expand Down Expand Up @@ -248,12 +252,16 @@ float metric_sharpenbad (uint8_t *inbuf, uint8_t *outbuf, int width, int height)
imdc = imd1 * imd2;
imd1 *= imd1;
imd2 *= imd2;
sumd += imd;
sumd1 += imd1;
sumd2 += imd2;
sumdc += imdc;
sumdl += imd;
sumd1l += imd1;
sumd2l += imd2;
sumdcl += imdc;
k++;
}
sumd += sumdl;
sumd1 += sumd1l;
sumd2 += sumd2l;
sumdc += sumdcl;
}
sumd2 *= sumd1;
if (sumd2 > 0.0f)
Expand All @@ -280,37 +288,58 @@ float metric_cor (uint8_t *inbuf, uint8_t *outbuf, int width, int height)
{
uint8_t *old, *new;
float im1, im2;
float sum1, sum2, sum12, sumq1, sumq2, sumq, cor;
int k, n;
float sum1, sum2, sum1l, sum2l;
float sum12, sumq1, sumq2, sum12l, sumq1l, sumq2l, sumq, cor;
int i, j, k, n;

old = inbuf;
new = outbuf;
n = width * height;

sum1 = 0;
sum2 = 0;
for (k = 0; k < n; k++)
k = 0;
sum1 = 0.0f;
sum2 = 0.0f;
for (i = 0; i < height; i++)
{
im1 = (float)old[k];
im2 = (float)new[k];
sum1 += im1;
sum2 += im2;
sum1l = 0.0f;
sum2l = 0.0f;
for (j = 0; j < width; j++)
{
im1 = (float)old[k];
im2 = (float)new[k];
sum1l += im1;
sum2l += im2;
k++;
}
sum1 += sum1l;
sum2 += sum2l;
}
sum1 /= (float)n;
sum2 /= (float)n;

k = 0;
sum12 = 0.0f;
sumq1 = 0.0f;
sumq2 = 0.0f;
for (k = 0; k < n; k++)
for (i = 0; i < height; i++)
{
im1 = (float)old[k];
im1 -= sum1;
im2 = (float)new[k];
im2 -= sum2;
sum12 += (im1 * im2);
sumq1 += (im1 * im1);
sumq2 += (im2 * im2);
sum12l = 0.0f;
sumq1l = 0.0f;
sumq2l = 0.0f;
for (j = 0; j < width; j++)
{
im1 = (float)old[k];
im1 -= sum1;
im2 = (float)new[k];
im2 -= sum2;
sum12l += (im1 * im2);
sumq1l += (im1 * im1);
sumq2l += (im2 * im2);
k++;
}
sum12 += sum12l;
sumq1 += sumq1l;
sumq2 += sumq2l;
}
sumq = sqrt(sumq1 * sumq2);
if (sumq > 0.0f)
Expand All @@ -328,22 +357,32 @@ float metric_corsharp (uint8_t *inbuf, uint8_t *outbuf, int width, int height, i
{
uint8_t *old, *new;
float im1, im2, imf1, imf2, ims1, ims2;
float sum1, sum2, sum12, sumq1, sumq2, sumq, cor;
float sum1, sum2, sum1l, sum2l;
float sum12, sumq1, sumq2, sum12l, sumq1l, sumq2l, sumq, cor;
int i, j, i0, j0, i1, j1, i2, j2, k, ki0, ki, kj, n;

old = inbuf;
new = outbuf;
n = width * height;
if (radius < 0) {radius = -radius;}

sum1 = 0;
sum2 = 0;
for (k = 0; k < n; k++)
k = 0;
sum1 = 0.0f;
sum2 = 0.0f;
for (i = 0; i < height; i++)
{
im1 = (float)old[k];
im2 = (float)new[k];
sum1 += im1;
sum2 += im2;
sum1l = 0.0f;
sum2l = 0.0f;
for (j = 0; j < width; j++)
{
im1 = (float)old[k];
im2 = (float)new[k];
sum1l += im1;
sum2l += im2;
k++;
}
sum1 += sum1l;
sum2 += sum2l;
}
sum1 /= (float)n;
sum2 /= (float)n;
Expand All @@ -354,6 +393,9 @@ float metric_corsharp (uint8_t *inbuf, uint8_t *outbuf, int width, int height, i
sumq2 = 0.0f;
for (i = 0; i < height; i++)
{
sum12l = 0.0f;
sumq1l = 0.0f;
sumq2l = 0.0f;
i0 = i - radius;
if (i0 < 0) {i0 = 0;}
i2 = i + radius + 1;
Expand Down Expand Up @@ -392,11 +434,14 @@ float metric_corsharp (uint8_t *inbuf, uint8_t *outbuf, int width, int height, i
im2 *= 2.0f;
im2 -= ims2;
im2 -= sum2;
sum12 += (im1 * im2);
sumq1 += (im1 * im1);
sumq2 += (im2 * im2);
sum12l += (im1 * im2);
sumq1l += (im1 * im1);
sumq2l += (im2 * im2);
k++;
}
sum12 += sum12l;
sumq1 += sumq1l;
sumq2 += sumq2l;
}
sumq = sqrt(sumq1 * sumq2);
if (sumq > 0.0f)
Expand Down Expand Up @@ -461,15 +506,17 @@ float metric_nhw (uint8_t *inbuf, uint8_t *outbuf, int width, int height)
{
uint8_t *old, *new;
int i, j, res, resr, resd, scan, delta;
int significance = 0;
float neatness_amount = 0.0f, neatness;
float amount = 0.0f, significance = 0.0f, neatness;
float amountl = 0.0f, significancel = 0.0f;

old = inbuf;
new = outbuf;

scan = 0;
for (i = 0; i < height; i++)
{
amountl = 0.0f;
significancel = 0.0f;
for (j = 0; j < width; j++)
{
res = pix_sharpen3 (new, width, height, i, j, scan);
Expand All @@ -480,14 +527,16 @@ float metric_nhw (uint8_t *inbuf, uint8_t *outbuf, int width, int height)
delta = abs(new[scan] - old[scan]);
if (delta > 0)
{
neatness_amount += (delta * delta) * resd;
significance += resd;
amountl += (delta * delta) * resd;
}
significancel += resd;
}
scan++;
}
amount += amountl;
significance += significancel;
}
neatness = (float)((significance > 0) ? ((float)(neatness_amount)/(float)(significance)) : 1.0f);
neatness = (significance > 0.0f) ? (amount / significance) : 1.0f;

return neatness;
}

0 comments on commit 353fc2e

Please sign in to comment.