@@ -8,78 +8,63 @@ imgNeoPixel::imgNeoPixel(Adafruit_NeoPixel* theLEDs,baseImage* theBMPImage) {
8
8
mImage = theBMPImage;
9
9
mRGBArray = NULL ;
10
10
mNumPixels = 0 ;
11
- mImageFile = NULL ;
11
+ mReadyToDraw = false ;
12
12
}
13
13
14
14
15
15
imgNeoPixel::~imgNeoPixel (void ) {
16
16
17
- resizeBuff (0 ,&mRGBArray );
18
- if (mFile ) {
19
- mFile .close ();
20
- }
17
+ resizeBuff (0 ,(byte**)&mRGBArray ); // Deallocate the offscreen buffer.
18
+ if (mImage ) mImage ->closeDocFile (); // Close but don't delete the image file.
21
19
}
22
20
23
-
24
- bool imgNeoPixel::setupOffscreen (int numPixels) {
25
21
26
- int maxWidth;
22
+ // Open up the image file, make sure its readable. Then, if so.. Setup to allocate the
23
+ // offscreen buffer. Basically an array of RGBpack(s). There are three numbers to take
24
+ // into account.
25
+ // First : The number of pixels we have on the string.
26
+ // Second : The width of the image we have to read from.
27
+ // Third : The actual value the uses puts in as the value, and that default to zero.
28
+ //
29
+ // How to choose?
30
+ void imgNeoPixel::setupOffscreen (int numPixels) {
31
+
32
+ int maxWidth;
27
33
28
- mImageFile = NULL ; // Just in case .
29
- maxWidth = min ( mPixels -> numPixels (), mImage -> getWidth ());
30
- if (numPixels== 0 ) {
31
- mNumPixels = maxWidth;
32
- } else {
33
- mNumPixels = min ( maxWidth, mNumPixels );
34
- }
35
- if ( resizeBuff ( sizeof (RGBpack)* mNumPixels ,& mRGBArray )) {
36
- mFile = SD. open ( mImage -> getDocFilePath ());
37
- if (mFile ) {
38
- mImageFile = & mFile ;
39
- return true ;
40
- } else {
41
- resizeBuff ( 0 ,& mRGBArray );
42
- mNumPixels = 0 ;
34
+ mReadyToDraw = false ; // We ain't ready yet. .
35
+ if ( mImage ) { // If we have an image file..
36
+ if (mImage -> openDocFile (FILE_READ)) { // If we can open/read said image file..
37
+ maxWidth = min ( mPixels -> numPixels (), mImage -> getWidth ()); // Grab the smaller of the image width and the number of pixels we have.
38
+ if (numPixels== 0 ) { // If the numPixels passed in is zero..
39
+ mNumPixels = maxWidth; // We just use the maxWidth we just calculated.
40
+ } else { // Else, we have non zero value passed in..
41
+ mNumPixels = min (maxWidth,numPixels); // We use the smallar of the previous max width and this new passed in value.
42
+ }
43
+ if (resizeBuff ( sizeof (RGBpack)* mNumPixels ,(byte**)& mRGBArray )) { // If we can grab the RAM..
44
+ mReadyToDraw = true ; // Ok, we are ready to draw!
45
+ return ; // We call all of this a success! And exit.
46
+ } else { // Else, we could NOT allocate the buffer..
47
+ mImage -> closeDocFile (); // Close the image file.
48
+ }
43
49
}
44
- }
45
- return false ;
50
+ } // And if we got here? We call this a failure. And exit.
46
51
}
47
-
48
-
49
- void imgNeoPixel::clearOffscreen (void ) {
50
-
51
- resizeBuff (0 ,&mRGBArray );
52
- mNumPixels = 0 ;
53
- if (mFile ) {
54
- mFile .close ();
55
- }
56
- mImageFile = NULL ;
57
- }
58
-
52
+
59
53
60
54
void imgNeoPixel::setLine (int row,int numPixels) {
61
55
62
56
int maxWidth;
63
- colorObj aPixel;
64
57
65
- maxWidth = min (mPixels ->numPixels (),mImage ->getWidth ());
66
- if (numPixels==0 ) {
67
- numPixels = maxWidth;
68
- } else {
69
- mNumPixels = min (maxWidth,mNumPixels );
70
- }
71
- if (mImageFile && mRGBArray ) {
72
- mImage ->getRow (row,mRGBArray ,mNumPixels ,mImageFile );
73
- for (int i=0 ;i<mNumPixels ;i++) {
74
- mPixels ->setPixelColor (i,mRGBArray [i].r ,mRGBArray [i].g ,mRGBArray [i].b );
58
+ if (mReadyToDraw ) {
59
+ if (numPixels) {
60
+ maxWidth = min (mNumPixels ,numPixels);
61
+ } else {
62
+ maxWidth = mNumPixels ;
75
63
}
76
- } else {
77
- for (int i=0 ;i<maxWidth;i++) {
78
- aPixel = mImage -> getPixel (i,row );
79
- mPixels -> setPixelColor (i,aPixel. getRed (),aPixel. getGreen (),aPixel. getBlue ());
64
+ if ( mImage -> getRow ( 0 ,row,maxWidth, mRGBArray )) {
65
+ for (int i=0 ;i<maxWidth;i++) {
66
+ mPixels -> setPixelColor (i,mRGBArray [i]. r , mRGBArray [i]. g , mRGBArray [i]. b );
67
+ }
80
68
}
81
69
}
82
- }
83
-
84
-
85
-
70
+ }
0 commit comments