Skip to content

Commit

Permalink
0.20231026: SHRIS: add ScaleNX
Browse files Browse the repository at this point in the history
  • Loading branch information
zvezdochiot committed Oct 26, 2023
1 parent 27c4463 commit c03843f
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CC = gcc
CPP = g++
CFLAGS = -DUNIX -I$(SRCS) -Wall -s
VER = 0
VERB = 20230809
VERB = 20231026
ifeq ($(OS),Windows_NT)
LIBS = FreeImage.lib
PLIBF = $(PNAME).$(VER).dll
Expand Down
4 changes: 4 additions & 0 deletions doc/imthreshold/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.20231026

SHRIS: ScaleNX

0.20230809

Size: Crop/Extent
Expand Down
2 changes: 1 addition & 1 deletion doc/imthreshold/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.20230809
0.20231026
1 change: 1 addition & 0 deletions man/man1/imthreshold-shris.1
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ imthreshold-shris [options] <input_file> <output_file>
name filter:
'hris' (default)
'gsample'
'scalenx'
'iris'
'frp' (long!)
.TP
Expand Down
3 changes: 3 additions & 0 deletions src/imthreshold.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ IMTpixel IMTset (BYTE, BYTE, BYTE);
IMTpixel IMTcalcS (IMTpixel);
IMTpixel IMTccorS (IMTpixel);
bool IMTequal (IMTpixel, IMTpixel);
IMTpixel IMTcopy (IMTpixel);
IMTpixel IMTnear (IMTpixel, IMTpixel, IMTpixel);
IMTpixel** IMTalloc (unsigned, unsigned);
void IMTfree (IMTpixel**, unsigned);
BYTE** BWalloc (unsigned, unsigned);
Expand Down Expand Up @@ -231,6 +233,7 @@ void IMTFilterSHRIS (IMTpixel**, IMTpixel**, unsigned, unsigned, int);
void IMTFilterSGSampleUp (IMTpixel**, IMTpixel**, unsigned, unsigned, int);
void IMTFilterSReduce (IMTpixel**, IMTpixel**, unsigned, unsigned, unsigned);
void IMTFilterSNearest (IMTpixel**, IMTpixel**, unsigned, unsigned, unsigned, unsigned);
void IMTFilterSScaleNX (IMTpixel**, IMTpixel**, unsigned int, unsigned int, int);
void IMTFilterSFRP (IMTpixel** p_im, IMTpixel** d_im, unsigned height, unsigned width, int smode);
int IMTFilterThreshold (IMTpixel**, BYTE**, unsigned, unsigned, int);
int IMTFilterThresholdLayer (IMTpixel**, WORD**, BYTE**, unsigned, unsigned);
Expand Down
32 changes: 28 additions & 4 deletions src/lib/commom.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,33 @@ bool IMTequal (IMTpixel im, IMTpixel imc)

////////////////////////////////////////////////////////////////////////////////

IMTpixel IMTcopy (IMTpixel im)
{
return (IMTset(im.c[0], im.c[1], im.c[2]));
}

////////////////////////////////////////////////////////////////////////////////

IMTpixel IMTnear (IMTpixel p0, IMTpixel p1, IMTpixel p2)
{
int d0, d1, d2;
IMTpixel p;

d0 = IMTdist (p1, p2);
d1 = IMTdist (p0, p1);
d2 = IMTdist (p0, p2);
if (d2 < d1)
{
d1 = d2;
p1 = p2;
}
p = (d1 < d0) ? p0 : p1;

return p;
}

////////////////////////////////////////////////////////////////////////////////

