What getBackgrounds actually returns
getBackgrounds() reads the explicit fill color set on each cell and returns a 2D array of hex strings — one entry per cell in the range. A white, unfilled cell comes back as "#ffffff". That is the complete picture: one hex string per cell, no metadata, no rule names.
The hex strings are always lowercase and always six digits. If you typed "#EA4335" into the fill-color picker, getBackgrounds() hands you "#ea4335". The case-insensitive comparison in the snippet above is defensive but harmless.
The function above is a custom function, meaning you call it directly from a cell formula. Sheets passes the second argument as a Range object, which is why the code calls range.getRow() rather than parsing a string like "A1:A50" itself. That Range-object convention is specific to custom functions — if you call COUNT_BY_COLOR from another script function instead, you would pass a Range object explicitly.