I don't claim to be an expert on Canvas, but I think we can figure it out. ;-)
Regarding [/font][font=monaco]putImageData[/font][font=arial], it would be easier for me to understand what the problem is if you had a link so I could see how you're using it. It's a little hard to answer that otherwise.
Your question about save state / restore state has to do with the behavior of Canvas. When you transform the canvas without clearing it and redrawing it, the canvas remains the same and new changes are placed on top of it. In other words, if you took out the save/clear/restore lines, and made the code look like the following, you would see duplicate copies of the image on top of one another:[/font]
//ctx.clearRect(-w*2, -h*2, w*4, h*4);
ctx.setTransform(p.m11, p.m12, p.m21, p.m22, p.dx, p.dy);
ctx.drawImage(img, 0, 0);
[font=arial]In that case, changing the parameters of the [/font][font=monaco]setTransform[/font][font=arial] method would duplicate the canvas view in addition to modifying it.
The way to work around this is, of course, to save the canvas context in its current state (which is why we start with the [/font][font=monaco]save()[/font][font=arial] method), clear what is currently visible on the canvas ([/font][font=monaco]clearRect()[/font][font=arial]), perform our transformation operation, and then when we're done, restore the canvas state ([/font][font=monaco]restore()[/font][font=arial]). The save/restore methods don't actually clear/restore the output of the canvas itself (that's what drawImage does); however, they do provide state-change information (the "context" as it were), which is important for a program that will be interacting with the canvas (particularly for optimizing redraws and the creation of new paths after they have been filled or stroked). Essentially, the transformations performed on the canvas are cumulative, and therefore each call saves and restores the canvas state. Does that help any?[/font]