Yes, but you're asking for a certain amount of heuristic intelligence in the PNG renderer. On the one hand, it does want to dither most of the time, because its fundamental aim is to display the (typically 24-bit) image it's given as faithfully as possible on the limited-depth screen it has. But on the other hand, you're asking it to recognise that in some situations dithering isn't the best thing it could be doing, and to refrain from it at that point. Presumably this will involve a layering violation to tell the PNG renderer not only what colour background it's got (which it needs anyway for alpha blending) but also what colour background it was supposed to be; and then the PNG renderer has to look round the edges of the image to find the latter colour, and render it consistently as the former where it appears. I know that wouldn't appeal to me if I were writing either the PNG renderer or the top-level CSS renderer that called it.
The other alternative is to have the dithering done universally, so that the PNG renderer outputs 24-bit data all the time and some top-level piece of code deals in a uniform way with converting it to the available colour depth. That doesn't strike me as a nice answer either, because even on a 16-bit display it doesn't seem obviously right to dither the entire window without better cause than that.
Having mentioned alpha blending ... it suddenly occurs to me, actually, to ask why you're trying to match up those backgrounds at all. PNG has an alpha channel, so why haven't you just set the parts of the image which want to be the same colour as the surrounding page to transparent? That might perfectly well actually work better.
Re: that the CSS renderer and the PNG renderer disagree
The other alternative is to have the dithering done universally, so that the PNG renderer outputs 24-bit data all the time and some top-level piece of code deals in a uniform way with converting it to the available colour depth. That doesn't strike me as a nice answer either, because even on a 16-bit display it doesn't seem obviously right to dither the entire window without better cause than that.
Having mentioned alpha blending ... it suddenly occurs to me, actually, to ask why you're trying to match up those backgrounds at all. PNG has an alpha channel, so why haven't you just set the parts of the image which want to be the same colour as the surrounding page to transparent? That might perfectly well actually work better.