implement a color inversion putPixel for SHARP memory Displa

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
tcornall
 
Posts: 17
Joined: Mon Mar 20, 2017 1:01 am

implement a color inversion putPixel for SHARP memory Displa

Post by tcornall »

Hi All.
My C++ -fu has let me down and I can't work out the best way to implement replacement drawing functions for the SHARP Memory display that can take a color other than 0 or 1 and use it to perform operations like INVERT or MIN MAX on the pixels in the display.

I can and have created a new subclassed display called mySharpMemDisplay that inherits from Adafruit_SharpMem and overrides the Adafruit_SharpMem::drawPixel() to do what I want, and if I directly call drawPixel() in any of the derived functions in mySharpMemDisplay class it is MY function that gets called and all is well.

The problems I am having are involved in calling inherited functions, like fillTriangle() that I haven't overridden . They go thru a series of calls to other functions in Adafruit_GFX::
and end up using GFXCanvas1::drawPixel(). Basically I think the issue is that I can't work out how to override a great-grandparent's putPixel() (Don't even know if it's possible but there are lots of comments in the Adafruit source code saying things like 'overwrite in subclass' that indicate that there is a way...)

I want fillTriangle() (and other functions) to use mySharpMemDisplay::drawPixel().
Will I end up having to implement my own derived (possibly skeleton) versions of fillTriangle(), writeFastHLine() drawFastHLine() writeLine() writePixel() in order to force everything to use mySharpMemDisplay::drawPixel()? Or is there an easier/more correct way to do this?

Thanks for any help. For what it's worth, here's my subclass code. It works, but with the issue as pointed out above.

Code: Select all

class mySharpMemDisplay: public Adafruit_SharpMem {
  public:
    mySharpMemDisplay(SPIClass* SPI, int CS, int W, int H, int SPEED) 
    : Adafruit_SharpMem(SPI, CS, W, H, SPEED){}

    //drawPixel that understands INVERSE color
    void drawPixel(uint16_t  x, uint16_t  y, uint16_t  color){
        if(color < INVERSE){    //INVERSE defined as 2
            Adafruit_SharpMem::drawPixel(x,y,color); //use the base drawPixel() for colors 0 and 1
        }else{  //color must be INVERSE
          //Serial.println("mySharpMemDisplay::drawPixel:: inverse detected");
          uint16_t c = getPixel(x, y); //find out what's there at that pixel
          if(c)
            Adafruit_SharpMem::drawPixel(x, y, 0); //invert it
          else
            Adafruit_SharpMem::drawPixel(x, y, 1); //invert it
        }
    }

User avatar
tcornall
 
Posts: 17
Joined: Mon Mar 20, 2017 1:01 am

Re: implement a color inversion putPixel for SHARP memory Di

Post by tcornall »

Or maybe I am mistaken that it ends up at GFXcanvas1_drawPixel() A closer look shows that it does end up at Adafruit_SharpMem::drawPixel() so maybe not so many grandparents involved at all.
Nonetheless, it isn't mySharpMemDisplay::drawPixel() which is where I need it to go.

It's just that it seems the adafruit code was written in a way that should allow me to just replace putPixel() but I can't get my head around how to get it to use my putPixel instead of the base one when the function (like fillTriangle()) is in the base, not the derived. I guess there just isn't a way to do that. I'll have to override fillTriangle() and all its dependents.

Terry

User avatar
tcornall
 
Posts: 17
Joined: Mon Mar 20, 2017 1:01 am

Re: implement a color inversion putPixel for SHARP memory Di

Post by tcornall »

Anyway, in the end, I just made a copy of Adafruit_SharpMem and modified its drawPixel(). That worked.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”