Skip to content

Commit

Permalink
4.3.8: Transform: strip code
Browse files Browse the repository at this point in the history
  • Loading branch information
zvezdochiot committed May 6, 2021
1 parent 1db04ee commit ae9cacf
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 97 deletions.
2 changes: 1 addition & 1 deletion src/transform/geoconformal/geoconformal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ GCIparams GeoConformalParams(QImage &img, QString sparams, QString sregion, int

void GeoConformal(QImage &img, GCIparams params)
{
int y, x, yr;
unsigned y, x, yr;
IMTimage imgin, imgout;
if ((params.trans.na < 3) || (params.rect1.n < 4))
return;
Expand Down
60 changes: 20 additions & 40 deletions src/transform/pixart-scaler/pixart_scaler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,62 +9,52 @@

Q_EXPORT_PLUGIN2(pixart-scaler, FilterPlugin);

void (*scaler_scalex_func[3])(uint*,uint*,int,int) = {
scaler_scalex_2x, scaler_scalex_3x, scaler_scalex_4x};

void
FilterPlugin:: filterScaleX(int n/*factor*/)
{
int w = data->image.width();
int h = data->image.height();
void *src = data->image.bits();
QImage dstImg(n*w, n*h, data->image.format());
void *dst = dstImg.bits();
scaler_scalex_func[n-2]((uint*)src, (uint*)dst, w, h);
data->image = dstImg;
emit imageChanged();
}

void (*xbr_filter_func[3])(uint*,uint*,int,int) = {
xbr_filter_xbr2x, xbr_filter_xbr3x, xbr_filter_xbr4x};

void
FilterPlugin:: filterXBR(int n/*factor*/)
void FilterPlugin:: UpcaleX(int method, int n/*factor*/)
{
int w = data->image.width();
int h = data->image.height();
void *src = data->image.bits();
QImage dstImg(n*w, n*h, data->image.format());
void *dst = dstImg.bits();
xbr_filter_func[n-2]((uint*)src, (uint*)dst, w, h);
switch (method)
{
case 0:
scaler_scalex((uint*)src, (uint*)dst, w, h, n);
break;
case 1:
xbr_filter((uint*)src, (uint*)dst, w, h, n);
break;
default:
dstImg = data->image;
break;
}
data->image = dstImg;
emit imageChanged();
}

// **************** RIS Dialog ******************
// **************** Upscale Dialog ******************
UpscaleDialog:: UpscaleDialog(QWidget *parent) : QDialog(parent)
{
this->setWindowTitle(PLUGIN_NAME);
this->resize(320, 158);

QGridLayout *gridLayout = new QGridLayout(this);
gridLayout = new QGridLayout(this);

QLabel *labelMethod = new QLabel("Method :", this);
labelMethod = new QLabel("Method :", this);
gridLayout->addWidget(labelMethod, 0, 0, 1, 1);
comboMethod = new QComboBox(this);
QStringList items = { "ScaleX", "xBr"};
comboMethod->addItems(items);
comboMethod->addItems(itemsMethod);
gridLayout->addWidget(comboMethod, 0, 1, 1, 1);

QLabel *labelMult = new QLabel("Mult :", this);
labelMult = new QLabel("Mult :", this);
gridLayout->addWidget(labelMult, 1, 0, 1, 1);
spinMult = new QSpinBox(this);
spinMult->setAlignment(Qt::AlignCenter);
spinMult->setRange(2,4);
spinMult->setValue(2);
gridLayout->addWidget(spinMult, 1, 1, 1, 1);

QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Horizontal, this);
buttonBox = new QDialogButtonBox(Qt::Horizontal, this);
buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
gridLayout->addWidget(buttonBox, 2, 0, 1, 2);

Expand All @@ -84,16 +74,6 @@ void FilterPlugin:: onMenuClick()
{
int method = dlg->comboMethod->currentIndex();
int mult = dlg->spinMult->value();
switch (method)
{
case 0:
filterScaleX(mult);
break;
case 1:
filterXBR(mult);
break;
default:
break;
}
UpcaleX(method, mult);
}
}
16 changes: 8 additions & 8 deletions src/transform/pixart-scaler/pixart_scaler.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ class FilterPlugin : public QObject, Plugin

public:
QString menuItem();
void filterScaleX(int n);
void filterXBR(int n);
void UpcaleX(int method, int n);

public slots:
void onMenuClick();
Expand All @@ -30,18 +29,19 @@ public slots:
class UpscaleDialog : public QDialog
{
public:
QGridLayout *gridLayout;
QLabel *labelMethod;
QComboBox *comboMethod;
QStringList itemsMethod = { "ScaleX", "xBr"};
QLabel *labelMult;
QSpinBox *spinMult;
QDialogButtonBox *buttonBox;

UpscaleDialog(QWidget *parent);
};

// XBR scaler
void xbr_filter_xbr2x(uint32_t* src, uint32_t *dst, int width, int height);
void xbr_filter_xbr3x(uint32_t* src, uint32_t *dst, int width, int height);
void xbr_filter_xbr4x(uint32_t* src, uint32_t *dst, int width, int height);
void xbr_filter( uint32_t *src, uint32_t *dst, int inWidth, int inHeight, int scaleFactor);

// ScaleX scaler
void scaler_scalex_2x(uint32_t* src, uint32_t *dst, int width, int height);
void scaler_scalex_3x(uint32_t* src, uint32_t *dst, int width, int height);
void scaler_scalex_4x(uint32_t* src, uint32_t *dst, int width, int height);
void scaler_scalex(uint32_t * sp, uint32_t * dp, int Xres, int Yres, int scalefactor);
56 changes: 27 additions & 29 deletions src/transform/pixart-scaler/scaler_scalex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ static const char TRUE = 1;
static const char FALSE = 0;
static const char BYTE_SIZE_RGBA_4BPP = 4; // RGBA 4BPP

void pixel_copy(uint8_t *, uint32_t, uint8_t *, uint32_t,int);
uint8_t pixel_eql(uint8_t *, uint32_t, uint32_t, int);
void scale_scale2x(uint8_t *, uint32_t *, int, int, int, int, int);
void scale_scale3x(uint8_t *, uint32_t *, int, int, int, int, int);
void scale_scale4x(uint8_t *, uint32_t *, int, int, int, int, int);


// Copy a pixel from src to dst
void pixel_copy(uint8_t * dst, uint32_t dpos, uint8_t * src, uint32_t spos, int bpp)
{
Expand All @@ -36,7 +29,6 @@ void pixel_copy(uint8_t * dst, uint32_t dpos, uint8_t * src, uint32_t spos, int
dst[dpos + i] = src[spos + i];
}


// Check if two pixels are equal
// TODO: RGBA Alpha handling, ignore Alpha byte?
uint8_t pixel_eql(uint8_t * src, uint32_t pos0, uint32_t pos1, int bpp)
Expand All @@ -56,14 +48,13 @@ uint8_t pixel_eql(uint8_t * src, uint32_t pos0, uint32_t pos1, int bpp)
// Return adjacent pixel values for given pixel
void scale_scale2x(uint8_t * src, uint32_t * ret_pos, int x, int y, int w, int h, int bpp)
{
int x0, x2;
int y0, y2;
int x0, y0, x2, y2;
uint32_t B, D, E, F, H;

if (x > 0) { x0 = x - 1; } else { x0 = 0; }
if (x < w - 1) { x2 = x + 1; } else { x2 = w - 1; }
if (y > 0) { y0 = y - 1; } else { y0 = 0; }
if (y < h - 1) { y2 = y + 1; } else { y2 = h - 1; }
x0 = (x > 0) ? (x - 1) : 0;
x2 = (x < w - 1) ? (x + 1) : (w - 1);
y0 = (y > 0) ? (y - 1) : 0;
y2 = (y < h - 1) ? (y + 1) : (h - 1);

x0 *= bpp;
x *= bpp;
Expand All @@ -90,18 +81,16 @@ void scale_scale2x(uint8_t * src, uint32_t * ret_pos, int x, int y, int w, int h
}
}


void scale_scale3x(uint8_t * src, uint32_t * ret_pos, int x, int y, int w, int h, int bpp)
{
int x0, x2;
int y0, y2;
int x0, y0, x2, y2;
uint32_t A, B, C, D, E, F, G, H, I;
uint8_t D_B, D_H, F_B, F_H, E_A, E_G, E_C, E_I;

if (x > 0) { x0 = x - 1; } else { x0 = 0; }
if (x < w - 1) { x2 = x + 1; } else { x2 = w - 1; }
if (y > 0) { y0 = y - 1; } else { y0 = 0; }
if (y < h - 1) { y2 = y + 1; } else { y2 = h - 1; }
x0 = (x > 0) ? (x - 1) : 0;
x2 = (x < w - 1) ? (x + 1) : (w - 1);
y0 = (y > 0) ? (y - 1) : 0;
y2 = (y < h - 1) ? (y + 1) : (h - 1);

x0 *= bpp;
x *= bpp;
Expand Down Expand Up @@ -166,11 +155,8 @@ void scale_scale3x(uint8_t * src, uint32_t * ret_pos, int x, int y, int w, int h
ret_pos[0] = ret_pos[1] = ret_pos[2] = ret_pos[3] = E;
ret_pos[4] = ret_pos[5] = ret_pos[6] = ret_pos[7] = ret_pos[8] = E;
}

}



// scaler_scalex_2x
//
// Scales image in *sp up by 2x into *dp
Expand Down Expand Up @@ -206,8 +192,6 @@ void scaler_scalex_2x(uint32_t * sp, uint32_t * dp, int Xres, int Yres)
}
}



