Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 17th January 2023, 15:01   #181  |  Link
anton_foy
Registered User
 
Join Date: Dec 2005
Location: Sweden
Posts: 703
CTools HBD rewrite

Not sure this is the right place to ask but since Ceppo is out of doom9 (at least since 10 months ago) I think forking his plugin would be in ok. Also I have not yet recieved a reply from Asd-g if he/she wants to modify/fork CTools.

The question is about the source code and how to modify it for HBD. I also see that it has no specific code for avx, avx2, avx512 etc. but as I am not even familiar with C++ or programming I leave that for now.

Here is my no-knowledge attempt to modify CDegrain.

type.h-file:
Code:
//type.h
#ifndef AVS_TYPES_H
#define AVS_TYPES_H

// Define all types necessary for interfacing with avisynth.dll
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
  #include <cstddef>
  #include <cstdarg>
#else
  #include <stddef.h>
  #include <stdarg.h>
#endif

// Raster types used by VirtualDub & Avisynth
typedef uint32_t Pixel32;
typedef uint16_t Pixel16;
//?
typedef Pixel16 Y_PLANE;
typedef Pixel16 U_PLANE;
typedef Pixel16 V_PLANE;
//?
typedef uint14_t Pixel14;
typedef Pixel14 Y_PLANE;
typedef Pixel14 U_PLANE;
typedef Pixel14 V_PLANE;
//
typedef uint12_t Pixel12;
typedef Pixel12 Y_PLANE;
typedef Pixel12 U_PLANE;
typedef Pixel12 V_PLANE;
//
typedef uint10_t Pixel10;
typedef Pixel10 Y_PLANE;
typedef Pixel10 U_PLANE;
typedef Pixel10 V_PLANE;
//
typedef uint8_t  BYTE;
typedef uint10_t  BYTE;
typedef uint12_t  BYTE;
typedef uint14_t  BYTE;
typedef uint16_t  BYTE;

// Audio Sample information
typedef float SFLOAT;

#endif //AVS_TYPES_H
CDegrain.h-file:
Code:
#pragma once
#include <cmath> 
#include <windows.h>
#include "avisynth.h"

class CDegrain : public GenericVideoFilter
{
    int radius;
    int nt;
    int thr;
    int blksize;
    PClip dClip;

public:
    CDegrain(PClip _child, int _radius, int _nt, int _thr, int _blksize, PClip _dClip, IScriptEnvironment* env);
    PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
};

void CDegrain_Y(PVideoFrame(&src)[15], PVideoFrame(&den)[15], PVideoFrame& dst, int nt, int thr, int radius, int blksize);
void CDegrain_YUV420(PVideoFrame(&src)[15], PVideoFrame(&den)[15], PVideoFrame& dst, int nt, int thr, int radius, int blksize);
void CDegrain_YUV422(PVideoFrame(&src)[15], PVideoFrame(&den)[15], PVideoFrame& dst, int nt, int thr, int radius, int blksize);
void CDegrain_YUV444(PVideoFrame(&src)[15], PVideoFrame(&den)[15], PVideoFrame& dst, int nt, int thr, int radius, int blksize);
End of part 1.
anton_foy is offline   Reply With Quote
Old 17th January 2023, 15:03   #182  |  Link
anton_foy
Registered User
 
Join Date: Dec 2005
Location: Sweden
Posts: 703
CTools HBD, part 2

CDegrain.cpp:
Code:
#include "CDegrain.h"

CDegrain::CDegrain(PClip _child, int _radius, int _nt, int _thr, int _blksize, PClip _dClip, IScriptEnvironment* env) : GenericVideoFilter(_child), radius(_radius), nt(_nt), thr(_thr), blksize(_blksize), dClip(_dClip)
{
    if (!vi.IsY() && !vi.IsYUV420() && !vi.IsYUV422() && !vi.IsYUV444())
    {
        env->ThrowError("CDegrain: supported colorspaces are Y, YUV420, YUV422, YUV444!");
    }
    else if ((vi.IsYUV420() || vi.IsYUV422()) && blksize < 2)
    {
        env->ThrowError("CDegrain: YUV420/YUV422 min. blksize is 2!");
    }
    else if (radius < 0 || radius > 7)
    {
        env->ThrowError("CDegrain: radius values must be in the [1, 7] range!");
    }
}

