Skip to content

Commit

Permalink
Merge pull request #449 from go-vgo/bitmap-pr
Browse files Browse the repository at this point in the history
Update README.md and removed type_string_delayed
  • Loading branch information
vcaesar authored Jan 26, 2022
2 parents 9d145c0 + 5c0f1d3 commit 72167ef
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 259 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,16 @@ func main() {
imgo.Save("test.png", img)

num := robotgo.DisplaysNum()
for i := 0; i < num; i++ {
robotgo.DisplayID = i
img1 := robotgo.CaptureImg()
for i := 0; i < num; i++ {
robotgo.DisplayID = i
img1 := robotgo.CaptureImg()
path1 := "save_" + strconv.Itoa(i)
robotgo.Save(img1, path1+".png")
robotgo.SaveJpeg(img1, path1+".jpeg", 50)
robotgo.Save(img1, path1+".png")
robotgo.SaveJpeg(img1, path1+".jpeg", 50)

img2 := robotgo.CaptureImg(10, 10, 20, 20)
robotgo.Save(img2, "test_"+strconv.Itoa(i)+".png")
}
img2 := robotgo.CaptureImg(10, 10, 20, 20)
robotgo.Save(img2, "test_"+strconv.Itoa(i)+".png")
}
}
```

Expand Down
11 changes: 3 additions & 8 deletions base/bitmap_free_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@
#include <assert.h>
#include <string.h>

MMBitmapRef createMMBitmap_c(
uint8_t *buffer,
size_t width,
size_t height,
size_t bytewidth,
uint8_t bitsPerPixel,
uint8_t bytesPerPixel
){
MMBitmapRef createMMBitmap_c(uint8_t *buffer, size_t width, size_t height,
size_t bytewidth, uint8_t bitsPerPixel, uint8_t bytesPerPixel
) {
MMBitmapRef bitmap = malloc(sizeof(MMBitmap));
if (bitmap == NULL) { return NULL; }

Expand Down
2 changes: 1 addition & 1 deletion base/endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
#define bitswap16(i) bswap_16(i) /* Linux system function */
#else /* Default macro */
#define bitswap16(i) (((uint16_t)(i) & 0xFF00) >> 8) | \
(((uint16_t)(i) & 0x00FF) << 8)
(((uint16_t)(i) & 0x00FF) << 8)
#endif
#endif /* bitswap16 */

Expand Down
2 changes: 0 additions & 2 deletions base/ms_stdbool.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#define __bool_true_false_are_defined 1

#ifndef __cplusplus

#if defined(true) || defined(false) || defined(bool)
#error "Boolean type already defined"
#endif
Expand All @@ -21,7 +20,6 @@
};

typedef unsigned char bool;

#endif /* !__cplusplus */

#endif /* MS_STDBOOL_H */
15 changes: 4 additions & 11 deletions base/rgb.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <stdint.h>
#endif


/* RGB colors in MMBitmaps are stored as BGR for convenience in converting
* to/from certain formats (mainly OpenGL).
*
Expand Down Expand Up @@ -46,8 +45,7 @@ typedef uint32_t MMRGBHex;
#define RGB_TO_HEX(red, green, blue) (((red) << 16) | ((green) << 8) | (blue))

/* Convenience wrapper for MMRGBColors. */
H_INLINE MMRGBHex hexFromMMRGB(MMRGBColor rgb)
{
H_INLINE MMRGBHex hexFromMMRGB(MMRGBColor rgb) {
return RGB_TO_HEX(rgb.red, rgb.green, rgb.blue);
}

Expand All @@ -56,8 +54,7 @@ H_INLINE MMRGBHex hexFromMMRGB(MMRGBColor rgb)
#define BLUE_FROM_HEX(hex) (hex & 0xFF)

/* Converts hexadecimal color to MMRGBColor. */
H_INLINE MMRGBColor MMRGBFromHex(MMRGBHex hex)
{
H_INLINE MMRGBColor MMRGBFromHex(MMRGBHex hex) {
MMRGBColor color;
color.red = RED_FROM_HEX(hex);
color.green = GREEN_FROM_HEX(hex);
Expand All @@ -73,9 +70,7 @@ H_INLINE MMRGBColor MMRGBFromHex(MMRGBHex hex)
/* Returns whether two colors are similar within the given range, |tolerance|.
* Tolerance can be in the range 0.0f - 1.0f, where 0 denotes the exact
* color and 1 denotes any color. */
H_INLINE int MMRGBColorSimilarToColor(MMRGBColor c1, MMRGBColor c2,
float tolerance)
{
H_INLINE int MMRGBColorSimilarToColor(MMRGBColor c1, MMRGBColor c2, float tolerance) {
/* Speedy case */
if (tolerance <= 0.0f) {
return MMRGBColorEqualToColor(c1, c2);
Expand All @@ -87,12 +82,10 @@ H_INLINE int MMRGBColorSimilarToColor(MMRGBColor c1, MMRGBColor c2,
(d2 * d2) +
(d3 * d3)) <= (tolerance * 442.0f);
}

}

/* Identical to MMRGBColorSimilarToColor, only for hex values. */
H_INLINE int MMRGBHexSimilarToColor(MMRGBHex h1, MMRGBHex h2, float tolerance)
{
H_INLINE int MMRGBHexSimilarToColor(MMRGBHex h1, MMRGBHex h2, float tolerance) {
if (tolerance <= 0.0f) {
return h1 == h2;
} else {
Expand Down
42 changes: 12 additions & 30 deletions base/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <stdint.h>

/* Some generic, cross-platform types. */

#ifdef RobotGo_64
typedef int64_t intptr;
typedef uint64_t uintptr;
Expand All @@ -21,87 +20,74 @@ struct _MMPoint {
size_t x;
size_t y;
};

typedef struct _MMPoint MMPoint;

struct _MMPointInt32 {
int32_t x;
int32_t y;
};

typedef struct _MMPointInt32 MMPointInt32;

struct _MMSize {
size_t width;
size_t height;
};

typedef struct _MMSize MMSize;

struct _MMSizeInt32 {
int32_t w;
int32_t h;
};

typedef struct _MMSizeInt32 MMSizeInt32;


struct _MMRect {
MMPoint origin;
MMSize size;
};

typedef struct _MMRect MMRect;

struct _MMRectInt32 {
MMPointInt32 origin;
MMSizeInt32 size;
};

typedef struct _MMRectInt32 MMRectInt32;

H_INLINE MMPoint MMPointMake(size_t x, size_t y)
{
H_INLINE MMPoint MMPointMake(size_t x, size_t y) {
MMPoint point;
point.x = x;
point.y = y;
return point;
}

H_INLINE MMPointInt32 MMPointInt32Make(int32_t x, int32_t y)
{
H_INLINE MMPointInt32 MMPointInt32Make(int32_t x, int32_t y) {
MMPointInt32 point;
point.x = x;
point.y = y;
return point;
}

H_INLINE MMSize MMSizeMake(size_t width, size_t height)
{
H_INLINE MMSize MMSizeMake(size_t width, size_t height) {
MMSize size;
size.width = width;
size.height = height;
return size;
}

H_INLINE MMSizeInt32 MMSizeInt32Make(int32_t w, int32_t h)
{
H_INLINE MMSizeInt32 MMSizeInt32Make(int32_t w, int32_t h) {
MMSizeInt32 size;
size.w = w;
size.h = h;
return size;
}

H_INLINE MMRect MMRectMake(size_t x, size_t y, size_t width, size_t height)
{
H_INLINE MMRect MMRectMake(size_t x, size_t y, size_t width, size_t height) {
MMRect rect;
rect.origin = MMPointMake(x, y);
rect.size = MMSizeMake(width, height);
return rect;
}

H_INLINE MMRectInt32 MMRectInt32Make(int32_t x, int32_t y, int32_t w, int32_t h)
{
H_INLINE MMRectInt32 MMRectInt32Make(int32_t x, int32_t y, int32_t w, int32_t h) {
MMRectInt32 rect;
rect.origin = MMPointInt32Make(x, y);
rect.size = MMSizeInt32Make(w, h);
Expand All @@ -112,18 +98,14 @@ H_INLINE MMRectInt32 MMRectInt32Make(int32_t x, int32_t y, int32_t w, int32_t h)
#define MMPointZero MMPointMake(0, 0)

#if defined(IS_MACOSX)
#define CGPointFromMMPoint(p) CGPointMake((CGFloat)(p).x, (CGFloat)(p).y)
#define MMPointFromCGPoint(p) MMPointMake((size_t)(p).x, (size_t)(p).y)

#define CGPointFromMMPoint(p) CGPointMake((CGFloat)(p).x, (CGFloat)(p).y)
#define MMPointFromCGPoint(p) MMPointMake((size_t)(p).x, (size_t)(p).y)

#define CGPointFromMMPointInt32(p) CGPointMake((CGFloat)(p).x, (CGFloat)(p).y)
#define MMPointInt32FromCGPoint(p) MMPointInt32Make((int32_t)(p).x, (int32_t)(p).y)

#define CGPointFromMMPointInt32(p) CGPointMake((CGFloat)(p).x, (CGFloat)(p).y)
#define MMPointInt32FromCGPoint(p) MMPointInt32Make((int32_t)(p).x, (int32_t)(p).y)
#elif defined(IS_WINDOWS)

#define MMPointFromPOINT(p) MMPointMake((size_t)p.x, (size_t)p.y)
#define MMPointInt32FromPOINT(p) MMPointInt32Make((int32_t)p.x, (int32_t)p.y)

#define MMPointFromPOINT(p) MMPointMake((size_t)p.x, (size_t)p.y)
#define MMPointInt32FromPOINT(p) MMPointInt32Make((int32_t)p.x, (int32_t)p.y)
#endif

#endif /* TYPES_H */
1 change: 0 additions & 1 deletion base/win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@
// printf("%d\n", info.hWnd);
return info.hWnd;
}

#endif
18 changes: 6 additions & 12 deletions key/goKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,23 +172,23 @@ int CheckKeyCodes(char* k, MMKeyCode *key){
int CheckKeyFlags(char* f, MMKeyFlags* flags){
if (!flags) { return -1; }

if ( strcmp(f, "alt") == 0 || strcmp(f, "ralt") == 0 ||
if (strcmp(f, "alt") == 0 || strcmp(f, "ralt") == 0 ||
strcmp(f, "lalt") == 0 ) {
*flags = MOD_ALT;
}
else if( strcmp(f, "command") == 0 || strcmp(f, "cmd") == 0 ||
else if(strcmp(f, "command") == 0 || strcmp(f, "cmd") == 0 ||
strcmp(f, "rcmd") == 0 || strcmp(f, "lcmd") == 0 ) {
*flags = MOD_META;
}
else if( strcmp(f, "control") == 0 || strcmp(f, "ctrl") == 0 ||
else if(strcmp(f, "control") == 0 || strcmp(f, "ctrl") == 0 ||
strcmp(f, "rctrl") == 0 || strcmp(f, "lctrl") == 0 ) {
*flags = MOD_CONTROL;
}
else if( strcmp(f, "shift") == 0 || strcmp(f, "right_shift") == 0 ||
else if(strcmp(f, "shift") == 0 || strcmp(f, "right_shift") == 0 ||
strcmp(f, "rshift") == 0 || strcmp(f, "lshift") == 0 ) {
*flags = MOD_SHIFT;
}
else if( strcmp(f, "none") == 0 ) {
else if(strcmp(f, "none") == 0 ) {
*flags = (MMKeyFlags) MOD_NONE;
} else {
return -2;
Expand Down Expand Up @@ -332,6 +332,7 @@ char* key_Toggles(char* k, char* keyArr[], int num) {
return "";
}

// remove
char* key_toggle(char* k, char* d, char* akey, char* keyT){
MMKeyFlags flags = (MMKeyFlags) MOD_NONE;
MMKeyCode key;
Expand Down Expand Up @@ -390,13 +391,6 @@ char* key_toggle(char* k, char* d, char* akey, char* keyT){
return "";
}

void type_string(char *str){
typeStringDelayed(str, 0);
}

void type_string_delayed(char *str, size_t cpm){
typeStringDelayed(str, cpm);
}

void set_keyboard_delay(size_t val){
keyboardDelay = val;
Expand Down
51 changes: 17 additions & 34 deletions key/keycode_c.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
#include "keycode.h"

#if defined(IS_MACOSX)
#include <CoreFoundation/CoreFoundation.h>
#include <Carbon/Carbon.h> /* For kVK_ constants, and TIS functions. */

#include <CoreFoundation/CoreFoundation.h>
#include <Carbon/Carbon.h> /* For kVK_ constants, and TIS functions. */

/* Returns string representation of key, if it is printable.
* Ownership follows the Create Rule; that is, it is the caller's
* responsibility to release the returned object. */
CFStringRef createStringForKey(CGKeyCode keyCode);

MMKeyCode keyCodeForCharFallBack(const char c);
/* Returns string representation of key, if it is printable.
* Ownership follows the Create Rule; that is, it is the caller's
* responsibility to release the returned object. */
CFStringRef createStringForKey(CGKeyCode keyCode);

MMKeyCode keyCodeForCharFallBack(const char c);
#elif defined(USE_X11)

/*
* Structs to store key mappings not handled by XStringToKeysym() on some
* Linux systems.
Expand Down Expand Up @@ -77,11 +74,9 @@ MMKeyCode keyCodeForChar(const char c){
/* Generate table of keycodes and characters. */
if (charToCodeDict == NULL) {
size_t i;
charToCodeDict = CFDictionaryCreateMutable(kCFAllocatorDefault,
128,
&kCFCopyStringDictionaryKeyCallBacks,
NULL);
if (charToCodeDict == NULL) return K_NOT_A_KEY;
charToCodeDict = CFDictionaryCreateMutable(kCFAllocatorDefault, 128,
&kCFCopyStringDictionaryKeyCallBacks, NULL);
if (charToCodeDict == NULL) { return K_NOT_A_KEY; }

/* Loop through every keycode (0 - 127) to find its current mapping. */
for (i = 0; i < 128; ++i) {
Expand Down Expand Up @@ -135,7 +130,7 @@ MMKeyCode keyCodeForChar(const char c){
* mapping table. */
struct XSpecialCharacterMapping* xs = XSpecialCharacterTable;
while (xs->name) {
if (c == xs->name ) {
if (c == xs->name) {
code = xs->code;
//
break;
Expand All @@ -152,34 +147,22 @@ MMKeyCode keyCodeForChar(const char c){
#endif
}


#if defined(IS_MACOSX)

CFStringRef createStringForKey(CGKeyCode keyCode){
TISInputSourceRef currentKeyboard = TISCopyCurrentASCIICapableKeyboardInputSource();
CFDataRef layoutData =
(CFDataRef)TISGetInputSourceProperty(currentKeyboard,
kTISPropertyUnicodeKeyLayoutData);
CFDataRef layoutData = (CFDataRef) TISGetInputSourceProperty(
currentKeyboard, kTISPropertyUnicodeKeyLayoutData);

if (layoutData == nil) { return 0; }

const UCKeyboardLayout *keyboardLayout =
(const UCKeyboardLayout *)CFDataGetBytePtr(layoutData);

const UCKeyboardLayout *keyboardLayout = (const UCKeyboardLayout *) CFDataGetBytePtr(layoutData);
UInt32 keysDown = 0;
UniChar chars[4];
UniCharCount realLength;

UCKeyTranslate(keyboardLayout,
keyCode,
kUCKeyActionDisplay,
0,
LMGetKbdType(),
kUCKeyTranslateNoDeadKeysBit,
&keysDown,
sizeof(chars) / sizeof(chars[0]),
&realLength,
chars);
UCKeyTranslate(keyboardLayout, keyCode, kUCKeyActionDisplay, 0, LMGetKbdType(),
kUCKeyTranslateNoDeadKeysBit, &keysDown,
sizeof(chars) / sizeof(chars[0]), &realLength, chars);
CFRelease(currentKeyboard);

return CFStringCreateWithCharacters(kCFAllocatorDefault, chars, 1);
Expand Down
Loading

0 comments on commit 72167ef

Please sign in to comment.