// scaler_scalex_3x
//
// Scales image in *sp up by 3x into *dp
Expand Down Expand Up @@ -251,8 +235,6 @@ void scaler_scalex_3x(uint32_t * sp, uint32_t * dp, int Xres, int Yres)
}
}



// scaler_scalex_4x
//
// 4x is just the 2x scaler run twice
Expand Down Expand Up @@ -283,4 +265,20 @@ void scaler_scalex_4x(uint32_t * sp, uint32_t * dp, int Xres, int Yres)
free(p_tempbuf);
}


void scaler_scalex(uint32_t * sp, uint32_t * dp, int Xres, int Yres, int scalefactor)
{
switch (scalefactor)
{
case 2:
scaler_scalex_2x(sp, dp, Xres, Yres);
break;
case 3:
scaler_scalex_3x(sp, dp, Xres, Yres);
break;
case 4:
scaler_scalex_4x(sp, dp, Xres, Yres);
break;
default:
break;
}
}
11 changes: 1 addition & 10 deletions src/transform/pixart-scaler/xbr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include <cstdint>
#include <cstdlib>


#define LB_MASK 0x00FEFEFE
#define RED_BLUE_MASK 0x00FF00FF
#define GREEN_MASK 0x0000FF00
Expand Down Expand Up @@ -71,7 +70,6 @@ uint32_t pixel_diff(uint32_t x, uint32_t y)
abs((yuv1 & VMASK) - (yuv2 & VMASK));
}


