robotgo/bitmap/goBitmap.h

118 lines
2.7 KiB
C
Raw Permalink Normal View History

2016-11-10 06:34:13 +00:00
// Copyright 2016 The go-vgo Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
2016-12-10 18:41:08 +00:00
// https://github.com/go-vgo/robotgo/blob/master/LICENSE
2016-11-10 06:34:13 +00:00
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
2016-10-19 17:10:10 +00:00
// class BMP
// {
// public:
// size_t width;
// size_t height;
// size_t byteWidth;
// uint8_t bitsPerPixel;
// uint8_t bytesPerPixel;
// uint8_t *image;
// };
#include "bitmap_class.h"
2016-11-13 16:01:21 +00:00
#include "bitmap_find_c.h"
2016-11-17 08:00:00 +00:00
#include "../base/color_find_c.h"
2016-11-13 16:01:21 +00:00
// #include "../screen/screen_c.h"
2016-11-17 08:00:00 +00:00
#include "../base/io_c.h"
#include "../base/pasteboard_c.h"
#include "../base/str_io_c.h"
2016-10-19 17:10:10 +00:00
#include <assert.h>
#include <stdio.h>
2017-06-06 14:56:48 +00:00
/* Returns false and sets error if |bitmap| is NULL. */
bool bitmap_ready(MMBitmapRef bitmap){
if (bitmap == NULL || bitmap->imageBuffer == NULL) {
return false;
}
return true;
}
void bitmap_dealloc(MMBitmapRef bitmap){
if (bitmap != NULL) {
destroyMMBitmap(bitmap);
bitmap = NULL;
}
}
bool bitmap_copy_to_pboard(MMBitmapRef bitmap){
MMPasteError err;
if (!bitmap_ready(bitmap)) return false;
if ((err = copyMMBitmapToPasteboard(bitmap)) != kMMPasteNoError) {
return false;
}
return true;
}
2017-06-29 14:50:53 +00:00
MMBitmapRef bitmap_deepcopy(MMBitmapRef bitmap){
return bitmap == NULL ? NULL : copyMMBitmap(bitmap);
}
2017-05-10 05:50:28 +00:00
MMPoint aFindBitmap(MMBitmapRef bit_map, MMRect rect){
2016-10-23 15:39:09 +00:00
// MMRect rect;
2017-05-09 13:56:22 +00:00
// rect.size.width = 10;
// rect.size.height = 20;
// rect.origin.x = 10;
// rect.origin.y = 20;
2016-10-20 11:22:11 +00:00
float tolerance = 0.0f;
MMPoint point;
2017-05-09 13:56:22 +00:00
tolerance = 0.5;
2016-10-20 11:22:11 +00:00
if (findBitmapInRect(bit_map, bit_map, &point,
rect, tolerance) == 0) {
return point;
}
return point;
}
MMBitmapRef bitmap_open(char *path, uint16_t ttype){
2016-10-30 11:16:03 +00:00
// MMImageType type;
2016-10-19 17:10:10 +00:00
MMBitmapRef bitmap;
MMIOError err;
2016-10-30 11:16:03 +00:00
bitmap = newMMBitmapFromFile(path, ttype, &err);
2017-05-10 13:04:55 +00:00
// printf("....%zd\n", bitmap->width);
2016-10-19 17:10:10 +00:00
return bitmap;
}
char *bitmap_save(MMBitmapRef bitmap, char *path, uint16_t type){
2017-05-10 13:04:55 +00:00
if (saveMMBitmapToFile(bitmap, path, (MMImageType) type) != 0) {
2016-10-19 17:10:10 +00:00
return "Could not save image to file.";
}else{
2016-10-20 10:04:41 +00:00
saveMMBitmapToFile(bitmap, path, (MMImageType) type);
2016-10-19 17:10:10 +00:00
}
//destroyMMBitmap(bitmap);
return "ok";
}
char *aTostringBitmap(MMBitmapRef bitmap){
char *buf = NULL;
MMBMPStringError err;
buf = (char *)createStringFromMMBitmap(bitmap, &err);
return buf;
}
2016-10-23 15:39:09 +00:00
2017-05-10 13:04:55 +00:00
MMBitmapRef aGetPortion(MMBitmapRef bit_map, MMRect rect){
2016-10-23 15:39:09 +00:00
// MMRect rect;
MMBitmapRef portion = NULL;
portion = copyMMBitmapFromPortion(bit_map, rect);
return portion;
}