I'm currently trying to perform on-chain image mutation. I'm writing the smart contract using smartpy.
The idea is:
- The image is on-chain "Raw PPM encoded", in
sp.TBytes
format. Each pixel is represented by 3 consecutives RGB bytes - The contract has an entrypoint that takes a pseudo-random pixel from the image and changes its value
To modify a pixel of the image, I then have to use sp.slice
on the image to isolate the pixel, mutate it, and then reconstruct the image by concatenating:
- bytes before pixel
- mutated pixel
- bytes after mutated pixel.
However, I have troubles when it comes to mutate the pixel's value.
Since there is no operator allowing arithmetic operations on sp.TBytes
, I would like to transform pixel's value in sp.TNat
.
I naively wanted to use sp.unpack
method, but it seems that it assumes the sp.TBytes
sequence contains a header.
What would then be the solution to perform some operations on a sp.TBytes
sequence?