Browse Source

draw point finished

master
blobt 5 years ago
parent
commit
2acc814d5f
  1. 5933
      src/CELLMath.hpp
  2. 5
      src/CMakeLists.txt
  3. 71
      src/Rester.cc
  4. 32
      src/Rester.h
  5. 61
      src/Rgba.cc
  6. 12
      src/Rgba.h
  7. 29
      src/common.h
  8. 16
      src/gtktest.cc
  9. 23
      src/tt.cc

5933
src/CELLMath.hpp
File diff suppressed because it is too large
View File

5
src/CMakeLists.txt

@ -1,5 +1,8 @@
add_executable(gtktest gtktest.cc Rgba.cc)
add_executable(gtktest gtktest.cc Rgba.cc Rester.cc)
target_link_libraries (gtktest ${FC_DEP_LIBS})
add_executable(timer timer.cc)
target_link_libraries (timer ${FC_DEP_LIBS})
add_executable(tt tt.cc Rgba.cc)
target_link_libraries (timer ${FC_DEP_LIBS})

71
src/Rester.cc

@ -0,0 +1,71 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: Rester.cc
* Author: blobt
*
* Created on January 23, 2020, 6:00 PM
*/
#include "Rgba.h"
#include "Rester.h"
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;
Rester::Rester(int width, int height) {
_width = width;
_height = height;
buffer = new Rgba[width * height];
}
Rester::~Rester() {
delete buffer;
}
void Rester::drawPointer(int x, int y, Rgba color, int pointSize) {
switch (pointSize) {
case 1:
setPixel(x, y, color);
case 2:
setPixel(x, y, color);
setPixel(x + 1, y, color);
setPixel(x, y + 1, color);
setPixel(x + 1, y + 1, color);
case 3:
setPixel(x - 1, y - 1, color);
setPixel(x, y - 1, color);
setPixel(x + 1, y - 1, color);
setPixel(x - 1, y, color);
setPixel(x, y, color);
setPixel(x + 1, y, color);
setPixel(x - 1, y + 1, color);
setPixel(x, y + 1, color);
setPixel(x + 1, y + 1, color);
}
}
int Rester::size() {
return _width * _height * sizeof (Rgba);
}
void Rester::clean() {
memset(buffer, 0, size());
}
bool Rester::setPixel(int x, int y, Rgba color) {
if (x < 0 || y < 0 || x >= 500 || y >= 500) {
return false;
}
//行列是反的
buffer[y * _width + x] = color;
}

32
src/Rester.h

@ -0,0 +1,32 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: Rester.h
* Author: blobt
*
* Created on January 23, 2020, 6:00 PM
*/
#ifndef RESTER_H
#define RESTER_H
class Rester {
public:
Rgba* buffer;
Rester(int width, int height);
virtual ~Rester();
void drawPointer(int x, int y, Rgba color, int pointSize = 1);
int size();
void clean();
bool setPixel(int x, int y, Rgba color);
private:
int _width;
int _height;
};
#endif /* RESTER_H */

61
src/Rgba.cc

@ -8,18 +8,65 @@
* File: Rgba.cc
* Author: Blobt
*
* Created on January 22, 2020, 9:14 PM
* Created on January 22, 2020, 11:36 PM
*/
#include <bitset>
#include <iostream>
#include "Rgba.h"
Rgba::Rgba() {
_r = 255;
_g = 255;
_b = 255;
_a = 255;
using namespace std;
Rgba::Rgba(unsigned char r, unsigned char g, unsigned char b, unsigned char a) {
_r = r;
_g = g;
_b = b;
_a = a;
}
bool operator==(Rgba &left, Rgba &right) {
return left._a == right._a && left._b == right._b && left._g == right._g && left._r == right._r;
}
Rgba::~Rgba() {
bool operator!=(Rgba &left, Rgba &right) {
return left._a != right._a || left._b != right._b || left._g != right._g || left._r != right._r;
}
Rgba::operator unsigned() {
unsigned int ret;
unsigned char* p = (unsigned char*)&ret;
p[0] = _r;
p[1] = _g;
p[2] = _b;
p[3] = _a;
//bitset<32> set = ret;
//cout << set << endl;
return ret;
}
Rgba::operator int() {
int ret;
unsigned char* p = (unsigned char*)&ret;
p[0] = _r;
p[1] = _g;
p[2] = _b;
p[3] = _a;
return ret;
}
Rgba::operator long() {
long ret;
unsigned char* p = (unsigned char*)&ret ;
p[0] = _r;
p[1] = _g;
p[2] = _b;
p[3] = _a;
return ret;
}

12
src/Rgba.h

@ -8,7 +8,7 @@
* File: Rgba.h
* Author: Blobt
*
* Created on January 22, 2020, 9:14 PM
* Created on January 22, 2020, 11:36 PM
*/
#ifndef RGBA_H
@ -16,9 +16,13 @@
class Rgba {
public:
Rgba();
~Rgba();
private:
Rgba(unsigned char r = 0, unsigned char g = 0, unsigned char b = 0, unsigned char a = 0);
friend bool operator==(Rgba &left, Rgba &right);
friend bool operator!=(Rgba &left, Rgba &righe);
operator unsigned();
operator int();
operator long();
public:
unsigned char _r;
unsigned char _g;
unsigned char _b;

29
src/common.h

@ -0,0 +1,29 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: common.h
* Author: Blobt
*
* Created on October 5, 2019, 4:55 PM
*/
#ifndef COMMON_H
#define COMMON_H
#ifdef __cplusplus
extern "C" {
#endif
#define die(m) do { perror(m); exit(EXIT_FAILURE); } while(0)
#ifdef __cplusplus
}
#endif
#endif /* COMMON_H */

16
src/gtktest.cc

@ -2,6 +2,8 @@
#include <cairo.h>
#include <gtk/gtk.h>
#include "Rgba.h"
#include "Rester.h"
#include "common.h"
using namespace std;
@ -9,12 +11,24 @@ using namespace std;
gint height = 500;
gint width = 500;
unsigned char* makeBitmap() {
Rester rester(width, height);
unsigned char* makeBitmapRand() {
unsigned char* data = new unsigned char[width * height * 4];
for (int i = 0; i < width * height * 4; i++) {
data[i] = rand() % 255;
}
return data;
}
unsigned char* makeBitmap() {
rester.clean();
unsigned char* data = new unsigned char[width * height * 4];
for (int i = 0; i < 100; i++) {
rester.drawPointer(rand() % 500, rand() % 500, Rgba(255, 0, 0), 3);
}
memcpy(data, rester.buffer, rester.size());
return data;
}

23
src/tt.cc

@ -0,0 +1,23 @@
#include "Rgba.h"
#include <stdio.h>
#include <iostream>
#include <bitset>
#include <string.h>
using namespace std;
int main() {
Rgba x(255, 0, 0, 255);
Rgba y(0, 0, 255, 255);
unsigned char* z = new unsigned char[4];
Rgba buffer[5][5];
printf("%ld\n", sizeof(buffer));
//memcpy(z, x, sizeof(x));
//
//
// bitset<32> set = (int)z;
// cout << set << endl;
}
Loading…
Cancel
Save