<commit_before>
import QtQuick 2.0
import Sailfish.Silica 1.0
import tohiri.TohIR 1.0
import QtMultimedia 5.0
import Sailfish.Media 1.0
import "."

Page
{
    id: page

    SilicaFlickable
    {
        anchors.fill: parent

        PullDownMenu
        {
            id: pdm

            visible: !saveTimer.running

            MenuItem
            {
                text: "About"
                onClicked: pageStack.push(Qt.resolvedUrl("aboutPage.qml"),
                                          { "version": tohir.version } )
            }
            MenuItem
            {
                text: "Settings"
                onClicked:
                {
                    var dialog = pageStack.push(Qt.resolvedUrl("SettingsDialog.qml"),
                                          { "gradientOpacity": tohir.gradientOpacity,
                                            "updateRate": tohir.updateRate,
                                            "granularity": tohir.granularity } )
                    dialog.accepted.connect( function()
                    {
                        tohir.gradientOpacity = dialog.gradientOpacity
                        tohir.updateRate = dialog.updateRate
                        tohir.granularity = dialog.granularity
                        tohir.saveSettings()
                    } )
                }

            }
            MenuItem
            {
                text: "Save image"
                onClicked:
                {
                    saveTimer.start()
                }
            }
        }

        Camera
        {
            id: camera
            flash.mode: Camera.FlashOff
            captureMode: Camera.CaptureStillImage
            focus.focusMode: Camera.FocusContinuous
            onError:
            {
                console.error("error: " + camera.errorString);
            }
        }

        PageHeader
        {
            anchors.top: parent.top
            id: cameraHeader
            title: "TOH Infrared Imager"
        }

        GStreamerVideoOutput
        {
            id: videoPreview
            z: 1
            anchors.centerIn: parent
            source: camera
            width: 480
            //height: 480
        }

        Canvas
        {
            id: grad
            width: 8
            height: 8

            anchors.horizontalCenter: parent.horizontalCenter
            anchors.bottom: videoPreview.top

            onPaint:
            {
                var ctx = getContext('2d')

                var temps = tohir.temperatures

                var x=0;
                var y=0;

                for (var i=0; i<64 ; i++)
                {
                    ctx.beginPath();
                    ctx.lineWidth="1";
                    ctx.strokeStyle=temps[i]
                    ctx.rect(x,y,1,1);
                    ctx.stroke();
                    x=x+1;
                    if (x==8)
                    {
                        x=0;
                        y=y+1;
                    }
                }
            }
        }

        ShaderEffect
        {
            anchors.fill: videoPreview

            property variant videoSource: ShaderEffectSource { sourceItem: videoPreview; hideSource: true }
            property variant gradientSource: ShaderEffectSource { sourceItem: grad; hideSource: true }

            property real op : tohir.gradientOpacity

            fragmentShader:
                "
                varying highp vec2 qt_TexCoord0;

                uniform sampler2D videoSource;
                uniform sampler2D gradientSource;
                uniform highp float op;

                void main()
                {
                        gl_FragColor = texture2D(videoSource, qt_TexCoord0) + op * (texture2D(gradientSource, qt_TexCoord0) - texture2D(videoSource, qt_TexCoord0));
                }
                "
        }

        Rectangle
        {
            id: gridPlaceHolder
            width: 480
            height: 480
            color: "transparent"
            anchors.centerIn: parent
        }

//        /* the 8x8 grig for temperature gradient */
//        Grid
//        {
//            id: tempGrid
//            z: 2
//            columns: 8
//            anchors.centerIn: parent

//            Repeater
//            {
//                id: gradient
//                model: 64

//                Rectangle
//                {
//                    width: 60
//                    height: 60
//                    opacity: tohir.gradientOpacity
//                    color: "#000000"
//                    property string lab: ""
//                    Label
//                    {
//                        anchors.centerIn: parent
//                        text: parent.lab
//                        color: Theme.primaryColor
//                        font.pixelSize: Theme.fontSizeLarge
//                        font.bold: true
//                        horizontalAlignment: Text.AlignHCenter
//                        opacity: 1.0
//                    }
//                }
//            }
//        }

        Rectangle
        {
            id: mamBackground
            z: 2
            color: Theme.secondaryHighlightColor
            width: 480
            height: mamLabels.height + mamValues.height + 10
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: gridPlaceHolder.bottom //videoPreview.bottom
        }

        Row
        {
            id: mamLabels
            z: 3
            x: Theme.paddingLarge
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: mamBackground.top //videoPreview.bottom

            Label
            {
                width: page.width/3
                text: "min"
                color: Theme.secondaryColor
                font.pixelSize: Theme.fontSizeSmall
                horizontalAlignment: Text.AlignHCenter
            }<commit_msg>granularity integer<commit_after>
import QtQuick 2.0
import Sailfish.Silica 1.0
import tohiri.TohIR 1.0
import QtMultimedia 5.0
import Sailfish.Media 1.0
import "."

Page
{
    id: page

    SilicaFlickable
    {
        anchors.fill: parent

        PullDownMenu
        {
            id: pdm

            visible: !saveTimer.running

            MenuItem
            {
                text: "About"
                onClicked: pageStack.push(Qt.resolvedUrl("aboutPage.qml"),
                                          { "version": tohir.version } )
            }
            MenuItem
            {
                text: "Settings"
                onClicked:
                {
                    var dialog = pageStack.push(Qt.resolvedUrl("SettingsDialog.qml"),
                                          { "gradientOpacity": tohir.gradientOpacity,
                                            "updateRate": tohir.updateRate,
                                            "granularity": tohir.granularity } )
                    dialog.accepted.connect( function()
                    {
                        tohir.gradientOpacity = dialog.gradientOpacity
                        tohir.updateRate = dialog.updateRate
                        tohir.granularity = dialog.granularity
                        tohir.saveSettings()
                    } )
                }

            }
            MenuItem
            {
                text: "Save image"
                onClicked:
                {
                    saveTimer.start()
                }
            }
        }

        Camera
        {
            id: camera
            flash.mode: Camera.FlashOff
            captureMode: Camera.CaptureStillImage
            focus.focusMode: Camera.FocusContinuous
            onError:
            {
                console.error("error: " + camera.errorString);
            }
        }

        PageHeader
        {
            anchors.top: parent.top
            id: cameraHeader
            title: "TOH Infrared Imager"
        }

        GStreamerVideoOutput
        {
            id: videoPreview
            z: 1
            anchors.centerIn: parent
            source: camera
            width: 480
            //height: 480
        }

        Canvas
        {
            id: grad
            width: 8 * tohir.granularity
            height: 8 * tohir.granularity

            anchors.centerIn: gridPlaceHolder

            onPaint:
            {
                var ctx = getContext('2d')

                var temps = tohir.temperatures

                var x = 0;
                var y = 0;

                for (var i=0; i<64 ; i++)
                {
                    ctx.beginPath()
                    ctx.lineWidth = "1"
                    ctx.strokeStyle = temps[i]
                    ctx.fillStyle = temps[i]
                    ctx.fillRect(x, y, tohir.granularity, tohir.granularity)
                    ctx.stroke()

                    x = x + tohir.granularity
                    if (x >= width)
                    {
                        x = 0
                        y = y + tohir.granularity
                    }
                }
            }
        }

        ShaderEffect
        {
            anchors.fill: videoPreview

            property variant videoSource: ShaderEffectSource { sourceItem: videoPreview; hideSource: true }
            property variant gradientSource: ShaderEffectSource { sourceItem: grad; hideSource: true }

            property real op : tohir.gradientOpacity

            smooth: false /* afaik this sets GL_NEAREST  (true sets GL_LINEAR) */

            fragmentShader:
                "
                varying highp vec2 qt_TexCoord0;

                uniform sampler2D videoSource;
                uniform sampler2D gradientSource;
                uniform highp float op;

                void main()
                {
                        gl_FragColor = (0.8* texture2D(videoSource, qt_TexCoord0)) + op * (texture2D(gradientSource, qt_TexCoord0) - texture2D(videoSource, qt_TexCoord0));
                }
                "
        }

        Rectangle
        {
            id: gridPlaceHolder
            width: 480
            height: 480
            color: "transparent"
            anchors.centerIn: parent
        }

        Rectangle
        {
            id: mamBackground
            z: 2
            color: Theme.secondaryHighlightColor
            width: 480
            height: mamLabels.height + mamValues.height + 10
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: gridPlaceHolder.bottom //videoPreview.bottom
        }

        Row
        {
            id: mamLabels
            z: 3
            x: Theme.paddingLarge
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: mamBackground.top //videoPreview.bottom

            Label
            {
                width: page.width/3
                text: "min"
                color: Theme.secondaryColor
                font.pixelSize: Theme.fontSizeSmall
                horizontalAlignment: Text.AlignHCenter
            }
{'fraction_non_alphanumeric': 0.07100324792493684, 'fraction_numerical': 0.011457957416095272, 'mean_word_length': 0.9396325459317585, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6160181', 'n_tokens_mistral': 2856, 'n_tokens_neox': 2555, 'n_words': 541}