PVideoFrame __stdcall CDegrain::GetFrame(int n, IScriptEnvironment* env) {

    int i;
    PVideoFrame dst = env->NewVideoFrame(vi);

    PVideoFrame src[15];

    for (i = 0; i < radius; i += 1)
    {
        src[i] = child->GetFrame(max(n - radius + i, 0), env);
    }

    src[radius] = child->GetFrame(n, env);
    
    for (i = 0; i < radius; i += 1)
    {
        src[i + radius + 1] = child->GetFrame(min(n + i + 1, vi.num_frames - 1), env);
    }

    PVideoFrame den[15];

    if (!dClip)
    {
        vi.IsY() ? CDegrain_Y(src, src, dst, nt, thr, radius, blksize) : NULL;
        vi.IsYUV420() ? CDegrain_YUV420(src, src, dst, nt, thr, radius, blksize) : NULL;
        vi.IsYUV422() ? CDegrain_YUV422(src, src, dst, nt, thr, radius, blksize) : NULL;
        vi.IsYUV444() ? CDegrain_YUV444(src, src, dst, nt, thr, radius, blksize) : NULL;
    }
    else
    {
        for (i = 0; i < radius; i += 1)
        {
            den[i] = dClip->GetFrame(max(n - radius + i, 0), env);
        }

        den[radius] = dClip->GetFrame(n, env);

        for (i = 0; i < radius; i += 1)
        {
            den[i + radius + 1] = dClip->GetFrame(min(n + i + 1, vi.num_frames - 1), env);
        }

        vi.IsY() ? CDegrain_Y(src, den, dst, nt, thr, radius, blksize) : NULL;
        vi.IsYUV420() ? CDegrain_YUV420(src, den, dst, nt, thr, radius, blksize) : NULL;
        vi.IsYUV422() ? CDegrain_YUV422(src, den, dst, nt, thr, radius, blksize) : NULL;
        vi.IsYUV444() ? CDegrain_YUV444(src, den, dst, nt, thr, radius, blksize) : NULL;
    }

    return dst;
}

void CDegrain_Y(PVideoFrame(&src)[15], PVideoFrame(&den)[15], PVideoFrame& dst, int nt, int thr, int radius, int blksize)
{
    int i;
    unsigned char* dstp;
    dstp = dst->GetWritePtr(PLANAR_Y);

    const unsigned char* srcp[15];
    const unsigned char* denp[15];
    for (i = 0; i < 15; i += 1)
    {
        srcp[min(i, radius * 2)] = src[min(i, radius * 2)]->GetReadPtr(PLANAR_Y);
        denp[min(i, radius * 2)] = den[min(i, radius * 2)]->GetReadPtr(PLANAR_Y);
    }

    int dst_pitch;
    dst_pitch = dst->GetPitch(PLANAR_Y);

    int src_pitch[15];
    int den_pitch[15];
    for (i = 0; i < 15; i += 1)
    {
        src_pitch[min(i, radius * 2)] = src[min(i, radius * 2)]->GetPitch(PLANAR_Y);
        den_pitch[min(i, radius * 2)] = den[min(i, radius * 2)]->GetPitch(PLANAR_Y);
    }

    int height = dst->GetHeight(PLANAR_Y);
    int row_size = dst->GetRowSize(PLANAR_Y);

    int64_t BSY = 0;
    int64_t BSX = 0;
    BSY += min(1, height % blksize);
    BSY += height / blksize;
    BSX += min(1, row_size % blksize);
    BSX += row_size / blksize;
    auto SUM = new int[BSY * BSX][15];
    memset(SUM, 0, BSY * BSX * 15 * sizeof(int));

    int BX, BY;
    int pixel_sum[2];
    int x, y, a, b, temp;

    //DIFFERENCE
    for (y = 0; y < height; y += 1)
    {
        BY = y / blksize;
        BY += y % blksize ? 1 : 0;
        for (x = 0; x < row_size; x += 1)
        {
            BX = x / blksize;
            BX += x % blksize ? 1 : 0;
            for (i = 0; i < radius * 2 + 1; i += 1)
            {
                temp = abs(denp[i][x] - denp[radius][x]);
                SUM[BY * BSY + BX][i] += temp > nt ? 255 : temp;
            }
        }
        for (i = 0; i < radius * 2 + 1; i += 1)
        {
            denp[i] += den_pitch[i];
        }
    }

    //BLENDING
    for (y = 0; y < height; y += 1)
    {
        BY = y / blksize;
        BY += y % blksize ? 1 : 0;
        for (x = 0; x < row_size; x += 1)
        {
            BX = x / blksize;
            BX += x % blksize ? 1 : 0;
            for (i = 0; i < radius * 2 + 1; i += 1)
            {
                pixel_sum[0] = 0;
                pixel_sum[1] = 0;
                for (i = 0; i < radius * 2 + 1; i += 1)
                {
                    pixel_sum[0] += SUM[BY * BSY + BX][i] <= thr ? 1 : 0;
                    pixel_sum[1] += SUM[BY * BSY + BX][i] <= thr ? srcp[i][x] : 0;
                }
                dstp[x] = int(pixel_sum[1] / static_cast<float>(pixel_sum[0]) + 0.5f);
            }
        }
        dstp += dst_pitch;
        for (i = 0; i < radius * 2 + 1; i += 1)
        {
            srcp[i] += src_pitch[i];
        }
    }
}