#define ALPHA_BLEND_BASE(a, b, m, s) ( (PART_MASK & (((a) & PART_MASK) + (((((b) & PART_MASK) - ((a) & PART_MASK)) * (m)) >> (s)))) \
| ((PART_MASK & ((((a) >> 8) & PART_MASK) + ((((((b) >> 8) & PART_MASK) - (((a) >> 8) & PART_MASK)) * (m)) >> (s)))) << 8))

Expand All @@ -81,8 +79,6 @@ uint32_t pixel_diff(uint32_t x, uint32_t y)
#define ALPHA_BLEND_192_W(a, b) ALPHA_BLEND_BASE(a, b, 3, 2)
#define ALPHA_BLEND_224_W(a, b) ALPHA_BLEND_BASE(a, b, 7, 3)



#define df(A, B) pixel_diff(A, B)
#define eq(A, B) (df(A, B) < 155)

Expand Down Expand Up @@ -208,7 +204,7 @@ uint32_t pixel_diff(uint32_t x, uint32_t y)
} \
} while (0)

static void xbr_filter( uint32_t *src, uint32_t *dst, int inWidth, int inHeight, int scaleFactor )
void xbr_filter( uint32_t *src, uint32_t *dst, int inWidth, int inHeight, int scaleFactor )
{
int Bpp = 4; // ARGB32 format

Expand Down Expand Up @@ -318,22 +314,17 @@ static void xbr_filter( uint32_t *src, uint32_t *dst, int inWidth, int inHeight,
}
}



