<commit_before>package cl11

import (
	"errors"
	"image"
	"unsafe"

	clw "github.com/rdwilliamson/clw11"
)

// A 2D or 3D image (Depth is 1 and SlicePitch is 0 for 2D images).
//
// TODO If Depth is 1 and SlicePitch is 0 it is ambiguous whether it is a 2D or
// 3D image.
type Image struct {
	id clw.Mem

	// The context the buffer was created on.
	Context *Context

	// The image format, the channel order and data type.
	Format ImageFormat

	// Size of each element of the image memory object
	ElementSize int

	// The width in pixels.
	Width int

	// The height in pixels.
	Height int

	// The depth in pixels. One for a 2D image.
	Depth int

	// Scan line width in bytes. Only valid if Host is not nil. If Host is not
	// nil then valid values are 0 (which is the same as Width * ElementSize) or
	// a value greater than or equal to Width * ElementSize.
	RowPitch int

	// The size in bytes of each 2D image in bytes. Only valid if Host is not
	// nil. valid values are 0 (which is the same as RowPitch * Height) or a
	// value greater than or equal to RowPitch * Height.
	SlicePitch int

	// Usage information for the buffer from the device's point of view.
	Flags MemFlags

	// The host backed memory for the buffer, if applicable.
	Host interface{}
}

type (
	MemObjectType clw.MemObjectType
	ChannelOrder  clw.ChannelOrder
	ChannelType   clw.ChannelType
)

type ImageFormat struct {
	ChannelOrder ChannelOrder
	ChannelType  ChannelType
}

const (
	R         = ChannelOrder(clw.R)
	A         = ChannelOrder(clw.A)
	RG        = ChannelOrder(clw.RG)
	RA        = ChannelOrder(clw.RA)
	RGB       = ChannelOrder(clw.RGB)
	RGBA      = ChannelOrder(clw.RGBA)
	BGRA      = ChannelOrder(clw.BGRA)
	ARGB      = ChannelOrder(clw.ARGB)
	Intensity = ChannelOrder(clw.Intensity)
	Luminance = ChannelOrder(clw.Luminance)
	Rx        = ChannelOrder(clw.Rx)
	RGx       = ChannelOrder(clw.RGx)
	RGBx      = ChannelOrder(clw.RGBx)
)

const (
	SnormInt8      = ChannelType(clw.SnormInt8)
	SnormInt16     = ChannelType(clw.SnormInt16)
	UnormInt8      = ChannelType(clw.UnormInt8)
	UnormInt16     = ChannelType(clw.UnormInt16)
	UnormShort565  = ChannelType(clw.UnormShort565)
	UnormShort555  = ChannelType(clw.UnormShort555)
	UnormInt101010 = ChannelType(clw.UnormInt101010)
	SignedInt8     = ChannelType(clw.SignedInt8)
	SignedInt16    = ChannelType(clw.SignedInt16)
	SignedInt32    = ChannelType(clw.SignedInt32)
	UnsignedInt8   = ChannelType(clw.UnsignedInt8)
	UnsignedInt16  = ChannelType(clw.UnsignedInt16)
	UnsignedInt32  = ChannelType(clw.UnsignedInt32)
	HalfFloat      = ChannelType(clw.HalfFloat)
	Float32        = ChannelType(clw.Float32)
)

