<html><head>

  <style id="css_styles" type="text/css"><!--blockquote.cite { margin-left: 5px; margin-right: 0px; padding-left: 10px; padding-right:0px; border-left: 1px solid #cccccc }
blockquote.cite2 {margin-left: 5px; margin-right: 0px; padding-left: 10px; padding-right:0px; border-left: 1px solid #cccccc; margin-top: 3px; padding-top: 0px; }
a img { border: 0px; }
li[style='text-align: center;'], li[style='text-align: center; '], li[style='text-align: right;'], li[style='text-align: right; '] {  list-style-position: inside;}
body { font-family: Helvetica; font-size: 9pt; }
.quote { margin-left: 1em; margin-right: 1em; border-left: 5px #ebebeb solid; padding-left: 0.3em; }
--></style></head>
  <body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div>Ah, OK. Thanks. You’re right. I think that’s it.</div><div><br /></div><div>I had assumed passthrough was a desired optimization because it starts out false and can only be assigned in `setHints`. But looking at the super class confirms your explanation.</div><div><br /></div><div>So… I still think there are problems here, but now they strike me as less interesting/severe:</div><div><br /></div><div>1. If an ImageProducer neglects to call setHints(..) AND if it produces pixels in, say, a random order: then AreaAveragingScaleFilter will fail with an exception. (It will enter the branch expecting pixels in a specific order, but it won’t get them in that order.)</div><div></div><div><br /></div><div>Attached is a test case confirming that not calling setHints(..) can lead to an exception.</div><div><div id="xf8c76c2ddfdd46e085a2fb4a9da3e070"><div><br /></div><div>In practice:</div><div><br /></div><div>   A. OffScreenImageSource doesn’t call setHints(), but it happens to deliver pixels in the desired order: so it works.</div><div><br /></div><div>   B. On my Mac: ToolkitImages use an ImageProducer that calls setHInts() and promises to deliver pixels in the right order, so it works.</div><div></div></div></div><div><br /></div><div>2. The AreaAveragingScalingFilter says in its documentation that if it doesn’t get the hints it wants: it will request new image production via  `requestTopDownLeftRightResent`. I don’t see any evidence that this class (or any of its ancestors) invoke this.</div><div><br /></div><div>(The attached test case also confirms.)</div><div><br /></div><div>Is there any interest in my writing either of these up?</div><div><br /></div><div>Regards,</div><div> - Jeremy</div>
<div><br /></div>
<div>
<div>------ Original Message ------</div>
<div>From "Aleksei Ivanov" <<a href="mailto:alexey.ivanov@oracle.com">alexey.ivanov@oracle.com</a>></div>
<div>To "Jeremy Wood" <<a href="mailto:mickleness@gmail.com">mickleness@gmail.com</a>>; "<a href="mailto:client-libs-dev@openjdk.org">client-libs-dev@openjdk.org</a>" <<a href="mailto:client-libs-dev@openjdk.org">client-libs-dev@openjdk.org</a>></div>
<div>Date 4/17/2023 7:43:06 AM</div>
<div>Subject Re: AreaAveragingScalingFilter</div></div><div><br /></div>
<div id="xb74c41729131492"><blockquote cite="53562955-5c06-f78f-623c-ec1cd994060f@oracle.com" type="cite" class="cite2">

    Hi Jeremy,<br />
    <br />
    The intention could be <i>to pass through</i> if the value of hints
    is different from the needed ones. That is the filter activates if
    and only if 
<code>hints == neededHints</code>, otherwise it doesn't
    do anything and forwards calls to its superclass.
<br />
    <br />
    -- <br />
    Regards,<br />
    Alexey<br />
    <br />
    <div class="moz-cite-prefix">On 17/04/2023 09:53, Jeremy Wood wrote:<br />
    </div>
    <blockquote type="cite" cite="mid:em065a3875-ff7a-40c4-b4a4-0158aa90d506@d8023f25.com" class="cite">
      
      <style type="text/css"><!--#xb74c41729131492 #x8140bcb8a2f345e, #xb74c41729131492
{font-family: Helvetica; font-size: 9pt;}
#xb74c41729131492 blockquote.cite
{margin-left: 5px; margin-right: 0px; padding-left: 10px; padding-right: 0px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204);}
#xb74c41729131492 blockquote.cite2
{margin-left: 5px; margin-right: 0px; padding-left: 10px; padding-right: 0px; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); margin-top: 3px; padding-top: 0px;}
#xb74c41729131492 a img
{border: 0px;}
#xb74c41729131492 li#xb74c41729131492 [style="'text-align: center;'"], #xb74c41729131492 li#xb74c41729131492 [style="'text-align: center; '"], #xb74c41729131492 li#xb74c41729131492 [style="'text-align: right;'"], #xb74c41729131492 li#xb74c41729131492 [style="'text-align: right; '"]
{list-style-position: inside;}
#xb74c41729131492 .quote
{margin-left: 1em; margin-right: 1em; border-left-width: 5px; border-left-style: solid; border-left-color: rgb(235, 235, 235); padding-left: 0.3em;}
--></style>
      
      <div><span>I could be mistaken, but it looks like
          AreaAveragingFilter has a typo in it. This method looks
          suspicious to me:
</span></div>
      <div id="x8140bcb8a2f345e" style="overflow-wrap: break-word;&#xA;        -webkit-nbsp-mode: space; line-break: after-white-space;&#xA;">
        <div id="xed53aded5dd341b7956b8c6700b79786">
          <div><br />
          </div>
          <div>
            <div style="color:#080808;font-family:'JetBrains&#xA;              Mono',monospace;font-size:9.8pt;&#xA;">
              <pre><span style="color:#0033B3;">public void </span><span style="color:#00627A;">setHints</span>(<span style="color:#0033B3;">int </span>hints) {
    <span style="color:#871094;">passthrough </span>= ((hints & <span style="color:#871094;font-style:italic;">neededHints</span>) != <span style="color:#871094;font-style:italic;">neededHints</span>);
    <span style="color:#0033B3;">super</span>.setHints(hints);
}
</pre>
            </div>
          </div>
          <div><br />
          </div>
          <div>Later on the passthrough field is used as:</div>
          <div><br />
          </div>
          <div>
            <div style="color:#080808;font-family:'JetBrains&#xA;              Mono',monospace;font-size:9.8pt;&#xA;">
              <pre><span style="color:#0033B3;">public void </span><span style="color:#00627A;">setPixels</span>(<span style="color:#0033B3;">int </span>x, <span style="color:#0033B3;">int </span>y, <span style="color:#0033B3;">int </span>w, <span style="color:#0033B3;">int </span>h,
                      <span style="color:#000;">ColorModel </span>model, <span style="color:#0033B3;">byte </span>pixels[], <span style="color:#0033B3;">int </span>off,
                      <span style="color:#0033B3;">int </span>scansize) {
    <span style="color:#0033B3;">if </span>(<span style="color:#871094;">passthrough</span>) {
        <span style="color:#0033B3;">super</span>.setPixels(x, y, w, h, model, pixels, off, scansize);
    } 
<span style="color:#0033B3;">else </span>{
        accumPixels(x, y, w, h, model, pixels, off, scansize);
    }
}
</pre>
            </div>
          </div>
          <div><br />
          </div>
          <div>This makes me think we want passthrough to be <i>true</i> when
            we match specific hints (“neededHints”) promising to deliver
            the pixel data in whole scanlines from top-to-bottom. So the
            “!=“ in setHints(..) should be “==“.
</div>
          <div><br />
          </div>
          <div>If I set passthrough to true for BufferedImages (which
            always deliver pixels from top to bottom in entire
            scanlines), then the execution time of this filter reduces
            to less than 5% of its current time. But it introduces
            scaling artifacts and looks lower quality.
</div>
          <div><br />
          </div>
          <div>So if (?) my theory is correct that there is a typo, and
            knowing that the AreaAveragingFilter is
<span> </span><a href="https://bugs.openjdk.org/browse/JDK-6196792?jql=status&#xA;              = Open AND text ~ "AreaAveragingScaleFilter"&#xA;" style="font-size: 9pt;" moz-do-not-send="true">effectively
              internally deprecated
</a><span> : is anyone interested in
              discussing this with me further? I attached my (very
              rough) test program that demonstrates both the performance
              difference and the scaling artifacts.
</span></div>
          <div><span><br />
            </span></div>
          <div><span>(My broad goal is to create thumbnails of large
              images. If I used a Graphics2D to scale the image more
              than 50%, then I also see scaling artifacts with that
              approach. I know “Filthy Rich Clients” outlined a
              solution to that problem, but it’s expensive. So I’m
              dusting off this filter to see if it can work.)
</span></div>
          <div><span><br />
            </span></div>
          <div>Regards,</div>
          <div> - Jeremy</div>
        </div>
      </div>
    </blockquote>
    <br />
  </blockquote></div>


</body></html>