Upscaling detection approach
Here is the poor man's approach:

var histogram = []
foreach pixel
    histogram.append(abs(pixel.value - pixel.south.value))
    histogram.append(abs(pixel.value - pixel.east.value))
sort(histogram)
sharpness = histogram[histogram.count * 0.95]
upscaled = sharpness &lt; X // You choose X experimentally