void CDegrain_YUV420(PVideoFrame(&src)[15], PVideoFrame(&den)[15], PVideoFrame& dst, int nt, int thr, int radius, int blksize)
{
    int i;
    unsigned char* dstp[3];
    dstp[0] = dst->GetWritePtr(PLANAR_Y);
    dstp[1] = dst->GetWritePtr(PLANAR_U);
    dstp[2] = dst->GetWritePtr(PLANAR_V);

    const unsigned char* srcp[3][15];
    const unsigned char* denp[3][15];
    for (i = 0; i < 15; i += 1)
    {
        srcp[0][min(i, radius * 2)] = src[min(i, radius * 2)]->GetReadPtr(PLANAR_Y);
        denp[0][min(i, radius * 2)] = den[min(i, radius * 2)]->GetReadPtr(PLANAR_Y);
        srcp[1][min(i, radius * 2)] = src[min(i, radius * 2)]->GetReadPtr(PLANAR_U);
        denp[1][min(i, radius * 2)] = den[min(i, radius * 2)]->GetReadPtr(PLANAR_U);
        srcp[2][min(i, radius * 2)] = src[min(i, radius * 2)]->GetReadPtr(PLANAR_V);
        denp[2][min(i, radius * 2)] = den[min(i, radius * 2)]->GetReadPtr(PLANAR_V);
    }

    int dst_pitch[3];
    dst_pitch[0] = dst->GetPitch(PLANAR_Y);
    dst_pitch[1] = dst->GetPitch(PLANAR_U);
    dst_pitch[2] = dst->GetPitch(PLANAR_V);

    int src_pitch[3][15];
    int den_pitch[3][15];
    for (i = 0; i < 15; i += 1)
    {
        src_pitch[0][min(i, radius * 2)] = src[min(i, radius * 2)]->GetPitch(PLANAR_Y);
        den_pitch[0][min(i, radius * 2)] = den[min(i, radius * 2)]->GetPitch(PLANAR_Y);
        src_pitch[1][min(i, radius * 2)] = src[min(i, radius * 2)]->GetPitch(PLANAR_U);
        den_pitch[1][min(i, radius * 2)] = den[min(i, radius * 2)]->GetPitch(PLANAR_U);
        src_pitch[2][min(i, radius * 2)] = src[min(i, radius * 2)]->GetPitch(PLANAR_V);
        den_pitch[2][min(i, radius * 2)] = den[min(i, radius * 2)]->GetPitch(PLANAR_V);
    }

    int height = dst->GetHeight(PLANAR_Y);
    int row_size = dst->GetRowSize(PLANAR_Y);

    int64_t BSY = 0;
    int64_t BSX = 0;
    BSY += min(1, height % blksize);
    BSY += height / blksize;
    BSX += min(1, row_size % blksize);
    BSX += row_size / blksize;
    auto SUM = new int[BSY * BSX][15];
    memset(SUM, 0, BSY * BSX * 15 * sizeof(int));

    int BX, BY;
    int pixel_sum[3];
    int x, y, a, b, temp;

    //DIFFERENCE
    for (y = 0; y < height; y += 1)
    {
        BY = y / blksize;
        BY += y % blksize ? 1 : 0;
        for (x = 0; x < row_size; x += 1)
        {
            BX = x / blksize;
            BX += x % blksize ? 1 : 0;
            for (i = 0; i < radius * 2 + 1; i += 1)
            {
                temp = abs(denp[0][i][x] - denp[0][radius][x]);
                SUM[BY * BSY + BX][i] += temp > nt ? 255 : temp;
            }
            if (!(y % 2) && !(x % 2))
            {
                for (i = 0; i < radius * 2 + 1; i += 1)
                {
                    temp = abs(denp[1][i][x / 2] - denp[1][radius][x / 2]);
                    SUM[BY * BSY + BX][i] += temp > nt ? 255 : temp;
                    temp = abs(denp[2][i][x / 2] - denp[2][radius][x / 2]);
                    SUM[BY * BSY + BX][i] += temp > nt ? 255 : temp;
                }
            }
        }
        for (i = 0; i < radius * 2 + 1; i += 1)
        {
            denp[0][i] += den_pitch[0][i];
        }
        if (!(y % 2))
        {
            for (i = 0; i < radius * 2 + 1; i += 1)
            {
                denp[1][i] += den_pitch[1][i];
                denp[2][i] += den_pitch[2][i];
            }
        }
    }

    //BLENDING
    for (y = 0; y < height; y += 1)
    {
        BY = y / blksize;
        BY += y % blksize ? 1 : 0;
        for (x = 0; x < row_size; x += 1)
        {
            BX = x / blksize;
            BX += x % blksize ? 1 : 0;
            for (i = 0; i < radius * 2 + 1; i += 1)
            {
                pixel_sum[0] = 0;
                pixel_sum[1] = 0;
                for (i = 0; i < radius * 2 + 1; i += 1)
                {
                    pixel_sum[0] += SUM[BY * BSY + BX][i] <= thr ? 1 : 0;
                    pixel_sum[1] += SUM[BY * BSY + BX][i] <= thr ? srcp[0][i][x] : 0;
                }
                dstp[0][x] = int(pixel_sum[1] / static_cast<float>(pixel_sum[0]) + 0.5f);
                
// Continues in next post.
anton_foy is offline   Reply With Quote
Old 17th January 2023, 15:04   #183  |  Link
anton_foy
Registered User
 
Join Date: Dec 2005
Location: Sweden
Posts: 703
Code:
                if (!(y % 2) && !(x % 2))
                {
                    pixel_sum[0] = 0;
                    pixel_sum[1] = 0;
                    pixel_sum[2] = 0;
                    for (i = 0; i < radius * 2 + 1; i += 1)
                    {
                        pixel_sum[0] += SUM[BY * BSY + BX][i] <= thr ? 1 : 0;
                        pixel_sum[1] += SUM[BY * BSY + BX][i] <= thr ? srcp[1][i][x / 2] : 0;
                        pixel_sum[2] += SUM[BY * BSY + BX][i] <= thr ? srcp[2][i][x / 2] : 0;
                    }
                    dstp[1][x / 2] = int(pixel_sum[1] / static_cast<float>(pixel_sum[0]) + 0.5f);
                    dstp[2][x / 2] = int(pixel_sum[2] / static_cast<float>(pixel_sum[0]) + 0.5f);
                }  
            }
        }
        dstp[0] += dst_pitch[0];
        for (i = 0; i < radius * 2 + 1; i += 1)
        {
            srcp[0][i] += src_pitch[0][i];
        }
        if (!(y % 2))
        {
            dstp[1] += dst_pitch[1];
            dstp[2] += dst_pitch[2];
            for (i = 0; i < radius * 2 + 1; i += 1)
            {
                srcp[1][i] += src_pitch[1][i];
                srcp[2][i] += src_pitch[2][i];
            }
        }
    }
}

