Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is some pseudocode for downscaling. WS,HS is the target image size WB,HB is the source size. WS is less than WB and HS is less than HB.</p> <pre><code>double row[WB]; double Xratio= WB/WS; double Yratio= HB/HS; double curYratio= Yratio; double remainY= Yratio - floor(Yratio); double remainX= Xratio - floor(Xratio); double curXratio; double rfac, cfac; int icol,irow, orow, ocol; zero-out row orow= 0; for(irow=0..HB-1) { // we find out how much of this row we will add to the current sum if (curYratio&gt;=1.0) rfac= 1.0; else rfac= curYratio; // we add it for(icol=0..WB) row[icol] += rfac * input[irow][icol]; // we reduce the total weight curYratio -= rfac; // if the total weight is now zero, we have a complete row, // otherwise we still need some of the next row if (curYratio!=0.0) continue; // we have a complete row, compute the weighted average for(icol=0..WB-1) row[icol]/= Yratio; // now we can scale the row in horizontal curXratio= Xratio; ocol= 0; double pixel= 0.0; for(icol=0..WB-1) { if (curXratio&gt;=1.0) cfac= 1.0; else cfac= curXratio; pixel+= row[icol]*cfac; curXratio -= cfac; if (curXratio!=0) continue; // now we have a complete pixel out[orow][ocol]= pixel / Xratio; pixel= remainX * row[icol]; curXratio= Xratio - remainX; ocol++; } orow++; // let's put the remainder of the last input row into 'row' for(icol=0..WB-1) row[i]= remainY*input[irow][icol]; curYratio= Yratio - remainY; } </code></pre> <p>This took longer than I thought it would, but there it is. Anyway, it's not very wise to run this directly on an input bitmap. You should convert each pixel value to it's sRGB value before doing any arithmetic. The pixel values in a common bitmap are just names for the real values which should be used in computations. Look up sRGB on wikipedia, it has good information. </p> <p>If you do it without converting to sRGB and back, you will have a darker image when you scale down.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload