I had a similar problem. My solution was to modify the image to a black and white image and then use zonal statistic. I did the following steps on a Windows 10 computer
1) Find out about the colours in the image. I did this using gdalinfo in the OSGeo4W shell (see this link for details)
gdalinfo -hist MyMapOriginal.tif
In my case, it gave me the following result
....
229145351 33906481 23372842 1766970 67856 30414 26 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Color Table (RGB with 256 entries)
0: 244,240,232,255
1: 48,132,92,255
2: 24,20,12,255
3: 240,232,72,255
4: 196,68,72,255
5: 40,116,196,255
6: 52,48,116,255
7: 0,0,0,255
...
I then used a web colour identifier (for example this one) to find out that the third colour (240,232,72) is the one I want to have the statistics about (the colour was yellow).
2) Replace colours using the replace command from Imagemagick. I first made all non-yellow pixel balck
magick MyMapOriginal.tif -fill black +opaque "rgb(240,232,72)" MyMap_yellowBlack.tif
and then the yellow pixel white
magick MyMap_yellowBlack.tif -fill white -opaque "rgb(240,232,72)" MyMap_whiteBlack.tif
3) In QGIS I then did zonal statistics. The value in "sum" returns the number of pixel within each zone (districts in the question of Q.S.J), and "value" the sum of the values in each zone. In my case, white had the value 255 and black the value 0. Thus to calculate the share of white (originally yellow) pixel, I need to derive (value/255)/sum.
4) You can now repeat 2) and 3) for each colour you are interested in.
Some notes beyond the question by Q.S.J:
a)If you work with a scan (e.g. a jpeg of a map) rather than an original raster file, you probably want to reduce the number of colours before you do step 1). The reply by Steven Kay explaines how this can be done within QGIS. I had good results using the GIMP tool found in the menue Image - Mode - Indexed using the custome palette PointJet colours.
b) If your scan consists of several sheets, it is a good idea to merge them first (e.g., using the montage command from imagemagick), otherwise you end up with different colour codes for each sheet.
c) If you also need to georeference your map (which is much more difficult with a black/white map), you can do this in QGIS using the Georeferencer (menue "Raster-Georeferencer...") with your original map ("MyMapOriginal.tif") and save the GCP Points (in the menue "File" within the georeferencer window). Then open the modifed black/white map ("MyMap_whiteBlack.tif") in the georference window, laod the GCP points and use them for georeferencing.
gdalinfo
to the raster file.