<?xml version="1.0"?>
<!DOCTYPE riscos-prm PUBLIC "-//Gerph//DTD PRM documentation 1.03//EN"
                            "http://gerph.org/dtd/103/prm.dtd">

<riscos-prm>
<chapter title="SuperSample">
<section title="Introduction and Overview">
<p>
SuperSample is a module which converts monochrome source image data into
4 bits-per-pixel destination image data while reducing the image size. It
is intended for use by the Font Manager when generating anti-aliased font
output from 1 bit-per-pixel source images.
</p>

<p>
The module provides two SWIs. <reference type="swi" name="Super_Sample90"/>
is used for images with a 1:1 pixel aspect ratio, and
<reference type="swi" name="Super_Sample45"/> is used for images with a
1:2 pixel aspect ratio. Both calls are internal interfaces and should not be
used by application software.
</p>
</section>

<section title="Technical Details">
<p>
Both SWIs treat the source image as a packed 1 bit-per-pixel bitmap and write
packed 4 bits-per-pixel output. The calls reduce the source by sampling output
points spaced four source pixels apart in both directions. The source width and
height are therefore expected to be 4n+3 pixels, allowing each output sample to
be centred on source position 3,3 and then advanced in steps of four pixels
without any special edge handling.
</p>

<subsection title="Source bitmap">
<p>
The source bitmap is described by a pointer, a line spacing and a row count.
The source words are read least significant bit first. The line spacing is the
number of bytes between source rows, and must be word aligned.
</p>

<p>
The source row format is:
</p>

<p>
<offset-table head-number="Offset" head-data-size="Size" head-value="Contents">
 <offset number="0" data-size="4">First 32 source pixels in the row, with the
 leftmost pixel in bit 0.</offset>
 <offset number="4" data-size="4">Next 32 source pixels in the row, in the
 same bit order.</offset>
 <offset number="8-" data-size="4">Further source words, if present.</offset>
</offset-table>
</p>

<p>
The last bit of each source row is unused. A row therefore describes
(8 * line spacing) - 1 source pixels, which is one less than a multiple of
eight pixels and so satisfies the 4n+3 width requirement.
</p>
</subsection>

<subsection title="Destination bitmap">
<p>
The destination bitmap is described by a pointer only. Output rows are written
consecutively, and each destination row occupies the same number of bytes as
the source line spacing. This is one 32 bit destination word for every 32 bits
of source row storage. Each output word contains up to eight 4 bit pixels,
least significant nibble first.
</p>

<p>
The destination row format is:
</p>

<p>
<offset-table head-number="Offset" head-data-size="Size" head-value="Contents">
 <offset number="0" data-size="4">First seven or eight destination pixels in the row,
 with the leftmost pixel in bits 3-0.</offset>
 <offset number="4" data-size="4">Next eight destination pixels in the row,
 in the same nibble order.</offset>
 <offset number="8-" data-size="4">Further destination words, if present.</offset>
</offset-table>
</p>

<p>
The number of destination rows generated is (source row count - 3) / 4. Each
row contains (2 * line spacing) - 1 destination pixels, so the final nibble of
the row is unused. If the source row count is 3, the call returns without
writing any output.
</p>
</subsection>

<subsection title="Sampling for square pixels">
<p>
<reference type="swi" name="Super_Sample90"/> calculates each output pixel
from a 7 by 7 source pixel grid centred on the output sample point. The
weights are:
</p>

<p>
<value-table head-number="Row" head-value="Weights">
 <value number="1">1, 2, 3, 4, 3, 2, 1</value>
 <value number="2">2, 4, 6, 8, 6, 4, 2</value>
 <value number="3">3, 6, 9, 12, 9, 6, 3</value>
 <value number="4">4, 8, 12, 16, 12, 8, 4</value>
 <value number="5">3, 6, 9, 12, 9, 6, 3</value>
 <value number="6">2, 4, 6, 8, 6, 4, 2</value>
 <value number="7">1, 2, 3, 4, 3, 2, 1</value>
</value-table>
</p>

<p>
The maximum weighted total is 256. The total is rounded by adding 14 and
then the high nibble is used as the 4 bit destination pixel value. Values
which would overflow the 4 bit range are clamped to 15. In module versions
from 0.06 onwards, very light pixels which would produce value 1 are forced
to 0.
</p>
</subsection>

<subsection title="Sampling for double-height pixels">
<p>
<reference type="swi" name="Super_Sample45"/> calculates each output pixel
from a 9 by 7 source pixel grid. The weights are:
</p>

