There's probably a lot of other answers, but among the molecules involved are anthocyanins, which are water soluble pigments produced by some plants upon stress of various types or as a normal part of fruit ripening, etc. Those pigments may act to filter (reduce) light intensity or they may act in other ways to protect the cell, like antioxidant function. There is more than one way they can have a photoprotective effect. So it's not necessarily the same focused purpose as melanin, the equivalent pigment that forms in human cells upon sun exposure and is shuttled from cell to cell so that it can sit around the nucleus and absorb UV that would otherwise cause DNA damage. Some anthocyanins do not contribute a meaningful amount of UV reduction, but presumably small differences in the molecules can affect the outcome dramatically. Certain chemical structures are much better at absorbing those frequencies than others.