Skip to content

Commit

Permalink
chore: rename
Browse files Browse the repository at this point in the history
  • Loading branch information
dongwlin committed Sep 22, 2024
1 parent 191ad49 commit 888860e
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (ctx *Context) runRecognition(entry, override string, img image.Image) *Rec
cOverride := C.CString(override)
defer C.free(unsafe.Pointer(cOverride))
imgBuf := buffer.NewImageBuffer()
imgBuf.SetRawData(img)
imgBuf.Set(img)
defer imgBuf.Destroy()

recId := int64(C.MaaContextRunRecognition(ctx.handle, cEntry, cOverride, (*C.MaaImageBuffer)(imgBuf.Handle())))
Expand Down
2 changes: 1 addition & 1 deletion controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ func (c *controller) CacheImage() image.Image {
return nil
}

img := imgBuffer.GetByRawData()
img := imgBuffer.Get()

return img
}
Expand Down
2 changes: 1 addition & 1 deletion custom_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func _ScreencapAgent(handleArg unsafe.Pointer, imgBuffer *C.MaaImageBuffer) C.ui
img, captured := ctrl.Screencap()
if captured {
imgImgBuffer := buffer.NewImageBufferByHandle(unsafe.Pointer(imgBuffer))
if ok := imgImgBuffer.SetRawData(img); ok {
if ok := imgImgBuffer.Set(img); ok {
return C.uint8_t(1)
}
}
Expand Down
2 changes: 1 addition & 1 deletion custom_recognition.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func _MaaCustomRecognitionCallbackAgent(
tasker := context.GetTasker()
taskDetail := tasker.getTaskDetail(int64(taskId))
imgBuffer := buffer.NewImageBufferByHandle(unsafe.Pointer(img))
imgImg := imgBuffer.GetByRawData()
imgImg := imgBuffer.Get()

ret, ok := recognizer.Run(
&Context{handle: ctx},
Expand Down
8 changes: 4 additions & 4 deletions internal/buffer/image_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func (i *ImageBuffer) Clear() bool {
return C.MaaImageBufferClear(i.handle) != 0
}

// GetByRawData retrieves the image from raw data stored in the buffer.
func (i *ImageBuffer) GetByRawData() image.Image {
// Get retrieves the image from raw data stored in the buffer.
func (i *ImageBuffer) Get() image.Image {
rawData := i.getRawData()
if rawData == nil {
return nil
Expand All @@ -71,8 +71,8 @@ func (i *ImageBuffer) GetByRawData() image.Image {
return img
}

// SetRawData converts an image.Image to raw data and sets it in the buffer.
func (i *ImageBuffer) SetRawData(img image.Image) bool {
// Set converts an image.Image to raw data and sets it in the buffer.
func (i *ImageBuffer) Set(img image.Image) bool {
width := img.Bounds().Dx()
height := img.Bounds().Dy()
imageType := int32(16) // CV_8UC3
Expand Down
6 changes: 3 additions & 3 deletions internal/buffer/image_buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestImageBuffer_Clear(t *testing.T) {
require.True(t, got)
}

func TestImageBuffer_SetRawData(t *testing.T) {
func TestImageBuffer_Set(t *testing.T) {
imageBuffer := createImageBuffer(t)
defer imageBuffer.Destroy()

Expand All @@ -50,10 +50,10 @@ func TestImageBuffer_SetRawData(t *testing.T) {
img1.SetNRGBA(0, 1, color.NRGBA{R: 0, G: 0, B: 255, A: 255})
img1.SetNRGBA(1, 1, color.NRGBA{R: 255, G: 255, B: 255, A: 255})

got := imageBuffer.SetRawData(img1)
got := imageBuffer.Set(img1)
require.True(t, got)

img2 := imageBuffer.GetByRawData()
img2 := imageBuffer.Get()
require.NotNil(t, img2)
require.Equal(t, img1, img2)
}
2 changes: 1 addition & 1 deletion internal/buffer/image_list_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (il *ImageListBuffer) Get(index uint64) image.Image {
img := &ImageBuffer{
handle: handle,
}
return img.GetByRawData()
return img.Get()
}

func (il *ImageListBuffer) GetAll() []image.Image {
Expand Down
8 changes: 4 additions & 4 deletions internal/buffer/image_list_buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestImageListBuffer_Append(t *testing.T) {
img1.SetNRGBA(0, 1, color.NRGBA{R: 0, G: 0, B: 255, A: 255})
img1.SetNRGBA(1, 1, color.NRGBA{R: 255, G: 255, B: 255, A: 255})

got := imageBuffer.SetRawData(img1)
got := imageBuffer.Set(img1)
require.True(t, got)

appended := imageListBuffer.Append(imageBuffer)
Expand Down Expand Up @@ -81,7 +81,7 @@ func TestImageListBuffer_Remove(t *testing.T) {
img.SetNRGBA(0, 1, color.NRGBA{R: 0, G: 0, B: 255, A: 255})
img.SetNRGBA(1, 1, color.NRGBA{R: 255, G: 255, B: 255, A: 255})

got := imageBuffer.SetRawData(img)
got := imageBuffer.Set(img)
require.True(t, got)

appended := imageListBuffer.Append(imageBuffer)
Expand All @@ -108,7 +108,7 @@ func TestImageListBuffer_Size(t *testing.T) {
img1.SetNRGBA(0, 1, color.NRGBA{R: 0, G: 0, B: 255, A: 255})
img1.SetNRGBA(1, 1, color.NRGBA{R: 255, G: 255, B: 255, A: 255})

got := imageBuffer.SetRawData(img1)
got := imageBuffer.Set(img1)
require.True(t, got)

appended := imageListBuffer.Append(imageBuffer)
Expand All @@ -132,7 +132,7 @@ func TestImageListBuffer_GetAll(t *testing.T) {
img1.SetNRGBA(0, 1, color.NRGBA{R: 0, G: 0, B: 255, A: 255})
img1.SetNRGBA(1, 1, color.NRGBA{R: 255, G: 255, B: 255, A: 255})

got := imageBuffer.SetRawData(img1)
got := imageBuffer.Set(img1)
require.True(t, got)

appended := imageListBuffer.Append(imageBuffer)
Expand Down
2 changes: 1 addition & 1 deletion tasker.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (t *Tasker) getRecognitionDetail(recId int64) *RecognitionDetail {
return nil
}

rawImg := raw.GetByRawData()
rawImg := raw.Get()
DrawImages := draws.GetAll()

return &RecognitionDetail{
Expand Down

0 comments on commit 888860e

Please sign in to comment.