<p>
<value-table head-number="Row" head-value="Weights">
 <value number="1">0, 0, 0, 0, 1, 0, 0, 0, 0</value>
 <value number="2">1, 2, 4, 6, 6, 6, 4, 2, 1</value>
 <value number="3">1, 4, 8, 12, 13, 12, 8, 4, 1</value>
 <value number="4">1, 4, 8, 12, 14, 12, 8, 4, 1</value>
 <value number="5">1, 4, 8, 12, 13, 12, 8, 4, 1</value>
 <value number="6">1, 2, 4, 6, 6, 6, 4, 2, 1</value>
 <value number="7">0, 0, 0, 0, 1, 0, 0, 0, 0</value>
</value-table>
</p>

<p>
The maximum weighted total, rounding and clamping rules are the same as for
<reference type="swi" name="Super_Sample90"/>.
</p>
</subsection>
</section>

<section title="SWI Calls">
<swi-definition name="Super_Sample90"
                number="40D80"
                description="Super-sample 1 bit-per-pixel image data to 4 bits-per-pixel output for square pixels"
                irqs="enabled"
                fiqs="enabled"
                processor-mode="SVC"
                re-entrant="no">
<entry>
 <register-use number="1">Pointer to the packed 1 bit-per-pixel source bitmap.</register-use>
 <register-use number="2">Source row spacing in bytes. This must be word aligned.</register-use>
 <register-use number="3">Number of source rows. This must be 4n+3.</register-use>
 <register-use number="4">Pointer to the packed 4 bits-per-pixel destination bitmap.</register-use>
</entry>

<exit>
 <register-use number="0" state="corrupted"/>
 <register-use number="1-11" state="preserved"/>
 <processor-flag name="V">Clear if the conversion completed; set if an error occurred, in which case R0 points to an error block.</processor-flag>
</exit>

<use>
<p>
This call converts the source data using the 7 by 7 square-pixel sampling
kernel described in <reference type="subsection" name="Sampling for square pixels"/>.
It is an internal interface used by the Font Manager. Application software
should not rely on it.
</p>

<p>
The caller must provide enough destination storage for ((R3 - 3) / 4) rows
of R2 bytes each. If R3 is 3, no output is written and the call
returns successfully.
</p>
</use>

<related>
 <reference type="swi" name="Super_Sample45"/>
 <reference type="error" name="BadParm"/>
</related>
</swi-definition>

<swi-definition name="Super_Sample45"
                number="40D81"
                description="Super-sample 1 bit-per-pixel image data to 4 bits-per-pixel output for double-height pixels"
                irqs="enabled"
                fiqs="enabled"
                processor-mode="SVC"
                re-entrant="no">
<entry>
 <register-use number="1">Pointer to the packed 1 bit-per-pixel source bitmap.</register-use>
 <register-use number="2">Source row spacing in bytes. This must be word aligned.</register-use>
 <register-use number="3">Number of source rows. This must be 4n+3.</register-use>
 <register-use number="4">Pointer to the packed 4 bits-per-pixel destination bitmap.</register-use>
</entry>

<exit>
 <register-use number="0" state="corrupted"/>
 <register-use number="1-11" state="preserved"/>
 <processor-flag name="V">Clear if the conversion completed; set if an error occurred, in which case R0 points to an error block.</processor-flag>
</exit>

<use>
<p>
This call converts the source data using the 9 by 7 double-height-pixel
sampling kernel described in
<reference type="subsection" name="Sampling for double-height pixels"/>.
It is an internal interface used by the Font Manager. Application software
should not rely on it.
</p>

<p>
The caller must provide enough destination storage for ((R3 - 3) / 4) rows
of R2 bytes each. If R3 is 3, no output is written and the call
returns successfully.
</p>
</use>

<related>
 <reference type="swi" name="Super_Sample90"/>
 <reference type="error" name="BadParm"/>
</related>
</swi-definition>
</section>

<section title="Error Messages">
<error-definition name="BadParm"
                  number="1EA"
                  description="Bad super-sample sprite size">
<use>
<p>
This error is returned if the source row count in R3 is not 4n+3 or if the
source row spacing in R2 is not word aligned.
</p>
</use>

<related>
 <reference type="swi" name="Super_Sample90"/>
 <reference type="swi" name="Super_Sample45"/>
</related>
</error-definition>
</section>

</chapter>

<!-- MetaData -->
<meta>
 <maintainer>
  <email name="Gerph" address="gerph@gerph.org" />
 </maintainer>
 <disclaimer>
    <p>
        &copy; Gerph, 2026.
    </p>
 </disclaimer>

 <history>
  <revision number="1" author="Charles Ferguson" date="19 May 2026" title="Initial version">
    <change>Created PRM-in-XML documentation for the SuperSample module interfaces and bitmap data formats.</change>
  </revision>
 </history>
</meta>
</riscos-prm>
