Path: blob/master/src/java.desktop/share/native/common/awt/utility/rect.c
41171 views
/*1* Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include "utility/rect.h"2627#if defined(__cplusplus)28extern "C" {29#endif3031/**32* bitsPerPixel must be 32 for now.33* outBuf must be large enough to conatin all the rectangles.34*/35int BitmapToYXBandedRectangles(int bitsPerPixel, int width, int height, unsigned char * buf, RECT_T * outBuf)36{37//XXX: we might want to reuse the code in the splashscreen library,38// though we'd have to deal with the ALPHA_THRESHOLD and different39// image formats in this case.40int widthBytes = width * bitsPerPixel / 8;41int alignedWidth = (((widthBytes - 1) / 4) + 1) * 4;4243RECT_T * out = outBuf;4445RECT_T *pPrevLine = NULL, *pFirst = out, *pThis = pFirst;46int i, j, i0;47int length;4849for (j = 0; j < height; j++) {50/* generate data for a scanline */5152unsigned char *pSrc = (unsigned char *) buf + j * alignedWidth;53RECT_T *pLine = pThis;5455i = 0;5657do {58// pSrc[0,1,2] == B,G,R; pSrc[3] == Alpha59while (i < width && !pSrc[3]) {60pSrc += 4;61++i;62}63if (i >= width)64break;65i0 = i;66while (i < width && pSrc[3]) {67pSrc += 4;68++i;69}70RECT_SET(*pThis, i0, j, i - i0, 1);71++pThis;72} while (i < width);7374/* check if the previous scanline is exactly the same, merge if so75(this is the only optimization we can use for YXBanded rectangles,76and win32 supports YXBanded only */7778length = pThis - pLine;79if (pPrevLine && pLine - pPrevLine == length) {80for (i = 0; i < length && RECT_EQ_X(pPrevLine[i], pLine[i]); ++i) {81}82if (i == pLine - pPrevLine) {83// do merge84for (i = 0; i < length; i++) {85RECT_INC_HEIGHT(pPrevLine[i]);86}87pThis = pLine;88continue;89}90}91/* or else use the generated scanline */9293pPrevLine = pLine;94}9596return pThis - pFirst;97}9899#if defined(__cplusplus)100}101#endif102103104