void CDegrain_YUV422(PVideoFrame(&src)[15], PVideoFrame(&den)[15], PVideoFrame& dst, int nt, int thr, int radius, int blksize)
{
    int i;
    unsigned char* dstp[3];
    dstp[0] = dst->GetWritePtr(PLANAR_Y);
    dstp[1] = dst->GetWritePtr(PLANAR_U);
    dstp[2] = dst->GetWritePtr(PLANAR_V);

    const unsigned char* srcp[3][15];
    const unsigned char* denp[3][15];
    for (i = 0; i < 15; i += 1)
    {
        srcp[0][min(i, radius * 2)] = src[min(i, radius * 2)]->GetReadPtr(PLANAR_Y);
        denp[0][min(i, radius * 2)] = den[min(i, radius * 2)]->GetReadPtr(PLANAR_Y);
        srcp[1][min(i, radius * 2)] = src[min(i, radius * 2)]->GetReadPtr(PLANAR_U);
        denp[1][min(i, radius * 2)] = den[min(i, radius * 2)]->GetReadPtr(PLANAR_U);
        srcp[2][min(i, radius * 2)] = src[min(i, radius * 2)]->GetReadPtr(PLANAR_V);
        denp[2][min(i, radius * 2)] = den[min(i, radius * 2)]->GetReadPtr(PLANAR_V);
    }

    int dst_pitch[3];
    dst_pitch[0] = dst->GetPitch(PLANAR_Y);
    dst_pitch[1] = dst->GetPitch(PLANAR_U);
    dst_pitch[2] = dst->GetPitch(PLANAR_V);

    int src_pitch[3][15];
    int den_pitch[3][15];
    for (i = 0; i < 15; i += 1)
    {
        src_pitch[0][min(i, radius * 2)] = src[min(i, radius * 2)]->GetPitch(PLANAR_Y);
        den_pitch[0][min(i, radius * 2)] = den[min(i, radius * 2)]->GetPitch(PLANAR_Y);
        src_pitch[1][min(i, radius * 2)] = src[min(i, radius * 2)]->GetPitch(PLANAR_U);
        den_pitch[1][min(i, radius * 2)] = den[min(i, radius * 2)]->GetPitch(PLANAR_U);
        src_pitch[2][min(i, radius * 2)] = src[min(i, radius * 2)]->GetPitch(PLANAR_V);
        den_pitch[2][min(i, radius * 2)] = den[min(i, radius * 2)]->GetPitch(PLANAR_V);
    }

    int height = dst->GetHeight(PLANAR_Y);
    int row_size = dst->GetRowSize(PLANAR_Y);

    int64_t BSY = 0;
    int64_t BSX = 0;
    BSY += min(1, height % blksize);
    BSY += height / blksize;
    BSX += min(1, row_size % blksize);
    BSX += row_size / blksize;
    auto SUM = new int[BSY * BSX][15];
    memset(SUM, 0, BSY * BSX * 15 * sizeof(int));

    int BX, BY;
    int pixel_sum[3];
    int x, y, a, b, temp;

    //DIFFERENCE
    for (y = 0; y < height; y += 1)
    {
        BY = y / blksize;
        BY += y % blksize ? 1 : 0;
        for (x = 0; x < row_size; x += 1)
        {
            BX = x / blksize;
            BX += x % blksize ? 1 : 0;
            for (i = 0; i < radius * 2 + 1; i += 1)
            {
                temp = abs(denp[0][i][x] - denp[0][radius][x]);
                SUM[BY * BSY + BX][i] += temp > nt ? 255 : temp;
            }
            if (!(x % 2))
            {
                for (i = 0; i < radius * 2 + 1; i += 1)
                {
                    temp = abs(denp[1][i][x / 2] - denp[1][radius][x / 2]);
                    SUM[BY * BSY + BX][i] += temp > nt ? 255 : temp;
                    temp = abs(denp[2][i][x / 2] - denp[2][radius][x / 2]);
                    SUM[BY * BSY + BX][i] += temp > nt ? 255 : temp;
                }
            }
        }
        for (i = 0; i < radius * 2 + 1; i += 1)
        {
            denp[0][i] += den_pitch[0][i];
            denp[1][i] += den_pitch[1][i];
            denp[2][i] += den_pitch[2][i];
        }
    }

    //BLENDING
    for (y = 0; y < height; y += 1)
    {
        BY = y / blksize;
        BY += y % blksize ? 1 : 0;
        for (x = 0; x < row_size; x += 1)
        {
            BX = x / blksize;
            BX += x % blksize ? 1 : 0;
            for (i = 0; i < radius * 2 + 1; i += 1)
            {
                pixel_sum[0] = 0;
                pixel_sum[1] = 0;
                for (i = 0; i < radius * 2 + 1; i += 1)
                {
                    pixel_sum[0] += SUM[BY * BSY + BX][i] <= thr ? 1 : 0;
                    pixel_sum[1] += SUM[BY * BSY + BX][i] <= thr ? srcp[0][i][x] : 0;
                }
                dstp[0][x] = int(pixel_sum[1] / static_cast<float>(pixel_sum[0]) + 0.5f);

                if (!(x % 2))
                {
                    pixel_sum[0] = 0;
                    pixel_sum[1] = 0;
                    pixel_sum[2] = 0;
                    for (i = 0; i < radius * 2 + 1; i += 1)
                    {
                        pixel_sum[0] += SUM[BY * BSY + BX][i] <= thr ? 1 : 0;
                        pixel_sum[1] += SUM[BY * BSY + BX][i] <= thr ? srcp[1][i][x / 2] : 0;
                        pixel_sum[2] += SUM[BY * BSY + BX][i] <= thr ? srcp[2][i][x / 2] : 0;
                    }
                    dstp[1][x / 2] = int(pixel_sum[1] / static_cast<float>(pixel_sum[0]) + 0.5f);
                    dstp[2][x / 2] = int(pixel_sum[2] / static_cast<float>(pixel_sum[0]) + 0.5f);
                }
            }
        }
        dstp[0] += dst_pitch[0];
        dstp[1] += dst_pitch[1];
        dstp[2] += dst_pitch[2];
        for (i = 0; i < radius * 2 + 1; i += 1)
        {
            srcp[0][i] += src_pitch[0][i];
            srcp[1][i] += src_pitch[1][i];
            srcp[2][i] += src_pitch[2][i];
        }
    }
}

