MZ How to tint/change individual colors in a picture?

So basically i need a method/plugin to change the 2 colors in my game(it is 1 bit) individually and not apply a color overlay/blend to the both of them.
I've done a bit of research myself and found this code but don't exactly know how to apply it in the context of Game Pictures.
Code Source: https://stackoverflow.com/questions/16228048/replace-a-specific-color-by-another-in-an-image-sprite
Spoiler: Code
JavaScript:
// pull the entire image into an array of pixel data
var imageData = context.getImageData(0, 0, w, h);

// examine every pixel,
// change any old rgb to the new-rgb
for (var i=0;i<imageData.data.length;i+=4)
  {
      // is this pixel the old rgb?
      if(imageData.data[i]==oldRed &&
         imageData.data[i+1]==oldGreen &&
         imageData.data[i+2]==oldBlue
      ){
          // change to your new rgb
          imageData.data[i]=newRed;
          imageData.data[i+1]=newGreen;
          imageData.data[i+2]=newBlue;
      }
  }
// put the altered data back on the canvas
context.putImageData(imageData,0,0);
Spoiler: Reference Image
Screenshot_598.png

Edit [ 8/24/2022 ]: I feel like i'm getting pretty close to solving this myself, will post an update soon once i'm done.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-tint-change-individual-colors-in-a-picture.150738/