<commit_before>﻿Imports System.Numerics
Imports Microsoft.Graphics.Canvas
Imports Microsoft.Graphics.Canvas.Effects
Imports Microsoft.Graphics.Canvas.UI.Xaml
Imports Windows.Graphics.DirectX
Imports Windows.UI


Public NotInheritable Class MainPageV1
    Inherits Page

    WithEvents App As App = App.Current
    WithEvents canvas1 As CanvasControl

    Dim Surface1, Surface2 As CanvasRenderTarget
    Dim StepEffectDL1, StepEffectDL2, StepEffectDR1, StepEffectDR2 As ConvolveMatrixEffect
    Dim StepEffectDL, StepEffectDR As ArithmeticCompositeEffect
    Dim DrawEffect1 As DpiCompensationEffect
    Dim DrawEffect2 As Transform2DEffect

    Dim Pen As Color = Colors.Gray

    Sub New()
        InitializeComponent()
        canvas1 = New CanvasControl
        container1.Children.Insert(0, canvas1)
    End Sub


    Sub App_Loaded() Handles App.Loaded
        If Surface1 Is Nothing Then Return
        Dim cols = App.Pixels.Select(Function(c) CType(c, ColorF)).ToArray()
        Surface1.SetPixelColorFs(cols, 0, 0, App.CWIDTH, App.CHEIGHT)
    End Sub

    Sub App_Unloading() Handles App.Unloading
        If Surface1 Is Nothing Then Return
        Dim cols = Surface1.GetPixelColorFs(0, 0, App.CWIDTH, App.CHEIGHT)
        App.Pixels = cols.Select(Function(c) CType(c, Color)).ToArray()
    End Sub


    Sub Canvas_CreateResources(sender As CanvasControl, args As Object) Handles canvas1.CreateResources
        Const defaultDpi = 96.0F
        Surface1 = New CanvasRenderTarget(canvas1, App.CWIDTH, App.CHEIGHT, defaultDpi, DirectXPixelFormat.R16G16B16A16Float, CanvasAlphaMode.Ignore)
        Surface2 = New CanvasRenderTarget(canvas1, App.CWIDTH, App.CHEIGHT, defaultDpi, DirectXPixelFormat.R16G16B16A16Float, CanvasAlphaMode.Ignore)
        App_Loaded()


        Dim kernelAddDL = KernelTracker.Generate({0, 0.5, 1},
                                              {Kernel.Center, Kernel.Up, Kernel.UpRight, Kernel.Right},
                                              Function(k)<commit_msg>Removed dependency on ColorF type, to just use BitConverter directly.<commit_after>﻿Imports System.Numerics
Imports Microsoft.Graphics.Canvas
Imports Microsoft.Graphics.Canvas.Effects
Imports Microsoft.Graphics.Canvas.UI.Xaml
Imports Windows.Graphics.DirectX
Imports Windows.UI


Public NotInheritable Class MainPageV1
    Inherits Page

    WithEvents App As App = App.Current
    WithEvents canvas1 As CanvasControl

    Dim Surface1, Surface2 As CanvasRenderTarget
    Dim StepEffectDL1, StepEffectDL2, StepEffectDR1, StepEffectDR2 As ConvolveMatrixEffect
    Dim StepEffectDL, StepEffectDR As ArithmeticCompositeEffect
    Dim DrawEffect1 As DpiCompensationEffect
    Dim DrawEffect2 As Transform2DEffect

    Dim Pen As Color = Colors.Gray

    Sub New()
        InitializeComponent()
        canvas1 = New CanvasControl
        container1.Children.Insert(0, canvas1)
    End Sub


    Sub App_Loaded() Handles App.Loaded
        If Surface1 Is Nothing Then Return
        Dim buf = New Byte(App.Pixels.Length * 16 - 1) {}
        For i = 0 To App.Pixels.Length - 1
            Dim c = App.Pixels(i)
            Array.Copy(BitConverter.GetBytes(CSng(c.R / 255)), 0, buf, i * 16 + 0, 4)
            Array.Copy(BitConverter.GetBytes(CSng(c.G / 255)), 0, buf, i * 16 + 4, 4)
            Array.Copy(BitConverter.GetBytes(CSng(c.B / 255)), 0, buf, i * 16 + 8, 4)
            Array.Copy(BitConverter.GetBytes(CSng(c.A / 255)), 0, buf, i * 16 + 12, 4)
        Next
        Surface1.SetPixelBytes(buf)
    End Sub

    Sub App_Unloading() Handles App.Unloading
        If Surface1 Is Nothing Then Return
        Dim buf = Surface1.GetPixelBytes()
        For i = 0 To App.Pixels.Length - 1
            Dim r = BitConverter.ToSingle(buf, i * 16 + 0)
            Dim g = BitConverter.ToSingle(buf, i * 16 + 4)
            Dim b = BitConverter.ToSingle(buf, i * 16 + 8)
            Dim a = BitConverter.ToSingle(buf, i * 16 + 12)
            App.Pixels(i) = Color.FromArgb(1, CByte(r * 255), CByte(g * 255), CByte(b * 255))
        Next
    End Sub


    Sub Canvas_CreateResources(sender As CanvasControl, args As Object) Handles canvas1.CreateResources
        Const defaultDpi = 96.0F
        Surface1 = New CanvasRenderTarget(canvas1, App.CWIDTH, App.CHEIGHT, defaultDpi, DirectXPixelFormat.R32G32B32A32Float, CanvasAlphaMode.Ignore)
        Surface2 = New CanvasRenderTarget(canvas1, App.CWIDTH, App.CHEIGHT, defaultDpi, DirectXPixelFormat.R32G32B32A32Float, CanvasAlphaMode.Ignore)
        App_Loaded()


        Dim kernelAddDL = KernelTracker.Generate({0, 0.5, 1},
                                              {Kernel.Center, Kernel.Up, Kernel.UpRight, Kernel.Right},
                                              Function(k)
{'fraction_non_alphanumeric': 0.0791974656810982, 'fraction_numerical': 0.034002111932418165, 'mean_word_length': 2.767700875099443, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1195075', 'n_tokens_mistral': 1549, 'n_tokens_neox': 1400, 'n_words': 379}