void CDegrain_YUV444(PVideoFrame(&src)[15], PVideoFrame(&den)[15], PVideoFrame& dst, int nt, int thr, int radius, int blksize)
{
    int i;
    unsigned char* dstp[3];
    dstp[0] = dst->GetWritePtr(PLANAR_Y);
    dstp[1] = dst->GetWritePtr(PLANAR_U);
    dstp[2] = dst->GetWritePtr(PLANAR_V);

    const unsigned char* srcp[3][15];
    const unsigned char* denp[3][15];
    for (i = 0; i < 15; i += 1)
    {
        srcp[0][min(i, radius * 2)] = src[min(i, radius * 2)]->GetReadPtr(PLANAR_Y);
        denp[0][min(i, radius * 2)] = den[min(i, radius * 2)]->GetReadPtr(PLANAR_Y);
        srcp[1][min(i, radius * 2)] = src[min(i, radius * 2)]->GetReadPtr(PLANAR_U);
        denp[1][min(i, radius * 2)] = den[min(i, radius * 2)]->GetReadPtr(PLANAR_U);
        srcp[2][min(i, radius * 2)] = src[min(i, radius * 2)]->GetReadPtr(PLANAR_V);
        denp[2][min(i, radius * 2)] = den[min(i, radius * 2)]->GetReadPtr(PLANAR_V);
    }

    int dst_pitch[3];
    dst_pitch[0] = dst->GetPitch(PLANAR_Y);
    dst_pitch[1] = dst->GetPitch(PLANAR_U);
    dst_pitch[2] = dst->GetPitch(PLANAR_V);

    int src_pitch[3][15];
    int den_pitch[3][15];
    for (i = 0; i < 15; i += 1)
    {
        src_pitch[0][min(i, radius * 2)] = src[min(i, radius * 2)]->GetPitch(PLANAR_Y);
        den_pitch[0][min(i, radius * 2)] = den[min(i, radius * 2)]->GetPitch(PLANAR_Y);
        src_pitch[1][min(i, radius * 2)] = src[min(i, radius * 2)]->GetPitch(PLANAR_U);
        den_pitch[1][min(i, radius * 2)] = den[min(i, radius * 2)]->GetPitch(PLANAR_U);
        src_pitch[2][min(i, radius * 2)] = src[min(i, radius * 2)]->GetPitch(PLANAR_V);
        den_pitch[2][min(i, radius * 2)] = den[min(i, radius * 2)]->GetPitch(PLANAR_V);
    }

    int height = dst->GetHeight(PLANAR_Y);
    int row_size = dst->GetRowSize(PLANAR_Y);

    int64_t BSY = 0;
    int64_t BSX = 0;
    BSY += min(1, height % blksize);
    BSY += height / blksize;
    BSX += min(1, row_size % blksize);
    BSX += row_size / blksize;
    auto SUM = new int[BSY * BSX][15];
    memset(SUM, 0, BSY * BSX * 15 * sizeof(int));

    int BX, BY;
    int pixel_sum[4];
    int x, y, a, b, temp;

    //DIFFERENCE
    for (y = 0; y < height; y += 1)
    {
        BY = y / blksize;
        BY += y % blksize ? 1 : 0;
        for (x = 0; x < row_size; x += 1)
        {
            BX = x / blksize;
            BX += x % blksize ? 1 : 0;
            for (i = 0; i < radius * 2 + 1; i += 1)
            {
                temp = abs(denp[0][i][x] - denp[0][radius][x]);
                SUM[BY * BSY + BX][i] += temp > nt ? 255 : temp;
                temp = abs(denp[1][i][x] - denp[1][radius][x]);
                SUM[BY * BSY + BX][i] += temp > nt ? 255 : temp;
                temp = abs(denp[2][i][x] - denp[2][radius][x]);
                SUM[BY * BSY + BX][i] += temp > nt ? 255 : temp;
            }
        }
        for (i = 0; i < radius * 2 + 1; i += 1)
        {
            denp[0][i] += den_pitch[0][i];
            denp[1][i] += den_pitch[1][i];
            denp[2][i] += den_pitch[2][i];
        }
    }

    //BLENDING
    for (y = 0; y < height; y += 1)
    {
        BY = y / blksize;
        BY += y % blksize ? 1 : 0;
        for (x = 0; x < row_size; x += 1)
        {
            BX = x / blksize;
            BX += x % blksize ? 1 : 0;
            for (i = 0; i < radius * 2 + 1; i += 1)
            {
                pixel_sum[0] = 0;
                pixel_sum[1] = 0;
                pixel_sum[2] = 0;
                pixel_sum[3] = 0;
                for (i = 0; i < radius * 2 + 1; i += 1)
                {
                    pixel_sum[0] += SUM[BY * BSY + BX][i] <= thr ? 1 : 0;
                    pixel_sum[1] += SUM[BY * BSY + BX][i] <= thr ? srcp[0][i][x] : 0;
                    pixel_sum[2] += SUM[BY * BSY + BX][i] <= thr ? srcp[1][i][x] : 0;
                    pixel_sum[3] += SUM[BY * BSY + BX][i] <= thr ? srcp[2][i][x] : 0;
                }
                dstp[0][x] = int(pixel_sum[1] / static_cast<float>(pixel_sum[0]) + 0.5f);
                dstp[1][x] = int(pixel_sum[2] / static_cast<float>(pixel_sum[0]) + 0.5f);
                dstp[2][x] = int(pixel_sum[3] / static_cast<float>(pixel_sum[0]) + 0.5f);
            }
        }
        dstp[0] += dst_pitch[0];
        dstp[1] += dst_pitch[1];
        dstp[2] += dst_pitch[2];
        for (i = 0; i < radius * 2 + 1; i += 1)
        {
            srcp[0][i] += src_pitch[0][i];
            srcp[1][i] += src_pitch[1][i];
            srcp[2][i] += src_pitch[2][i];
        }
    }
}
Someone who knows better could tell me where the BitsPerComponent should be? Or if this code is structured in another manner.
anton_foy is offline   Reply With Quote
Old 17th January 2023, 20:26   #184  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
I once asked Pinterf if there was a good example for coding for AVS+ colorspace stuff, [I cant find the posts, but], see here reply suggested Average plugin :-
https://github.com/pinterf/Average/releases/tag/0.95
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 17th January 2023 at 21:26.
StainlessS is offline   Reply With Quote
Old 18th January 2023, 00:35   #185  |  Link
anton_foy
Registered User
 
