Ceppo
25th January 2023, 03:03
Can someone teach me what I'm doing wrong, please :confused:
Everytime I write on a clip inside a struct or a class nothing works :\.
#pragma once
#include <cmath>
#include <windows.h>
#include <avisynth.h>
using namespace std;
struct CSharpenFilter
{
PVideoFrame src;
unsigned char* srcp;
int height, row_size, src_pitch;
//int* vector_srcp = new int[height * row_size];
//int* vector_blur = new int[height * row_size];
void GetFrame(PClip child, int n, IScriptEnvironment* env)
{
src = child->GetFrame(n, env);
env->MakeWritable(&src);
}
void GetPlaneY()
{
srcp = src->GetWritePtr(PLANAR_Y);
src_pitch = src->GetPitch(PLANAR_Y);
height = src->GetHeight(PLANAR_Y);
row_size = src->GetRowSize(PLANAR_Y);
}
void GetPlaneU()
{
srcp = src->GetWritePtr(PLANAR_U);
src_pitch = src->GetPitch(PLANAR_U);
height = src->GetHeight(PLANAR_U);
row_size = src->GetRowSize(PLANAR_U);
}
void GetPlaneV()
{
srcp = src->GetWritePtr(PLANAR_V);
src_pitch = src->GetPitch(PLANAR_V);
height = src->GetHeight(PLANAR_V);
row_size = src->GetRowSize(PLANAR_V);
}
void CoreFilter(int nt, int mode)
{
//for (int y = 0; y < height; y++)
//{
// for (int x = 0; x < row_size; x++)
// {
// vector_srcp[y * row_size + x] = srcp[x];
// }
// srcp += src_pitch;
//}
//for (int y = 0; y < height; y++)
//{
// for (int x = 0; x < row_size; x++)
// {
// vector_blur[y * row_size + x] += vector_srcp[y * row_size + x] * 4;
// vector_blur[y * row_size + x] += vector_srcp[y * row_size + max(0, x - 1)] * 2;
// vector_blur[y * row_size + x] += vector_srcp[y * row_size + min(row_size, x + 1)] * 2;
// vector_blur[y * row_size + x] += vector_srcp[max(0, y - 1) * row_size + x] * 2;
// vector_blur[y * row_size + x] += vector_srcp[max(0, y - 1) * row_size + max(0, x - 1)];
// vector_blur[y * row_size + x] += vector_srcp[max(0, y - 1) * row_size + min(row_size, x + 1)];
// vector_blur[y * row_size + x] += vector_srcp[min(height - 1, y + 1) * row_size + x] * 2;
// vector_blur[y * row_size + x] += vector_srcp[min(height - 1, y + 1) * row_size + max(0, x - 1)];
// vector_blur[y * row_size + x] += vector_srcp[min(height - 1, y + 1) * row_size + min(row_size, x + 1)];
// vector_blur[y * row_size + x] = static_cast<int64_t>(vector_blur[y * row_size + x] / 16.0f + 0.5f);
// }
//}
int i, j, k;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < row_size; x++)
{
i = (srcp + y * src_pitch)[x] * 4;
i += (srcp + y * src_pitch)[max(0, x - 1)] * 2;
i += (srcp + y * src_pitch)[min(row_size, x + 1)] * 2;
i += (srcp + max(0, y - 1) * src_pitch)[x] * 2;
i += (srcp + max(0, y - 1) * src_pitch)[max(0, x - 1)];
i += (srcp + max(0, y - 1) * src_pitch)[min(row_size, x + 1)];
i += (srcp + min(height - 1, y + 1) * src_pitch)[x] * 2;
i += (srcp + min(height - 1, y + 1) * src_pitch)[max(0, x - 1)];
i += (srcp + min(height - 1, y + 1) * src_pitch)[min(row_size, x + 1)];
i = srcp[x] - static_cast<int>(i / 16.0f + 0.5f);
j = abs(i);
k = (i > 0) - (i < 0);
i = j < nt ? 0 : i;
i = mode > 0 ? (int)sqrt(j) : i;
i = mode > 1 ? (int)atan(j) * i : i;
i = i * k;
i = max(0, min(255, (srcp + y * src_pitch)[x] + i));
(srcp + y * src_pitch)[x] = i;
}
}
}
};
class CSharpen : public GenericVideoFilter
{
int nt, mode;
bool Y, U, V;
public:
CSharpen::CSharpen(PClip _child, int _nt, int _mode, bool _Y, bool _U, bool _V, IScriptEnvironment* env) : GenericVideoFilter(_child), nt(_nt), mode(_mode), Y(_Y), U(_U), V(_V)
{
if (!vi.IsYUV())
{
env->ThrowError("CSharpen: supported colorspaces are Y8, YV12, YV16, YV24!");
}
else if (nt < 0 || nt > 255)
{
env->ThrowError("CSharpen: nt avaible range is [0, 255]!");
}
else if (mode < 0 || mode > 2)
{
env->ThrowError("CSharpen: mode avaible mode values are 0, 1, 2!");
}
}
PVideoFrame __stdcall CSharpen::GetFrame(int n, IScriptEnvironment* env) {
CSharpenFilter Frame;
Frame.GetFrame(child, n, env);
Y ? Frame.GetPlaneY() : NULL;
Y ? Frame.CoreFilter(nt, mode) : NULL;
!vi.IsY8() && U ? Frame.GetPlaneU() : NULL;
!vi.IsY8() && U ? Frame.CoreFilter(nt, mode) : NULL;
!vi.IsY8() && V ? Frame.GetPlaneV() : NULL;
!vi.IsY8() && V ? Frame.CoreFilter(nt, mode) : NULL;
return Frame.src;
}
};
Everytime I write on a clip inside a struct or a class nothing works :\.
#pragma once
#include <cmath>
#include <windows.h>
#include <avisynth.h>
using namespace std;
struct CSharpenFilter
{
PVideoFrame src;
unsigned char* srcp;
int height, row_size, src_pitch;
//int* vector_srcp = new int[height * row_size];
//int* vector_blur = new int[height * row_size];
void GetFrame(PClip child, int n, IScriptEnvironment* env)
{
src = child->GetFrame(n, env);
env->MakeWritable(&src);
}
void GetPlaneY()
{
srcp = src->GetWritePtr(PLANAR_Y);
src_pitch = src->GetPitch(PLANAR_Y);
height = src->GetHeight(PLANAR_Y);
row_size = src->GetRowSize(PLANAR_Y);
}
void GetPlaneU()
{
srcp = src->GetWritePtr(PLANAR_U);
src_pitch = src->GetPitch(PLANAR_U);
height = src->GetHeight(PLANAR_U);
row_size = src->GetRowSize(PLANAR_U);
}
void GetPlaneV()
{
srcp = src->GetWritePtr(PLANAR_V);
src_pitch = src->GetPitch(PLANAR_V);
height = src->GetHeight(PLANAR_V);
row_size = src->GetRowSize(PLANAR_V);
}
void CoreFilter(int nt, int mode)
{
//for (int y = 0; y < height; y++)
//{
// for (int x = 0; x < row_size; x++)
// {
// vector_srcp[y * row_size + x] = srcp[x];
// }
// srcp += src_pitch;
//}
//for (int y = 0; y < height; y++)
//{
// for (int x = 0; x < row_size; x++)
// {
// vector_blur[y * row_size + x] += vector_srcp[y * row_size + x] * 4;
// vector_blur[y * row_size + x] += vector_srcp[y * row_size + max(0, x - 1)] * 2;
// vector_blur[y * row_size + x] += vector_srcp[y * row_size + min(row_size, x + 1)] * 2;
// vector_blur[y * row_size + x] += vector_srcp[max(0, y - 1) * row_size + x] * 2;
// vector_blur[y * row_size + x] += vector_srcp[max(0, y - 1) * row_size + max(0, x - 1)];
// vector_blur[y * row_size + x] += vector_srcp[max(0, y - 1) * row_size + min(row_size, x + 1)];
// vector_blur[y * row_size + x] += vector_srcp[min(height - 1, y + 1) * row_size + x] * 2;
// vector_blur[y * row_size + x] += vector_srcp[min(height - 1, y + 1) * row_size + max(0, x - 1)];
// vector_blur[y * row_size + x] += vector_srcp[min(height - 1, y + 1) * row_size + min(row_size, x + 1)];
// vector_blur[y * row_size + x] = static_cast<int64_t>(vector_blur[y * row_size + x] / 16.0f + 0.5f);
// }
//}
int i, j, k;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < row_size; x++)
{
i = (srcp + y * src_pitch)[x] * 4;
i += (srcp + y * src_pitch)[max(0, x - 1)] * 2;
i += (srcp + y * src_pitch)[min(row_size, x + 1)] * 2;
i += (srcp + max(0, y - 1) * src_pitch)[x] * 2;
i += (srcp + max(0, y - 1) * src_pitch)[max(0, x - 1)];
i += (srcp + max(0, y - 1) * src_pitch)[min(row_size, x + 1)];
i += (srcp + min(height - 1, y + 1) * src_pitch)[x] * 2;
i += (srcp + min(height - 1, y + 1) * src_pitch)[max(0, x - 1)];
i += (srcp + min(height - 1, y + 1) * src_pitch)[min(row_size, x + 1)];
i = srcp[x] - static_cast<int>(i / 16.0f + 0.5f);
j = abs(i);
k = (i > 0) - (i < 0);
i = j < nt ? 0 : i;
i = mode > 0 ? (int)sqrt(j) : i;
i = mode > 1 ? (int)atan(j) * i : i;
i = i * k;
i = max(0, min(255, (srcp + y * src_pitch)[x] + i));
(srcp + y * src_pitch)[x] = i;
}
}
}
};
class CSharpen : public GenericVideoFilter
{
int nt, mode;
bool Y, U, V;
public:
CSharpen::CSharpen(PClip _child, int _nt, int _mode, bool _Y, bool _U, bool _V, IScriptEnvironment* env) : GenericVideoFilter(_child), nt(_nt), mode(_mode), Y(_Y), U(_U), V(_V)
{
if (!vi.IsYUV())
{
env->ThrowError("CSharpen: supported colorspaces are Y8, YV12, YV16, YV24!");
}
else if (nt < 0 || nt > 255)
{
env->ThrowError("CSharpen: nt avaible range is [0, 255]!");
}
else if (mode < 0 || mode > 2)
{
env->ThrowError("CSharpen: mode avaible mode values are 0, 1, 2!");
}
}
PVideoFrame __stdcall CSharpen::GetFrame(int n, IScriptEnvironment* env) {
CSharpenFilter Frame;
Frame.GetFrame(child, n, env);
Y ? Frame.GetPlaneY() : NULL;
Y ? Frame.CoreFilter(nt, mode) : NULL;
!vi.IsY8() && U ? Frame.GetPlaneU() : NULL;
!vi.IsY8() && U ? Frame.CoreFilter(nt, mode) : NULL;
!vi.IsY8() && V ? Frame.GetPlaneV() : NULL;
!vi.IsY8() && V ? Frame.CoreFilter(nt, mode) : NULL;
return Frame.src;
}
};