/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include "jlong.h"
#include "math.h"
#include "string.h"
#include "stdlib.h"
#include "sunfontids.h"
#include "fontscalerdefs.h"
#include "glyphblitting.h"
#include "GraphicsPrimitiveMgr.h"
#include "sun_java2d_loops_DrawGlyphList.h"
#include "sun_java2d_loops_DrawGlyphListAA.h"
/*
* Need to account for the rare case when (eg) repainting damaged
* areas results in the drawing location being negative, in which
* case (int) rounding always goes towards zero. We need to always
* round down instead, so that we paint at the correct position.
* We only call "floor" when value is < 0 (ie rarely).
* Storing the result of (eg) (x+ginfo->topLeftX) benchmarks is more
* expensive than repeating the calculation as we do here.
* "floor" shows up as a significant cost in app-level microbenchmarks.
* This macro avoids calling it on positive values, instead using an
* (int) cast.
*/
#define FLOOR_ASSIGN(l, r)\
if ((r)<0) (l) = ((int)floor(r)); else (l) = ((int)(r))
int g, bytesNeeded;
? (jfloatArray)
: NULL;
return (GlyphBlitVector*)NULL;
}
/* Add 0.5 to x and y and then use floor (or an equivalent operation)
* to round down the glyph positions to integral pixel positions.
*/
x += 0.5f;
y += 0.5f;
if (glyphPositions) {
int n = -1;
return (GlyphBlitVector*)NULL;
}
for (g=0; g<len; g++) {
}
} else {
for (g=0; g<len; g++) {
/* copy image data into this array at x/y locations */
}
}
return gbv;
}
int index;
}
}
/* since the AA and non-AA loop functions share a common method
* signature, can call both through this common function since
* there's no difference except for the inner loop.
* This could be a macro but there's enough of those already.
*/
int ret;
if (sdOps == 0) {
return;
}
}
{
return;
}
if (ret != SD_SUCCESS) {
if (ret == SD_SLOWLOCK) {
return;
}
} else {
return;
}
}
return;
}
}
}
static unsigned char* getLCDGammaLUT(int gamma);
static unsigned char* getInvLCDGammaLUT(int gamma);
int ret;
if (sdOps == 0) {
return;
}
}
{
return;
}
if (ret != SD_SUCCESS) {
if (ret == SD_SLOWLOCK) {
return;
}
} else {
return;
}
}
return;
}
}
}
/*
* Class: sun_java2d_loops_DrawGlyphList
* Method: DrawGlyphList
* Signature: (Lsun/java2d/SunGraphics2D;Lsun/java2d/SurfaceData;Lsun/java2d/font/GlyphList;J)V
*/
return;
}
return;
}
}
/*
* Class: sun_java2d_loops_DrawGlyphListAA
* Method: DrawGlyphListAA
* Signature: (Lsun/java2d/SunGraphics2D;Lsun/java2d/SurfaceData;Lsun/java2d/font/GlyphList;J)V
*/
return;
}
return;
}
}
/*
* Class: sun_java2d_loops_DrawGlyphListLCD
* Method: DrawGlyphListLCD
* Signature: (Lsun/java2d/SunGraphics2D;Lsun/java2d/SurfaceData;Lsun/java2d/font/GlyphList;J)V
*/
return;
}
return;
}
}
/*
* LCD text utilises a filter which spreads energy to adjacent subpixels.
* So we add 3 bytes (one whole pixel) of padding at the start of every row
* to hold energy from the very leftmost sub-pixel.
* This is to the left of the intended glyph image position so LCD text also
* adjusts the top-left X position of the padded image one pixel to the left
* so a glyph image is drawn in the same place it would be if the padding
* were not present.
*
* So in the glyph cache for LCD text the first two bytes of every row are
* zero.
* We make use of this to be able to adjust the rendering position of the
* text when the client specifies a fractional metrics sub-pixel positioning
* rendering hint.
*
* So the first 6 bytes in a cache row looks like :
* 00 00 Ex G0 G1 G2
*
* where
* 00 are the always zero bytes
* Ex is extra energy spread from the glyph into the left padding pixel.
* Gn are the RGB component bytes of the first pixel of the glyph image
* For an RGB display G0 is the red component, etc.
*
* If a glyph is drawn at X=12 then the G0 G1 G2 pixel is placed at that
* position : ie G0 is drawn in the first sub-pixel at X=12
*
* Draw at X=12,0
* PIXEL POS 11 11 11 12 12 12 13 13 13
* SUBPX POS 0 1 2 0 1 2 0 1 2
* 00 00 Ex G0 G1 G2
*
* If a sub-pixel rounded glyph position is calculated as being X=12.33 -
* ie 12 and one-third pixels, we want the result to look like this :
* Draw at X=12,1
* PIXEL POS 11 11 11 12 12 12 13 13 13
* SUBPX POS 0 1 2 0 1 2 0 1 2
* 00 00 Ex G0 G1 G2
*
* ie the G0 byte is moved one sub-pixel to the right.
* To do this we need to make two adjustments :
* - set X=X+1
* - set start of scan row to start+2, ie index past the two zero bytes
* ie we don't need the 00 00 bytes at all any more. Rendering start X
* can skip over those.
*
* Lets look at the final case :
* If a sub-pixel rounded glyph position is calculated as being X=12.67 -
* ie 12 and two-third pixels, we want the result to look like this :
* Draw at X=12,2
* PIXEL POS 11 11 11 12 12 12 13 13 13
* SUBPX POS 0 1 2 0 1 2 0 1 2
* 00 00 Ex G0 G1 G2
*
* ie the G0 byte is moved two sub-pixels to the right, so that the image
* starts at 12.67
* To do this we need to make these two adjustments :
* - set X=X+1
* - set start of scan row to start+1, ie index past the first zero byte
* In this case the second of the 00 bytes is used as a no-op on the first
* red sub-pixel position.
*
* The final adjustment needed to make all this work is note that if
* we moved the start of row one or two bytes in we will go one or two bytes
* past the end of the row. So the glyph cache needs to have 2 bytes of
* zero padding at the end of each row. This is the extra memory cost to
* accommodate this algorithm.
*
* The resulting text is perhaps fractionally better in overall perception
* than rounding to the whole pixel grid, as a few issues arise.
*
* * the improvement in inter-glyph spacing as well as being limited
* to 1/3 pixel resolution, is also limited because the glyphs were hinted
* so they fit to the whole pixel grid. It may be worthwhile to pursue
* disabling x-axis gridfitting.
*
* * an LCD display may have gaps between the pixels that are greater
* than the subpixels. Thus for thin stemmed fonts, if the shift causes
* the "heart" of a stem to span whole pixels it may appear more diffuse -
* less sharp. Eliminating hinting would probably not make this worse - in
* effect we have already doing that here. But it would improve the spacing.
*
* * perhaps contradicting the above point in some ways, more diffuse glyphs
* are better at reducing colour fringing, but what appears to be more
* colour fringing in this FM case is more likely attributable to a greater
* likelihood for glyphs to abutt. In integer metrics or even whole pixel
* rendered fractional metrics, there's typically more space between the
* glyphs. Perhaps disabling X-axis grid-fitting will help with that.
*/
int g, bytesNeeded;
? (jfloatArray)
: NULL;
return (GlyphBlitVector*)NULL;
}
/* The position of the start of the text is adjusted up so
* that we can round it to an integral pixel position for a
* bitmap glyph or non-subpixel positioning, and round it to an
* integral subpixel position for that case, hence 0.5/3 = 0.166667
* Presently subPixPos means FM, and FM disables embedded bitmaps
* Therefore if subPixPos is true we should never get embedded bitmaps
* and the glyphlist will be homogenous. This test and the position
* adjustments will need to be per glyph once this case becomes
* heterogenous.
* Also set subPixPos=false if detect a B&W bitmap as we only
* need to test that on a per glyph basis once the list becomes
* heterogenous
*/
/* rowBytes==width tests if its a B&W or LCD glyph */
}
}
if (subPixPos) {
x += 0.1666667f;
y += 0.1666667f;
} else {
x += 0.5f;
y += 0.5f;
}
if (glyphPositions) {
int n = -1;
return (GlyphBlitVector*)NULL;
}
for (g=0; g<len; g++) {
/*
* Subpixel positioning may be requested for LCD text.
*
* Subpixel positioning can take place only in the direction in
* which the subpixels increase the resolution.
* So this is useful for the typical case of vertical stripes
* increasing the resolution in the direction of the glyph
* advances - ie typical horizontally laid out text.
* If the subpixel stripes are horizontal, subpixel positioning
* can take place only in the vertical direction, which isn't
* as useful - you would have to be drawing rotated text on
* a display which actually had that organisation. A pretty
* unlikely combination.
* So this is supported only for vertical stripes which
* increase the horizontal resolution.
* If in this case the client also rotates the text then there
* will still be some benefit for small rotations. For 90 degree
* rotation there's no horizontal advance and less benefit
* from the subpixel rendering too.
* The test for width==rowBytes detects the case where the glyph
* is a B&W image obtained from an embedded bitmap. In that
* case we cannot apply sub-pixel positioning so ignore it.
* This is handled on a per glyph basis.
*/
if (subPixPos) {
int frac;
/* Calculate the fractional pixel position - ie the subpixel
* the nearest, even though we just do (int) since at the
* start of the loop the position was already adjusted by
* 0.5 (sub)pixels to get rounding.
* Thus the "fractional" position will be 0, 1 or 2.
* eg 0->0.32 is 0, 0.33->0.66 is 1, > 0.66->0.99 is 2.
* We can use an (int) cast here since the floor operation
* above guarantees us that the value is positive.
*/
if (frac == 0) {
/* frac rounded down to zero, so this is equivalent
* to no sub-pixel positioning.
*/
} else {
/* In this case we need to adjust both the position at
* which the glyph will be positioned by one pixel to the
* left and adjust the position in the glyph image row
* from which to extract the data
* Every glyph image row has 2 bytes padding
* on the right to account for this.
*/
}
} else {
}
}
} else {
for (g=0; g<len; g++) {
if (subPixPos) {
int frac;
if (frac == 0) {
} else {
}
} else {
}
/* copy image data into this array at x/y locations */
}
}
return gbv;
}
/* LCD text needs to go through a gamma (contrast) adjustment.
* Gamma is constrained to the range 1.0->2.2 with a quantization of
* 0.01 (more than good enough). Representing as an integer with that
* precision yields a range 100->250 thus we need to store up to 151 LUTs
* and inverse LUTs.
* We allocate the actual LUTs on an as needed basis. Typically zero or
* one is what will be needed.
* Colour component values are in the range 0.0->1.0 represented as an integer
* in the range 0->255 (ie in a byte). It is assumed that even if we have 5
* bit colour components these are presented mapped on to 8 bit components.
* lcdGammaLUT references LUTs which convert linear colour components
* to a gamma adjusted space, and
* lcdInvGammaLUT references LUTs which convert gamma adjusted colour
* components to a linear space.
*/
int i,index;
double ig,g;
if (gamma==100) {
for (i=0;i<256;i++) {
}
return;
}
g = 1.0/ig;
for (i=1;i<255;i++) {
}
}
int index;
}
if (!lcdGammaLUT[index]) {
}
return (unsigned char*)lcdGammaLUT[index];
}
int index;
}
if (!lcdInvGammaLUT[index]) {
}
return (unsigned char*)lcdInvGammaLUT[index];
}
#if 0
void printDefaultTables(int gamma) {
int i;
g = getLCDGammaLUT(gamma);
printf("UInt8 defaultGammaLUT[256] = {\n");
for (i=0;i<256;i++) {
if (i % 8 == 0) {
printf(" /* %3d */ ", i);
}
if ((i+1) % 8 == 0) {
printf("\n");
}
}
printf("};\n");
printf("UInt8 defaultInvGammaLUT[256] = {\n");
for (i=0;i<256;i++) {
if (i % 8 == 0) {
printf(" /* %3d */ ", i);
}
if ((i+1) % 8 == 0) {
printf("\n");
}
}
printf("};\n");
}
#endif
/* These tables are generated for a Gamma adjustment of 1.4 */
/* 0 */ 0, 4, 7, 10, 13, 15, 17, 19,
/* 8 */ 21, 23, 25, 27, 28, 30, 32, 33,
/* 16 */ 35, 36, 38, 39, 41, 42, 44, 45,
/* 24 */ 47, 48, 49, 51, 52, 53, 55, 56,
/* 32 */ 57, 59, 60, 61, 62, 64, 65, 66,
/* 40 */ 67, 69, 70, 71, 72, 73, 75, 76,
/* 48 */ 77, 78, 79, 80, 81, 83, 84, 85,
/* 56 */ 86, 87, 88, 89, 90, 91, 92, 93,
/* 64 */ 94, 96, 97, 98, 99, 100, 101, 102,
/* 72 */ 103, 104, 105, 106, 107, 108, 109, 110,
/* 80 */ 111, 112, 113, 114, 115, 116, 117, 118,
/* 88 */ 119, 120, 121, 122, 123, 124, 125, 125,
/* 96 */ 126, 127, 128, 129, 130, 131, 132, 133,
/* 104 */ 134, 135, 136, 137, 138, 138, 139, 140,
/* 112 */ 141, 142, 143, 144, 145, 146, 147, 147,
/* 120 */ 148, 149, 150, 151, 152, 153, 154, 154,
/* 128 */ 155, 156, 157, 158, 159, 160, 161, 161,
/* 136 */ 162, 163, 164, 165, 166, 167, 167, 168,
/* 144 */ 169, 170, 171, 172, 172, 173, 174, 175,
/* 152 */ 176, 177, 177, 178, 179, 180, 181, 181,
/* 160 */ 182, 183, 184, 185, 186, 186, 187, 188,
/* 168 */ 189, 190, 190, 191, 192, 193, 194, 194,
/* 176 */ 195, 196, 197, 198, 198, 199, 200, 201,
/* 184 */ 201, 202, 203, 204, 205, 205, 206, 207,
/* 192 */ 208, 208, 209, 210, 211, 212, 212, 213,
/* 200 */ 214, 215, 215, 216, 217, 218, 218, 219,
/* 208 */ 220, 221, 221, 222, 223, 224, 224, 225,
/* 216 */ 226, 227, 227, 228, 229, 230, 230, 231,
/* 224 */ 232, 233, 233, 234, 235, 236, 236, 237,
/* 232 */ 238, 239, 239, 240, 241, 242, 242, 243,
/* 240 */ 244, 244, 245, 246, 247, 247, 248, 249,
/* 248 */ 249, 250, 251, 252, 252, 253, 254, 255,
};
/* 0 */ 0, 0, 0, 0, 0, 1, 1, 1,
/* 8 */ 2, 2, 2, 3, 3, 3, 4, 4,
/* 16 */ 5, 5, 6, 6, 7, 7, 8, 8,
/* 24 */ 9, 9, 10, 10, 11, 12, 12, 13,
/* 32 */ 13, 14, 15, 15, 16, 17, 17, 18,
/* 40 */ 19, 19, 20, 21, 21, 22, 23, 23,
/* 48 */ 24, 25, 26, 26, 27, 28, 29, 29,
/* 56 */ 30, 31, 32, 32, 33, 34, 35, 36,
/* 64 */ 36, 37, 38, 39, 40, 40, 41, 42,
/* 72 */ 43, 44, 45, 45, 46, 47, 48, 49,
/* 80 */ 50, 51, 52, 52, 53, 54, 55, 56,
/* 88 */ 57, 58, 59, 60, 61, 62, 63, 64,
/* 96 */ 64, 65, 66, 67, 68, 69, 70, 71,
/* 104 */ 72, 73, 74, 75, 76, 77, 78, 79,
/* 112 */ 80, 81, 82, 83, 84, 85, 86, 87,
/* 120 */ 88, 89, 90, 91, 92, 93, 95, 96,
/* 128 */ 97, 98, 99, 100, 101, 102, 103, 104,
/* 136 */ 105, 106, 107, 109, 110, 111, 112, 113,
/* 144 */ 114, 115, 116, 117, 119, 120, 121, 122,
/* 152 */ 123, 124, 125, 127, 128, 129, 130, 131,
/* 160 */ 132, 133, 135, 136, 137, 138, 139, 140,
/* 168 */ 142, 143, 144, 145, 146, 148, 149, 150,
/* 176 */ 151, 152, 154, 155, 156, 157, 159, 160,
/* 184 */ 161, 162, 163, 165, 166, 167, 168, 170,
/* 192 */ 171, 172, 173, 175, 176, 177, 178, 180,
/* 200 */ 181, 182, 184, 185, 186, 187, 189, 190,
/* 208 */ 191, 193, 194, 195, 196, 198, 199, 200,
/* 216 */ 202, 203, 204, 206, 207, 208, 210, 211,
/* 224 */ 212, 214, 215, 216, 218, 219, 220, 222,
/* 232 */ 223, 224, 226, 227, 228, 230, 231, 232,
/* 240 */ 234, 235, 236, 238, 239, 241, 242, 243,
/* 248 */ 245, 246, 248, 249, 250, 252, 253, 255,
};
/* Since our default is 140, here we can populate that from pre-calculated
* data, it needs only 512 bytes - plus a few more of overhead - and saves
* about that many intrinsic function calls plus other FP calculations.
*/
void initLCDGammaTables() {
/* printDefaultTables(140); */
}