Join Date: Dec 2005
Location: Sweden
Posts: 703
Quote:
Originally Posted by StainlessS View Post
I once asked Pinterf if there was a good example for coding for AVS+ colorspace stuff, [I cant find the posts, but], see here reply suggested Average plugin :-
https://github.com/pinterf/Average/releases/tag/0.95
Thanks for the link! Way over my head atm but hopefully Im getting the hang of things later on.
Harassing the ChatGPT bot to spit out CUDA optimizations of CTools and hbd support. One can only dream I guess.

Edit: here I paste what the bot did. Gibberish or usable?

Cdegrain_cuda.cpp:
https://pastebin.com/cCsNN3Uh

Cdegrain.h (cuda):
https://pastebin.com/HDy5wS10

AvisynthpluginInit_cuda.cpp:
https://pastebin.com/VRAQhgri

types_cuda.h:
https://pastebin.com/SCnCWY3N

minmax_cuda.h:
https://pastebin.com/0MTCE2pB

cpuid_cuda.h:
https://pastebin.com/Ndu6wSJu

Alignment_cuda.h:
https://pastebin.com/xdh1hNM2

Ctemporalsoften_cuda.cpp:
https://pastebin.com/d4bBPxD2

Last edited by anton_foy; 18th January 2023 at 14:05.
anton_foy is offline   Reply With Quote
Old 18th January 2023, 22:47   #186  |  Link
Ceppo
Registered User
 
