devongovett / jpg-stream

A streaming JPEG encoder and decoder
85 stars 14 forks source link

Scaling ratio incorrect? #4

Open ziriax opened 8 years ago

ziriax commented 8 years ago

The code to compute the scaling ratio is:

  // Calculate scale so we only decode what we need
  if (desiredWidth && desiredHeight) {
    int wdeg = imageWidth / desiredWidth;
    int hdeg = imageHeight / desiredHeight;
    dec.scale_num = 1;
    dec.scale_denom = std::max(1, std::min(std::min(wdeg, hdeg), 8));
  }

However, the following article says:

_Just set the desired scaling factor of N/8 (N=1...16) in the djpeg -scale option or via the scale_num/scale_denom variables in library application._

So I guess you should set the scale_denom to 8, and then compute the scale_num so that imageWidth * scale_num / 8 <= desiredWidth?