Transparency Issues

Hi guys,

Very specific problem I have here that you guys might be interested in. I’m working on getting transparency to work with bitmaps using the drawBitmap function. I’ve seen some posts on this before and the solution seemed to be “go into the adafruit library and change the drawBitmap method”. I’d rather not mess around with the library so I tried to think of another way to do it. I’m gonna give a summarized version now so you guys don’t have to read a wall of text. If you want any more details please ask and I’ll try to give them to you as fast as possible. The process is;

  1. Create an array of strings size 1024.
    1024 = ((64 pixels width X 128 pixels height) / 8 pixels taken up in one hex value)
  2. For every char element in the bitmap array convert the element from a char hex to a binary element.
  3. Convert the element to a string and assign it to the string array at the same position as the bitmap array.

With this working I should be able to manipulate any individual pixel using the string array and substring methods

Before the program displays it will convert the string array back into a char hex array and I’ll output it to the screen using the normal drawBitmap method.

The logic for converting to a binary string away has been tested and is working in a normal c++ program, see code below. I’m working on the assumption that the substring methods won’t give a problem and the conversion back to hex will work in the opposite way.

The problem I’m having is doing the same in arduino code. The closest I’ve gotten is outputting the binary string array to the serial monitor but the elements either come out as blank or the don’t come out as full 8bit binary numbers. Maybe 7 out of 1024 come out properly.

Do you guys have any ideas?

input.JPG shows the input hex array

output.JPG shows what I’d like the output to look like. This was created in the c++ file.

Working C++ Version:

#include
#include
#include
#include

using namespace std;

int main()
{
vector strArray;
int count = 0;
char hexArray
{
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF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FC,
0x3F, 0xFF, 0xFF, 0xFC, 0x3F, 0xDF, 0xFF, 0xFC,
0x30, 0x38, 0x15, 0x00, 0x3B, 0x07, 0xF8, 0xFC,
0x30, 0x00, 0x00, 0x00, 0x00, 0x01, 0xE0, 0x7C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18,
0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19,
0x8C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x31,
0xCE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73,
0xC7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE3,
0xE3, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0xC7,
0xF1, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x03, 0x8F,
0xF8, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x07, 0x1F,
0xFC, 0x70, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x3F,
0xFE, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x7F,
0xFF, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xFF,
0xFF, 0xC3, 0xFF, 0xFF, 0xFF, 0xFF, 0xC3, 0xFF,
0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF,
0xFF, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF
};

for each (char c in hexArray)
{
cout << "HEX: " << “\t\t” << c << endl;
cout << "DECIMAL: " << “\t” << (int)c << endl;

string binary = std::bitset<8>((int)c).to_string();
cout << "BINARY: " << “\t” << binary << “\n\n” << endl;
strArray.push_back(binary);
}

for each (string s in strArray)
{
cout << s << “,”;
count++;

if (count == 8)
{
count = 0;
cout << endl;
}
}
system(“pause”);
return 0;
}

output.JPG

employee:

  1. Create an array of strings size 1024.
    1024 = ((64 pixels width X 128 pixels height) / 8 pixels taken up in one hex value)
  2. For every char element in the bitmap array convert the element from a char hex to a binary element.
  3. Convert the element to a string and assign it to the string array at the same position as the bitmap array.

With this working I should be able to manipulate any individual pixel using the string array and substring methods

What a crazy idea. :confused:

In which Arduino should that monster of inefficency run?

Most Arduinos have not enough memory to hold 1024 empty Strings.

Better forget about the existence of Strings and learn how to manipulate bits.

I'm using the MEGA 2560

Even with a 2560, using "Strings" is not the way to go with a small microcontroller. On a PC with an operating system handling huge amounts of physical and even more virtual memory, it of course works.

As has been pointed out, you should use direct bit manipulation to achieve your goal.
Look at bitRead() etc. You can directly address and manipulate individual bits within a byte. Then start looking at bitwise operators for and, or, exclusive or etc. operations.

6v6gt:
Look at bitRead() etc. You can directly address and manipulate individual bits within a byte.

Thanks for the help. I'll let you know how I get on.