void xbr_filter_xbr2x(uint32_t *src, uint32_t *dst, int inWidth, int inHeight )
{
xbr_filter( src, dst, inWidth, inHeight, 2); // 2x scale factor
}


void xbr_filter_xbr3x(uint32_t *src, uint32_t *dst, int inWidth, int inHeight)
{
xbr_filter( src, dst, inWidth, inHeight, 3); // 3x scale factor
}


void xbr_filter_xbr4x(uint32_t *src, uint32_t *dst, int inWidth, int inHeight)
{
xbr_filter( src, dst, inWidth, inHeight, 4); // 4x scale factor
}

9 changes: 9 additions & 0 deletions src/transform/ris-scaler/libris.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
#ifndef __LIBRIS_H_
#define __LIBRIS_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
Expand Down Expand Up @@ -86,4 +90,9 @@ void scaler_hris_3x(uint32_t *src, uint32_t *dst, int width, int height);
void scaler_mean_x(uint32_t *src, uint32_t *dst, int width, int height, int scale_factor);
void scaler_mean_2x(uint32_t *src, uint32_t *dst, int width, int height);
void scaler_mean_3x(uint32_t *src, uint32_t *dst, int width, int height);

#ifdef __cplusplus
}
#endif

#endif //__LIBRIS_H_//
14 changes: 5 additions & 9 deletions src/transform/ris-scaler/ris_scaler.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#include "ris_scaler.h"
extern "C"
{
#include "libris.h"
}

#define PLUGIN_NAME "RIS Scalers"
#define PLUGIN_MENU "Transform/RIS"
Expand Down Expand Up @@ -52,24 +49,23 @@ RISDialog:: RISDialog(QWidget *parent) : QDialog(parent)
this->setWindowTitle(PLUGIN_NAME);
this->resize(320, 158);

QGridLayout *gridLayout = new QGridLayout(this);
gridLayout = new QGridLayout(this);

QLabel *labelMethod = new QLabel("Method :", this);
labelMethod = new QLabel("Method :", this);
gridLayout->addWidget(labelMethod, 0, 0, 1, 1);
comboMethod = new QComboBox(this);
QStringList items = { "GSample", "HRIS", "Mean"};
comboMethod->addItems(items);
comboMethod->addItems(itemsMethod);
gridLayout->addWidget(comboMethod, 0, 1, 1, 1);

QLabel *labelMult = new QLabel("Mult :", this);
labelMult = new QLabel("Mult :", this);
gridLayout->addWidget(labelMult, 1, 0, 1, 1);
spinMult = new QSpinBox(this);
spinMult->setAlignment(Qt::AlignCenter);
spinMult->setRange(2,3);
spinMult->setValue(2);
gridLayout->addWidget(spinMult, 1, 1, 1, 1);

QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Horizontal, this);
buttonBox = new QDialogButtonBox(Qt::Horizontal, this);
buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
gridLayout->addWidget(buttonBox, 2, 0, 1, 2);

Expand Down
5 changes: 5 additions & 0 deletions src/transform/ris-scaler/ris_scaler.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ public slots:
class RISDialog : public QDialog
{
public:
QGridLayout *gridLayout;
QLabel *labelMethod;
QComboBox *comboMethod;
QStringList itemsMethod = { "GSample", "HRIS", "Mean"};
QLabel *labelMult;
QSpinBox *spinMult;
QDialogButtonBox *buttonBox;

RISDialog(QWidget *parent);
};

0 comments on commit ae9cacf

Please sign in to comment.