docs: public CmsImageScaler getReScaler(CmsImageScaler target) {
  
          int height = target.getHeight();
          int width = target.getWidth();
          int type = target.getType();
  
          if (type == 5) {
              // best fit option without upscale in the provided dimensions
              if (target.isValid()) {
                  // ensure we have sensible values for maxWidth / minWidth even if one has not been set
                  float maxWidth = target.getMaxWidth() > 0 ? target.getMaxWidth() : height;
                  float maxHeight = target.getMaxHeight() > 0 ? target.getMaxHeight() : width;
                  // calculate the factor of the image and the 3 possible target dimensions
                  float scaleOfImage = (float)getWidth() / (float)getHeight();
                  float[] scales = new float[3];
                  scales[0] = (float)width / (float)height;
                  scales[1] = width / maxHeight;
                  scales[2] = maxWidth / height;
                  int useScale = calculateClosest(scaleOfImage, scales);
                  int[] dimensions;
                  switch (useScale) {
                      case 1:
                          dimensions = calculateDimension(getWidth(), getHeight(), width, (int)maxHeight);
                          break;
                      case 2:
                          dimensions = calculateDimension(getWidth(), getHeight(), (int)maxWidth, height);
                          break;
                      case 0:
                      default:
                          dimensions = calculateDimension(getWidth(), getHeight(), width, height);
                          break;
                  }
                  width = dimensions[0];
                  height = dimensions[1];
              } else {
                  // target not valid, switch type to 1 (no upscale)
                  type = 1;
              }
          }
  
          if (type != 5) {
              if ((width > 0) && (getWidth() > 0)) {
                  // width is known, calculate height
                  float scale = (float)width / (float)getWidth();
                  height = Math.round(getHeight() * scale);
              } else if ((height > 0) && (getHeight() > 0)) {
                  // height is known, calculate width
                  float scale = (float)height / (float)getHeight();
                  width = Math.round(getWidth() * scale);
              } else if (isValid() && !target.isValid()) {
                  // scaler is not valid but original is, so use original size of image
                  width = getWidth();
                  height = getHeight();
              }
          }
  
          if ((type == 1) && (!target.isValid())) {
              // "no upscale" has been requested, only one target dimension was given
              if ((target.getWidth() > 0) && (getWidth() < width)) {
                  // target width was given, target image should have this width
                  height = getHeight();
              } else if ((target.getHeight() > 0) && (getHeight() < height)) {
                  // target height was given, target image should have this height
                  width = getWidth();
              }
          }
  
          // now create and initialize the result scaler
          CmsImageScaler result = new CmsImageScaler(target, width, height);
          // type may have been switched
          result.setType(type);
          return result;
      }