I think you can do this without the pixel RGBA check.
You will mask out the terrain using invisible sprites, right?
You can make your own version of raycaster. To check if there is a wall on the right, move a virtual point from the character to the right, constantly checking if this point is overlapping terrain and not overlapping masking sprite.
For x=player.x to (player.x+50)
...Pick terrainSprite overlapping a point (loopindex, player.y)
.......Pick maskSprite overlapping a point (loopindex, player.y)
.......Else -> set wallDetected=1 ; Stop loop