IMTpixel IMTRGBtoRYB4 (IMTpixel pim, int direct)
{
int R, G, B, r, y, b;
Expand Down Expand Up @@ -600,10 +627,7 @@ unsigned IMTdist (IMTpixel IMTim0, IMTpixel IMTim1)
{
imd = (int)IMTim0.c[d];
imd -= (int)IMTim1.c[d];
if (imd < 0)
{
imd = -imd;
}
imd = (imd < 0) ? -imd : imd;
imds += imd;
}

Expand Down
131 changes: 123 additions & 8 deletions src/lib/size.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,128 @@ void IMTFilterSize (IMTpixel** p_im, IMTpixel** d_im, int scaler, unsigned heigh

////////////////////////////////////////////////////////////////////////////////

void IMTFilterSScaleNX (IMTpixel** p_im, IMTpixel** d_im, unsigned int height, unsigned int width, int smode)
{
unsigned int y, x, y0, x0, y1, x1, y2, x2;
IMTpixel pA, pB, pC, pD, pE, pF, pG, pH, pI;
IMTpixel pBH, pDF;
IMTpixel pEA, pEC, pEG, pEI;
IMTpixel rA, rB, rC, rD, rE, rF, rG, rH, rI;

smode = (smode < 2) ? 2 : (smode > 3) ? 3 : smode;

if (smode == 2)
{
for (y = 0; y < height; y++)
{
y0 = (y > 0) ? (y - 1) : 0;
y1 = y + 1;
y1 = (y1 < height) ? y1 : (height - 1);
y2 = y + y;
for (x = 0; x < width; x++)
{
x0 = (x > 0) ? (x - 1) : 0;
x1 = x + 1;
x1 = (x1 < width) ? x1 : (width - 1);
x2 = x + x;

pB = p_im[y0][x];
pD = p_im[y][x0];
pE = p_im[y][x];
pF = p_im[y][x1];
pH = p_im[y1][x];

rA = IMTcopy(pE);
rB = IMTcopy(pE);
rC = IMTcopy(pE);
rD = IMTcopy(pE);
pBH = IMTnear(pE, pB, pH);
pDF = IMTnear(pE, pD, pF);
if (IMTequal(pBH, pE) && IMTequal(pDF, pE))
{
rA = IMTnear(pE, pB, pD);
rB = IMTnear(pE, pB, pF);
rC = IMTnear(pE, pH, pD);
rD = IMTnear(pE, pH, pF);
}
d_im[y2 + 0][x2 + 0] = rA;
d_im[y2 + 0][x2 + 1] = rB;
d_im[y2 + 1][x2 + 0] = rC;
d_im[y2 + 1][x2 + 1] = rD;
}
}
}
else
{
for (y = 0; y < height; y++)
{
y0 = (y > 0) ? (y - 1) : 0;
y1 = y + 1;
y1 = (y1 < height) ? y1 : (height - 1);
y2 = y + y + y;
for (x = 0; x < width; x++)
{
x0 = (x > 0) ? (x - 1) : 0;
x1 = x + 1;
x1 = (x1 < width) ? x1 : (width - 1);
x2 = x + x + x;

pA = p_im[y0][x0];
pB = p_im[y0][x];
pC = p_im[y0][x1];
pD = p_im[y][x0];
pE = p_im[y][x];
pF = p_im[y][x1];
pG = p_im[y1][x0];
pH = p_im[y1][x];
pI = p_im[y1][x1];

rA = IMTcopy(pE);
rB = IMTcopy(pE);
rC = IMTcopy(pE);
rD = IMTcopy(pE);
rE = IMTcopy(pE);
rF = IMTcopy(pE);
rG = IMTcopy(pE);
rH = IMTcopy(pE);
rI = IMTcopy(pE);
pBH = IMTnear(pE, pB, pH);
pDF = IMTnear(pE, pD, pF);
if (IMTequal(pBH, pE) && IMTequal(pDF, pE))
{
rA = IMTnear(pE, pB, pD);
rC = IMTnear(pE, pB, pF);
rG = IMTnear(pE, pD, pH);
rI = IMTnear(pE, pF, pH);

pEA = IMTnear(rA, pE, pA);
pEC = IMTnear(rC, pE, pC);
pEG = IMTnear(rG, pE, pG);
pEI = IMTnear(rI, pE, pI);

rB = IMTnear(pE, pEA, pEC);
rD = IMTnear(pE, pEA, pEG);
rF = IMTnear(pE, pEC, pEI);
rH = IMTnear(pE, pEG, pEI);
}


d_im[y2 + 0][x2 + 0] = rA;
d_im[y2 + 0][x2 + 1] = rB;
d_im[y2 + 0][x2 + 2] = rC;
d_im[y2 + 1][x2 + 0] = rD;
d_im[y2 + 1][x2 + 1] = rE;
d_im[y2 + 1][x2 + 2] = rF;
d_im[y2 + 2][x2 + 0] = rG;
d_im[y2 + 2][x2 + 1] = rH;
d_im[y2 + 2][x2 + 2] = rI;
}
}
}
}

////////////////////////////////////////////////////////////////////////////////

int IMTFilterSBWMag2 (BYTE** d_im, BYTE** r_im, unsigned height, unsigned width, unsigned height2, unsigned width2)
{
unsigned y, x, y1, x1, y2, x2, n, s, threshold = 0;
Expand Down Expand Up @@ -799,14 +921,7 @@ void IMTFilterSHRIS (IMTpixel** p_im, IMTpixel** d_im, unsigned height, unsigned
float k1[3];
float k2[3];

if (smode < 2)
{
smode = 2;
}
if (smode > 3)
{
smode = 3;
}
smode = (smode < 2) ? 2 : (smode > 3) ? 3 : smode;

if (smode == 2)
{
Expand Down
6 changes: 6 additions & 0 deletions src/shris.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void ImthresholdFilterSHRISUsage()
printf(" -f str name filter:\n");
printf(" 'hris' (default)\n");
printf(" 'gsample'\n");
printf(" 'scalenx'\n");
printf(" 'iris'\n");
printf(" 'frp' (long!)\n");
printf(" -m mode (int, optional, default = 2, {2,3})\n");
Expand Down Expand Up @@ -177,6 +178,11 @@ int main(int argc, char *argv[])
printf("Scale= Up %s\n", namefilter);
IMTFilterSGSampleUp(p_im, d_im, height, width, smode);
}
else if (strcmp(namefilter, "scalenx") == 0)
{
printf("Scale= Up %s\n", namefilter);
IMTFilterSScaleNX(p_im, d_im, height, width, smode);
}
else if (strcmp(namefilter, "frp") == 0)
{
printf("Scale= Up %s\n", namefilter);
Expand Down

0 comments on commit c03843f

Please sign in to comment.