Join Date: Feb 2016
Location: Nonsense land
Posts: 339
I got the notification for this CDegrain stuff, glad someone found uselful my work and wants to improve it. BTW, it was not for the argument on github iyeah I was pissed, I admit it) that i leaved but because I'm tring to get a degree in philosophy in 1 year and I'm giving 3 exams for month, I also left my job, so I can't let myself get obsessed by my encoding obsession otherwise or I want be able to reach my goal. I won't answer to any replay to protect myself from the ipnoting power of avisynth.
Ceppo is offline   Reply With Quote
Old 18th January 2023, 22:56   #187  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,666
@Ceppo

Glad that I was wrong that you won't return ... It just sounded that way from your last words on there, and then you went missing. But good to hear that all is fine with you!
Reel.Deel is offline   Reply With Quote
Old 19th January 2023, 00:38   #188  |  Link
anton_foy
Registered User
 
Join Date: Dec 2005
Location: Sweden
Posts: 703
Quote:
Originally Posted by Ceppo View Post
I got the notification for this CDegrain stuff, glad someone found uselful my work and wants to improve it. BTW, it was not for the argument on github iyeah I was pissed, I admit it) that i leaved but because I'm tring to get a degree in philosophy in 1 year and I'm giving 3 exams for month, I also left my job, so I can't let myself get obsessed by my encoding obsession otherwise or I want be able to reach my goal. I won't answer to any replay to protect myself from the ipnoting power of avisynth.
Good to hear from you, sorry about the job but good luck with your goals!

Thanks for letting me/us improve your code.
anton_foy is offline   Reply With Quote
Old 23rd January 2023, 20:23   #189  |  Link
Ceppo
Registered User
 
Join Date: Feb 2016
Location: Nonsense land
Posts: 339
I have a good news, to get a degree I need to do only 2 exams and write the thesis. So if someone mods CSharpen or a simple plugin like that I can rewrite CTools for HBD (when I want to relax to not think about philosophy) but is not something that I will do in a few days. Also, I have no knowlodge of optimization and stuff, and unless someone makes me an easy tutorial to get started, someone else will have to do the optimization.

Hope that helps.
Ceppo is offline   Reply With Quote
Old 23rd January 2023, 22:30   #190  |  Link
anton_foy
Registered User
 
Join Date: Dec 2005
Location: Sweden
Posts: 703
Quote:
Originally Posted by Ceppo View Post
I have a good news, to get a degree I need to do only 2 exams and write the thesis. So if someone mods CSharpen or a simple plugin like that I can rewrite CTools for HBD (when I want to relax to not think about philosophy) but is not something that I will do in a few days. Also, I have no knowlodge of optimization and stuff, and unless someone makes me an easy tutorial to get started, someone else will have to do the optimization.

Hope that helps.
Yay Ceppo awesome news! I wish I could help but I know nothing about programming. But I don't think just making it HBD should be so hard. If I understand correctly (which I probably don't) then what I modded in the helper headers and cpp-files for hbd is enough?
From old avisynth to avs+ I was thinking the change is
yv12 becomes YUV420, YV16 - YUV422, yv24 - YUV444, Y8 - Y. Then call bitspercomponent and probably use bitLshift when need of scaling 0-256.
Someone who really knows this please correct me.
anton_foy is offline   Reply With Quote
Old 23rd January 2023, 22:35   #191  |  Link
Ceppo
Registered User
 
Join Date: Feb 2016
Location: Nonsense land
Posts: 339
I'm not a programmer, I need working examples to make experiments and learn that way to get the hang of it. Sadly, I have a humanistic CV, so I lack a lot of information about programming.

AND ON STACKOVERFLOW NOBODY CARES ABOUT AVISYNTH; WHYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY

of course I'm drunk

Last edited by Ceppo; 23rd January 2023 at 22:37.
Ceppo is offline   Reply With Quote
Old 24th January 2023, 17:17   #192  |  Link
Ceppo
Registered User
 
Join Date: Feb 2016
Location: Nonsense land
Posts: 339
I have only 1 exam this month, so I'm making experiments since I'm rusty. Can someone help me figure out why this plugins makes AVSPMOD crash? It's probabily something stupid, but I can't figure it out.

Code:
#pragma once
#include <avisynth.h>

class CReadVideoFrame
{
public:
    PVideoFrame frame;
    const unsigned char* pixel[3];
    int pitch[3];
    int height[3];
    int row_size[3];