const (
	MemObjectBuffer  = MemObjectType(clw.MemObjectBuffer)<commit_msg>Added string method for image format members.<commit_after>package cl11

import (
	"errors"
	"fmt"
	"image"
	"unsafe"

	clw "github.com/rdwilliamson/clw11"
)

// A 2D or 3D image (Depth is 1 and SlicePitch is 0 for 2D images).
//
// TODO If Depth is 1 and SlicePitch is 0 it is ambiguous whether it is a 2D or
// 3D image.
type Image struct {
	id clw.Mem

	// The context the buffer was created on.
	Context *Context

	// The image format, the channel order and data type.
	Format ImageFormat

	// Size of each element of the image memory object
	ElementSize int

	// The width in pixels.
	Width int

	// The height in pixels.
	Height int

	// The depth in pixels. One for a 2D image.
	Depth int

	// Scan line width in bytes. Only valid if Host is not nil. If Host is not
	// nil then valid values are 0 (which is the same as Width * ElementSize) or
	// a value greater than or equal to Width * ElementSize.
	RowPitch int

	// The size in bytes of each 2D image in bytes. Only valid if Host is not
	// nil. valid values are 0 (which is the same as RowPitch * Height) or a
	// value greater than or equal to RowPitch * Height.
	SlicePitch int

	// Usage information for the buffer from the device's point of view.
	Flags MemFlags

	// The host backed memory for the buffer, if applicable.
	Host interface{}
}

type (
	MemObjectType clw.MemObjectType
	ChannelOrder  clw.ChannelOrder
	ChannelType   clw.ChannelType
)

type ImageFormat struct {
	ChannelOrder ChannelOrder
	ChannelType  ChannelType
}

const (
	R         = ChannelOrder(clw.R)
	A         = ChannelOrder(clw.A)
	RG        = ChannelOrder(clw.RG)
	RA        = ChannelOrder(clw.RA)
	RGB       = ChannelOrder(clw.RGB)
	RGBA      = ChannelOrder(clw.RGBA)
	BGRA      = ChannelOrder(clw.BGRA)
	ARGB      = ChannelOrder(clw.ARGB)
	Intensity = ChannelOrder(clw.Intensity)
	Luminance = ChannelOrder(clw.Luminance)
	Rx        = ChannelOrder(clw.Rx)
	RGx       = ChannelOrder(clw.RGx)
	RGBx      = ChannelOrder(clw.RGBx)
)

func (co ChannelOrder) String() string {
	switch co {
	case R:
		return "R"
	case A:
		return "A"
	case RG:
		return "RG"
	case RA:
		return "RA"
	case RGB:
		return "RGB"
	case RGBA:
		return "RGBA"
	case BGRA:
		return "BGRA"
	case ARGB:
		return "ARGB"
	case Intensity:
		return "Intensity"
	case Luminance:
		return "Luminance"
	case Rx:
		return "Rx"
	case RGx:
		return "RGx"
	case RGBx:
		return "RGBx"
	default:
		return fmt.Sprintf("unknown (%x)", int(co))
	}
}

const (
	SnormInt8      = ChannelType(clw.SnormInt8)
	SnormInt16     = ChannelType(clw.SnormInt16)
	UnormInt8      = ChannelType(clw.UnormInt8)
	UnormInt16     = ChannelType(clw.UnormInt16)
	UnormShort565  = ChannelType(clw.UnormShort565)
	UnormShort555  = ChannelType(clw.UnormShort555)
	UnormInt101010 = ChannelType(clw.UnormInt101010)
	SignedInt8     = ChannelType(clw.SignedInt8)
	SignedInt16    = ChannelType(clw.SignedInt16)
	SignedInt32    = ChannelType(clw.SignedInt32)
	UnsignedInt8   = ChannelType(clw.UnsignedInt8)
	UnsignedInt16  = ChannelType(clw.UnsignedInt16)
	UnsignedInt32  = ChannelType(clw.UnsignedInt32)
	HalfFloat      = ChannelType(clw.HalfFloat)
	Float32        = ChannelType(clw.Float32)
)

func (ct ChannelType) String() string {
	switch ct {
	case SnormInt8:
		return "SnormInt8"
	case SnormInt16:
		return "SnormInt16"
	case UnormInt8:
		return "UnormInt8"
	case UnormInt16:
		return "UnormInt16"
	case UnormShort565:
		return "UnormShort565"
	case UnormShort555:
		return "UnormShort555"
	case UnormInt101010:
		return "UnormInt101010"
	case SignedInt8:
		return "SignedInt8"
	case SignedInt16:
		return "SignedInt16"
	case SignedInt32:
		return "SignedInt32"
	case UnsignedInt8:
		return "UnsignedInt8"
	case UnsignedInt16:
		return "UnsignedInt16"
	case UnsignedInt32:
		return "UnsignedInt32"
	case HalfFloat:
		return "HalfFloat"
	case Float32:
		return "Float32"
	default:
		return fmt.Sprintf("unknown (%x)", int(ct))
	}
}

const (
	MemObjectBuffer  = MemObjectType(clw.MemObjectBuffer)
{'fraction_non_alphanumeric': 0.08343319352905931, 'fraction_numerical': 0.032055122828040745, 'mean_word_length': 3.392763157894737, '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': '3759424', 'n_tokens_mistral': 2586, 'n_tokens_neox': 2382, 'n_words': 706}