add more color processing and conversion

This commit is contained in:
vcaesar 2017-12-25 17:05:10 +08:00
parent bb7518a04a
commit 4f85eb5056
2 changed files with 62 additions and 8 deletions

View File

@ -62,7 +62,7 @@ import (
)
const (
version string = "v0.47.0.460, Mount Cook!"
version string = "v0.47.0.461, Mount Cook!"
)
type (
@ -114,6 +114,40 @@ func Try(fun func(), handler func(interface{})) {
|_______/ \______|| _| `._____||_______||_______||__| \__|
*/
// ToMMRGBHex trans CHex to C.MMRGBHex
func ToMMRGBHex(hex CHex) C.MMRGBHex {
return C.MMRGBHex(hex)
}
// U32ToHex trans C.uint32_t to C.MMRGBHex
func U32ToHex(hex C.uint32_t) C.MMRGBHex {
return C.MMRGBHex(hex)
}
// U8ToHex teans *C.uint8_t to C.MMRGBHex
func U8ToHex(hex *C.uint8_t) C.MMRGBHex {
return C.MMRGBHex(*hex)
}
// PadHex trans C.MMRGBHex to string
func PadHex(hex C.MMRGBHex) string {
color := C.pad_hex(hex)
gcolor := C.GoString(color)
defer C.free(unsafe.Pointer(color))
return gcolor
}
// HexToRgb trans hex to rgb
func HexToRgb(hex uint32) *C.uint8_t {
return C.color_hex_to_rgb(C.uint32_t(hex))
}
// RgbToHex trans rgb to hex
func RgbToHex(r, g, b uint8) C.uint32_t {
return C.color_rgb_to_hex(C.uint8_t(r), C.uint8_t(g), C.uint8_t(b))
}
// GetPxColor get pixel color return C.MMRGBHex
func GetPxColor(x, y int) C.MMRGBHex {
cx := C.size_t(x)
@ -123,11 +157,6 @@ func GetPxColor(x, y int) C.MMRGBHex {
return color
}
// ToMMRGBHex trans CHex to C.MMRGBhex
func ToMMRGBHex(hex CHex) C.MMRGBHex {
return C.MMRGBHex(hex)
}
// GetPixelColor get pixel color return string
func GetPixelColor(x, y int) string {
cx := C.size_t(x)

View File

@ -9,6 +9,7 @@
// except according to those terms.
#include "../base/types.h"
#include "../base/rgb.h"
#include "screengrab_c.h"
#include "screen_c.h"
// #include "../MMBitmap_c.h"
@ -19,6 +20,31 @@ void padHex(MMRGBHex color, char* hex){
snprintf(hex, 7, "%06x", color);
}
char* pad_hex(MMRGBHex color){
char hex[7];
padHex(color, hex);
// destroyMMBitmap(bitmap);
char* str = (char*)calloc(100, sizeof(char*));
if(str)strcpy(str, hex);
return str;
}
static uint8_t rgb[3];
uint8_t *color_hex_to_rgb(uint32_t h){
rgb[0] = RED_FROM_HEX(h);
rgb[1] = GREEN_FROM_HEX(h);
rgb[2] = BLUE_FROM_HEX(h);
return rgb;
}
uint32_t color_rgb_to_hex(uint8_t r, uint8_t g, uint8_t b){
return RGB_TO_HEX(r, g, b);
}
MMRGBHex get_Pixel_Color(size_t x, size_t y){
MMBitmapRef bitmap;
MMRGBHex color;
@ -97,8 +123,7 @@ MMBitmapRef capture_screen(size_t x, size_t y, size_t w, size_t h){
// if (){
// x = 0;
// y = 0;
// //Get screen size.
// // Get screen size.
// MMSize displaySize = getMainDisplaySize();
// w = displaySize.width;
// h = displaySize.height;