Final Project로 실제 점검에 사용된 코드
Dependencies: mbed Adafruit_GFX
PixelArray/PixelArray.cpp@0:22391cd705e2, 2019-06-15 (annotated)
- Committer:
- 21400688
- Date:
- Sat Jun 15 20:52:15 2019 +0000
- Revision:
- 0:22391cd705e2
vb
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
21400688 | 0:22391cd705e2 | 1 | #include "PixelArray.h" |
21400688 | 0:22391cd705e2 | 2 | |
21400688 | 0:22391cd705e2 | 3 | PixelArray::PixelArray(int size) |
21400688 | 0:22391cd705e2 | 4 | { |
21400688 | 0:22391cd705e2 | 5 | pbufsize = size; |
21400688 | 0:22391cd705e2 | 6 | pbuf = new int[pbufsize]; |
21400688 | 0:22391cd705e2 | 7 | SetAll(0x0); // initialise memory to zeros |
21400688 | 0:22391cd705e2 | 8 | |
21400688 | 0:22391cd705e2 | 9 | } |
21400688 | 0:22391cd705e2 | 10 | |
21400688 | 0:22391cd705e2 | 11 | PixelArray::~PixelArray() |
21400688 | 0:22391cd705e2 | 12 | { |
21400688 | 0:22391cd705e2 | 13 | delete[] pbuf; |
21400688 | 0:22391cd705e2 | 14 | } |
21400688 | 0:22391cd705e2 | 15 | |
21400688 | 0:22391cd705e2 | 16 | void PixelArray::SetAll(unsigned int value) |
21400688 | 0:22391cd705e2 | 17 | { |
21400688 | 0:22391cd705e2 | 18 | // for each pixel |
21400688 | 0:22391cd705e2 | 19 | for (int i=0 ; i < pbufsize; i++) { |
21400688 | 0:22391cd705e2 | 20 | __set_pixel(i,value); |
21400688 | 0:22391cd705e2 | 21 | } |
21400688 | 0:22391cd705e2 | 22 | } |
21400688 | 0:22391cd705e2 | 23 | |
21400688 | 0:22391cd705e2 | 24 | |
21400688 | 0:22391cd705e2 | 25 | void PixelArray::SetAllI(unsigned char value) |
21400688 | 0:22391cd705e2 | 26 | { |
21400688 | 0:22391cd705e2 | 27 | // for each pixel |
21400688 | 0:22391cd705e2 | 28 | for (int i=0 ; i < pbufsize; i++) { |
21400688 | 0:22391cd705e2 | 29 | __set_pixel_component(i,3,value); |
21400688 | 0:22391cd705e2 | 30 | } |
21400688 | 0:22391cd705e2 | 31 | } |
21400688 | 0:22391cd705e2 | 32 | |
21400688 | 0:22391cd705e2 | 33 | |
21400688 | 0:22391cd705e2 | 34 | |
21400688 | 0:22391cd705e2 | 35 | void PixelArray::SetAllR(unsigned char value) |
21400688 | 0:22391cd705e2 | 36 | { |
21400688 | 0:22391cd705e2 | 37 | // for each pixel |
21400688 | 0:22391cd705e2 | 38 | for (int i=0 ; i < pbufsize; i++) { |
21400688 | 0:22391cd705e2 | 39 | __set_pixel_component(i,2,value); |
21400688 | 0:22391cd705e2 | 40 | } |
21400688 | 0:22391cd705e2 | 41 | } |
21400688 | 0:22391cd705e2 | 42 | |
21400688 | 0:22391cd705e2 | 43 | void PixelArray::SetAllG(unsigned char value) |
21400688 | 0:22391cd705e2 | 44 | { |
21400688 | 0:22391cd705e2 | 45 | // for each pixel |
21400688 | 0:22391cd705e2 | 46 | for (int i=0 ; i < pbufsize; i++) { |
21400688 | 0:22391cd705e2 | 47 | __set_pixel_component(i,1,value); |
21400688 | 0:22391cd705e2 | 48 | } |
21400688 | 0:22391cd705e2 | 49 | } |
21400688 | 0:22391cd705e2 | 50 | |
21400688 | 0:22391cd705e2 | 51 | void PixelArray::SetAllB(unsigned char value) |
21400688 | 0:22391cd705e2 | 52 | { |
21400688 | 0:22391cd705e2 | 53 | // for each pixel |
21400688 | 0:22391cd705e2 | 54 | for (int i=0 ; i < pbufsize; i++) { |
21400688 | 0:22391cd705e2 | 55 | __set_pixel_component(i,0,value); |
21400688 | 0:22391cd705e2 | 56 | } |
21400688 | 0:22391cd705e2 | 57 | } |
21400688 | 0:22391cd705e2 | 58 | |
21400688 | 0:22391cd705e2 | 59 | |
21400688 | 0:22391cd705e2 | 60 | |
21400688 | 0:22391cd705e2 | 61 | |
21400688 | 0:22391cd705e2 | 62 | |
21400688 | 0:22391cd705e2 | 63 | void PixelArray::Set(int i, unsigned int value) |
21400688 | 0:22391cd705e2 | 64 | { |
21400688 | 0:22391cd705e2 | 65 | if ((i >= 0) && (i < pbufsize)) { |
21400688 | 0:22391cd705e2 | 66 | __set_pixel(i,value); |
21400688 | 0:22391cd705e2 | 67 | } |
21400688 | 0:22391cd705e2 | 68 | } |
21400688 | 0:22391cd705e2 | 69 | |
21400688 | 0:22391cd705e2 | 70 | |
21400688 | 0:22391cd705e2 | 71 | |
21400688 | 0:22391cd705e2 | 72 | void PixelArray::SetI(int i, unsigned char value) |
21400688 | 0:22391cd705e2 | 73 | { |
21400688 | 0:22391cd705e2 | 74 | if ((i >= 0) && (i < pbufsize)) { |
21400688 | 0:22391cd705e2 | 75 | __set_pixel_component(i,3,value); |
21400688 | 0:22391cd705e2 | 76 | } |
21400688 | 0:22391cd705e2 | 77 | } |
21400688 | 0:22391cd705e2 | 78 | |
21400688 | 0:22391cd705e2 | 79 | |
21400688 | 0:22391cd705e2 | 80 | void PixelArray::SetR(int i, unsigned char value) |
21400688 | 0:22391cd705e2 | 81 | { |
21400688 | 0:22391cd705e2 | 82 | if ((i >= 0) && (i < pbufsize)) { |
21400688 | 0:22391cd705e2 | 83 | __set_pixel_component(i,2,value); |
21400688 | 0:22391cd705e2 | 84 | } |
21400688 | 0:22391cd705e2 | 85 | } |
21400688 | 0:22391cd705e2 | 86 | |
21400688 | 0:22391cd705e2 | 87 | void PixelArray::SetG(int i, unsigned char value) |
21400688 | 0:22391cd705e2 | 88 | { |
21400688 | 0:22391cd705e2 | 89 | if ((i >= 0) && (i < pbufsize)) { |
21400688 | 0:22391cd705e2 | 90 | __set_pixel_component(i,1,value); |
21400688 | 0:22391cd705e2 | 91 | } |
21400688 | 0:22391cd705e2 | 92 | } |
21400688 | 0:22391cd705e2 | 93 | |
21400688 | 0:22391cd705e2 | 94 | void PixelArray::SetB(int i, unsigned char value) |
21400688 | 0:22391cd705e2 | 95 | { |
21400688 | 0:22391cd705e2 | 96 | if ((i >= 0) && (i < pbufsize)) { |
21400688 | 0:22391cd705e2 | 97 | __set_pixel_component(i,0,value); |
21400688 | 0:22391cd705e2 | 98 | } |
21400688 | 0:22391cd705e2 | 99 | } |
21400688 | 0:22391cd705e2 | 100 | |
21400688 | 0:22391cd705e2 | 101 | |
21400688 | 0:22391cd705e2 | 102 | int* PixelArray::getBuf() |
21400688 | 0:22391cd705e2 | 103 | { |
21400688 | 0:22391cd705e2 | 104 | return (pbuf); |
21400688 | 0:22391cd705e2 | 105 | } |
21400688 | 0:22391cd705e2 | 106 | |
21400688 | 0:22391cd705e2 | 107 | |
21400688 | 0:22391cd705e2 | 108 | // set either the I,R,G,B value of specific pixel channel |
21400688 | 0:22391cd705e2 | 109 | void PixelArray::__set_pixel_component(int index, int channel, int value) |
21400688 | 0:22391cd705e2 | 110 | { |
21400688 | 0:22391cd705e2 | 111 | |
21400688 | 0:22391cd705e2 | 112 | // AND with 0x00 shifted to the right location to clear the bits |
21400688 | 0:22391cd705e2 | 113 | pbuf[index] &= ~(0xFF << (8 * channel)); |
21400688 | 0:22391cd705e2 | 114 | |
21400688 | 0:22391cd705e2 | 115 | // Set the bits with an OR |
21400688 | 0:22391cd705e2 | 116 | pbuf[index] |= (value << (8 * channel)); |
21400688 | 0:22391cd705e2 | 117 | } |
21400688 | 0:22391cd705e2 | 118 | |
21400688 | 0:22391cd705e2 | 119 | |
21400688 | 0:22391cd705e2 | 120 | // set either the I,R,G,B value of specific pixel channel |
21400688 | 0:22391cd705e2 | 121 | void PixelArray::__set_pixel(int index, int value) |
21400688 | 0:22391cd705e2 | 122 | { |
21400688 | 0:22391cd705e2 | 123 | // AND with 0x00 shifted to the right location to clear the bits |
21400688 | 0:22391cd705e2 | 124 | pbuf[index] = value; |
21400688 | 0:22391cd705e2 | 125 | } |
21400688 | 0:22391cd705e2 | 126 | |
21400688 | 0:22391cd705e2 | 127 |