<commit_before>package grcode

// #cgo darwin pkg-config: zbar
// #cgo LDFLAGS: -lzbar
// #include <zbar.h>
import "C"
import (
	"image"
	_ "image/jpeg"
	_ "image/png"
	"log"
	"os"
)

type RawData string

func GetDataFromFile(imagePath string) (results []string, err error) {
	// TODO: read via libjpeg, libpng instead of Go
	//filePath := C.CString(imagePath)
	reader, err := os.Open(imagePath)
	if err != nil {
		log.Printf("open file error: %v", err)
		return results, err
	}
	defer reader.Close()
	m, _, err := image.Decode(reader)
	if err != nil {
		log.Printf("decode file error: %v", err)
		return results, err
	}
	scanner := NewScanner()
	defer scanner.Close()
	scanner.SetConfig(0, C.ZBAR_CFG_ENABLE, 1)
	zImg := NewZbarImage(m)
	defer zImg.Close()
	scanner.Scan(zImg)
	symbol := zImg.GetSymbol()
	for ; symbol != nil; symbol = symbol.Next() {
		results = append(results, symbol.Data())
	}
	return results, nil
}<commit_msg>implement function that reads from image.Image golang class<commit_after>package grcode

// #cgo darwin pkg-config: zbar
// #cgo LDFLAGS: -lzbar
// #include <zbar.h>
import "C"
import (
	"image"
	_ "image/jpeg"
	_ "image/png"
	"log"
	"os"
)

type RawData string

func GetDataFromFile(imagePath string) (results []string, err error) {
	// TODO: read via libjpeg, libpng instead of Go
	//filePath := C.CString(imagePath)
	reader, err := os.Open(imagePath)
	if err != nil {
		log.Printf("open file error: %v", err)
		return results, err
	}
	defer reader.Close()
	m, _, err := image.Decode(reader)
	if err != nil {
		log.Printf("decode file error: %v", err)
		return results, err
	}
	scanner := NewScanner()
	defer scanner.Close()
	scanner.SetConfig(0, C.ZBAR_CFG_ENABLE, 1)
	zImg := NewZbarImage(m)
	defer zImg.Close()
	scanner.Scan(zImg)
	symbol := zImg.GetSymbol()
	for ; symbol != nil; symbol = symbol.Next() {
		results = append(results, symbol.Data())
	}
	return results, nil
}

//GetDataFromImage read qrcode directly from golang Image class
func GetDataFromImage(image image.Image) (results []string, err error) {

	scanner := NewScanner()
	defer scanner.Close()
	scanner.SetConfig(0, C.ZBAR_CFG_ENABLE, 1)
	zImg := NewZbarImage(image)
	defer zImg.Close()
	scanner.Scan(zImg)
	symbol := zImg.GetSymbol()
	for ; symbol != nil; symbol = symbol.Next() {
		results = append(results, symbol.Data())
	}
	return results, nil
}
{'fraction_non_alphanumeric': 0.1464346349745331, 'fraction_numerical': 0.0025466893039049238, 'mean_word_length': 4.112798264642082, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3765134', 'n_tokens_mistral': 901, 'n_tokens_neox': 875, 'n_words': 235}