<commit_before>package main

import (
	"bytes"
	"image"
	_ "image/jpeg"
	_ "image/png"
	"io"
	"os"
	"syscall"
	"unsafe"

	"github.com/develed/develed/imconv"
	srv "github.com/develed/develed/services"
	"golang.org/x/net/context"
)

const (
	cResetDuration = 60 // [us]
	cBytePerUSec   = 5
)

var resetCmd [cResetDuration * cBytePerUSec]byte

// DeviceSink serializes images to a character device using the appropriate
// timings and parameters.
type DeviceSink struct {
	dev *os.File
}

// NewDeviceSink create a new DeviceSink using the device specified by devname.
// If no such device exists or the process lacks permissions to access it,
// an error is returned. Otherwise, the device is initialized with the correct
// parameters.
func NewDeviceSink(devname string) (*DeviceSink, error) {
	out, err := os.OpenFile(devname, os.O_WRONLY, os.ModeCharDevice)
	if err != nil {
		return nil, err
	}

	// configure sample format
	sampleFormatIoctl := 0xc0045005
	sampleSize := 0x00002000 /* AFMT_S32_BE */
	syscall.Syscall(
		syscall.SYS_IOCTL,
		out.Fd(),
		uintptr(sampleFormatIoctl),
		uintptr(unsafe.Pointer(&sampleSize)))

	return &DeviceSink{
		dev: out,
	}, nil
}

func (ds *DeviceSink) Draw(ctx context.Context, req *srv.DrawRequest) (*srv.DrawResponse, error) {
	img, _, err := image.Decode(bytes.NewReader(req.Data))
	if err != nil {
		return nil, err
	}

	if err := blitImage(img, ds.dev); err != nil {
		return nil, err
	}
	if err := sendResetCmd(ds.dev); err != nil {
		return nil, err
	}

	return &srv.DrawResponse{Code: 0, Status: "OK"}, nil<commit_msg>dspd: fix overflow on ARM builds<commit_after>package main

import (
	"bytes"
	"image"
	_ "image/jpeg"
	_ "image/png"
	"io"
	"os"
	"syscall"
	"unsafe"

	"github.com/develed/develed/imconv"
	srv "github.com/develed/develed/services"
	"golang.org/x/net/context"
)

const (
	cResetDuration = 60 // [us]
	cBytePerUSec   = 5
)

var resetCmd [cResetDuration * cBytePerUSec]byte

// DeviceSink serializes images to a character device using the appropriate
// timings and parameters.
type DeviceSink struct {
	dev *os.File
}

// NewDeviceSink create a new DeviceSink using the device specified by devname.
// If no such device exists or the process lacks permissions to access it,
// an error is returned. Otherwise, the device is initialized with the correct
// parameters.
func NewDeviceSink(devname string) (*DeviceSink, error) {
	out, err := os.OpenFile(devname, os.O_WRONLY, os.ModeCharDevice)
	if err != nil {
		return nil, err
	}

	// configure sample format
	sampleFormatIoctl := uint32(0xc0045005)
	sampleSize := 0x00002000 /* AFMT_S32_BE */
	syscall.Syscall(
		syscall.SYS_IOCTL,
		out.Fd(),
		uintptr(sampleFormatIoctl),
		uintptr(unsafe.Pointer(&sampleSize)))

	return &DeviceSink{
		dev: out,
	}, nil
}

func (ds *DeviceSink) Draw(ctx context.Context, req *srv.DrawRequest) (*srv.DrawResponse, error) {
	img, _, err := image.Decode(bytes.NewReader(req.Data))
	if err != nil {
		return nil, err
	}

	if err := blitImage(img, ds.dev); err != nil {
		return nil, err
	}
	if err := sendResetCmd(ds.dev); err != nil {
		return nil, err
	}

	return &srv.DrawResponse{Code: 0, Status: "OK"}, nil
{'fraction_non_alphanumeric': 0.12440645773979107, 'fraction_numerical': 0.015194681861348529, 'mean_word_length': 4.0, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3698661', 'n_tokens_mistral': 1205, 'n_tokens_neox': 1120, 'n_words': 314}