@@ -337,6 +337,71 @@ void RGBmatrixPanel::drawPixel(int16_t x, int16_t y, uint16_t c) {
337337 }
338338}
339339
340+ uint16_t RGBmatrixPanel::getPixel (int16_t x, int16_t y) {
341+ uint8_t r, g, b, bit, limit, *ptr;
342+
343+ if ((x < 0 ) || (x >= _width) || (y < 0 ) || (y >= _height)) return 0 ;
344+
345+ switch (rotation) {
346+ case 1 :
347+ swap (x, y);
348+ x = WIDTH - 1 - x;
349+ break ;
350+ case 2 :
351+ x = WIDTH - 1 - x;
352+ y = HEIGHT - 1 - y;
353+ break ;
354+ case 3 :
355+ swap (x, y);
356+ y = HEIGHT - 1 - y;
357+ break ;
358+ }
359+
360+ // Loop counter stuff
361+ bit = 2 ;
362+ limit = 1 << nPlanes;
363+
364+ // This code was taken and reversed from drawPixel above.
365+ // A bit easier, since we can start with zeros for r, g, and b.
366+
367+ r = g = b = 0 ;
368+
369+ if (y < nRows) {
370+ // Data for the upper half of the display is stored in the lower
371+ // bits of each byte.
372+ ptr = &matrixbuff[1 -backindex][y * WIDTH * (nPlanes - 1 ) + x]; // Base addr
373+ // Plane 0 is a tricky case -- its data is spread about,
374+ // stored in least two bits not used by the other planes.
375+ if (ptr[64 ] & B00000001) r |= 1 ;
376+ if (ptr[64 ] & B00000010) g |= 1 ;
377+ if (ptr[32 ] & B00000001) b |= 1 ;
378+ // The remaining three image planes are more normal-ish.
379+ // Data is stored in the high 6 bits so it can be quickly
380+ // copied to the DATAPORT register w/6 output lines.
381+ for (; bit < limit; bit <<= 1 ) {
382+ if (*ptr & B00000100) r |= bit;
383+ if (*ptr & B00001000) g |= bit;
384+ if (*ptr & B00010000) b |= bit;
385+ ptr += WIDTH; // Advance to next bit plane
386+ }
387+ } else {
388+ // Data for the lower half of the display is stored in the upper
389+ // bits, except for the plane 0 stuff, using 2 least bits.
390+ ptr = &matrixbuff[1 -backindex][(y - nRows) * WIDTH * (nPlanes - 1 ) + x];
391+ if (ptr[32 ] & B00000010) r |= 1 ;
392+ if (*ptr & B00000001) g |= 1 ;
393+ if (*ptr & B00000010) b |= 1 ;
394+ for (; bit < limit; bit <<= 1 ) {
395+ if (*ptr & B00100000) r |= bit;
396+ if (*ptr & B01000000) g |= bit;
397+ if (*ptr & B10000000) b |= bit;
398+ ptr += WIDTH; // Advance to next bit plane
399+ }
400+ }
401+
402+ return Color444 (r, g, b);;
403+ }
404+
340405void RGBmatrixPanel::fillScreen (uint16_t c) {
341406 if ((c == 0x0000 ) || (c == 0xffff )) {
342407 // For black or white, all bits in frame buffer will be identically
0 commit comments