    CReadVideoFrame(PVideoFrame src)
    {
        this->frame = src;
        this->pixel[0] = this->frame->GetReadPtr(PLANAR_Y);
        this->pixel[1] = this->frame->GetReadPtr(PLANAR_U);
        this->pixel[2] = this->frame->GetReadPtr(PLANAR_V);
        this->pitch[0] = this->frame->GetPitch(PLANAR_Y);
        this->pitch[1] = this->frame->GetPitch(PLANAR_U);
        this->pitch[2] = this->frame->GetPitch(PLANAR_V);
        this->height[0] = this->frame->GetHeight(PLANAR_Y);
        this->height[1] = this->frame->GetHeight(PLANAR_U);
        this->height[2] = this->frame->GetHeight(PLANAR_V);
        this->row_size[0] = this->frame->GetRowSize(PLANAR_Y);
        this->row_size[1] = this->frame->GetRowSize(PLANAR_U);
        this->row_size[2] = this->frame->GetRowSize(PLANAR_V);
    };
};

class CWriteVideoFrame
{
public:
    PVideoFrame frame;
    unsigned char* pixel[3];
    int pitch[3];

    CWriteVideoFrame(PVideoFrame dst)
    {
        this->frame = dst;
        this->pixel[0] = this->frame->GetWritePtr(PLANAR_Y);
        this->pixel[1] = this->frame->GetWritePtr(PLANAR_U);
        this->pixel[2] = this->frame->GetWritePtr(PLANAR_V);
        this->pitch[0] = this->frame->GetPitch(PLANAR_Y);
        this->pitch[1] = this->frame->GetPitch(PLANAR_U);
        this->pitch[2] = this->frame->GetPitch(PLANAR_V);
    };
};

class SimpleCopy : public GenericVideoFilter
{
public:
    SimpleCopy(PClip _child, IScriptEnvironment* env) : GenericVideoFilter(_child)
    { }
    PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env)
    {
        CReadVideoFrame src(child->GetFrame(n, env));
        CWriteVideoFrame dst(env->NewVideoFrame(vi));

        for (int p = 0; p < 3; p++)
        {
            for (int y = 0; y < src.height[p]; y++)
            {
                for (int x = 0; x < src.row_size[p]; x++)
                {
                    dst.pixel[p][x] = src.pixel[p][x];
                }
                dst.pixel[p] += dst.pitch[p];
                src.pixel[p] += src.pitch[p];
            }

        }
        return dst.frame;
    }
};

AVSValue __cdecl Create_SimpleCopy(AVSValue args, void* user_data, IScriptEnvironment* env)
{
    return new SimpleCopy(args[0].AsClip(), env);
}

const AVS_Linkage* AVS_linkage = 0;

extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit3(IScriptEnvironment * env, const AVS_Linkage* const vectors)
{
    AVS_linkage = vectors;
    env->AddFunction("SimpleCopy", "c", Create_SimpleCopy, 0);

    return "SimpleCopy";
}
Ceppo is offline   Reply With Quote
Old 7th March 2023, 05:40   #193  |  Link
PoeBear
Registered User
 
Join Date: Jan 2017
Posts: 48
Quote:
Originally Posted by real.finder View Post
even if it not a big problem with dClip, but will test and see, thanks
Can I ask what the fix is with dClip to solve the field matching problem?

I'm enjoying CQTGMC on my live-action DVDs, but it seems to affect nearly every Fox Animation DVD I have, though they are notorious for being poorly encoded (Simpsons, Family Guy, etc)
PoeBear is offline   Reply With Quote
Old 15th July 2023, 05:03   #194  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,587
Quote:
Originally Posted by PoeBear View Post
Can I ask what the fix is with dClip to solve the field matching problem?

I'm enjoying CQTGMC on my live-action DVDs, but it seems to affect nearly every Fox Animation DVD I have, though they are notorious for being poorly encoded (Simpsons, Family Guy, etc)
you can search in this Thread and see

anyway, if Ceppo still care, I came across a source with a stubborn scene that has mouth problem, so I used animeivtc but even the default autoAssufthr1 was not enough so I did use "autoAssuf=true, autoAssufthr1=0.3"

so Ceppo may like port the method to CTelecine https://github.com/realfinder/AVS-St...avsi#L290-L307 as mode=7 or as new parameter
__________________
See My Avisynth Stuff

Last edited by real.finder; 15th July 2023 at 05:09.
real.finder is offline   Reply With Quote
Old 14th October 2023, 15:53   #195  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,587
after more tests seems http://avisynth.nl/index.php/IT is the best for field matching mouth problem

also seems Ceppo delete his account in github and also the project go with it so here the archive like for it https://web.archive.org/web/20230118...poTools/CTools
__________________
See My Avisynth Stuff
real.finder is offline   Reply With Quote
Old 15th October 2023, 02:34   #196  |  Link
kedautinh12
Registered User
 
Join Date: Jan 2018
Posts: 2,156
@real.finder did you test new ideas from Ceppo???
https://forum.doom9.org/showthread.php?t=185104
kedautinh12 is offline   Reply With Quote
Old 15th October 2023, 03:43   #197  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,587
Quote:
Originally Posted by kedautinh12 View Post
@real.finder did you test new ideas from Ceppo???
https://forum.doom9.org/showthread.php?t=185104
didn't note it, I am busy with other things these days so I kinda not check doom9 as before

anyway it seems interesting, but still I hope for a plugin update not only for better Field Matching but also for better VFR and frame properties support Plus HBD
__________________
See My Avisynth Stuff
real.finder is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:05.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.