2013-07-19 04:13:41 +08:00
|
|
|
/****************************************************************************
|
2013-10-29 20:25:03 +08:00
|
|
|
Copyright (c) 2013 Zynga Inc.
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
|
|
|
|
2013-10-29 20:25:03 +08:00
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2013-07-12 06:43:45 +08:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2013-10-29 20:25:03 +08:00
|
|
|
#include <algorithm>
|
2013-08-07 05:37:19 +08:00
|
|
|
|
2013-10-14 14:01:00 +08:00
|
|
|
#include "ccUTF8.h"
|
2013-07-12 06:43:45 +08:00
|
|
|
#include "CCFontFreeType.h"
|
2014-01-17 13:35:58 +08:00
|
|
|
#include "platform/CCFileUtils.h"
|
2014-01-21 10:36:32 +08:00
|
|
|
#include "edtaa3func.h"
|
2013-07-12 06:43:45 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-07-17 06:18:39 +08:00
|
|
|
|
|
|
|
FT_Library FontFreeType::_FTlibrary;
|
|
|
|
bool FontFreeType::_FTInitialized = false;
|
2014-01-21 10:36:32 +08:00
|
|
|
const int FontFreeType::DistanceMapSpread = 3;
|
2013-07-17 06:18:39 +08:00
|
|
|
|
2013-08-07 04:43:29 +08:00
|
|
|
FontFreeType * FontFreeType::create(const std::string &fontName, int fontSize, GlyphCollection glyphs, const char *customGlyphs)
|
2013-08-06 06:56:18 +08:00
|
|
|
{
|
2014-01-20 10:32:12 +08:00
|
|
|
FontFreeType *tempFont = new FontFreeType();
|
2013-10-29 20:25:03 +08:00
|
|
|
|
2013-08-07 04:43:29 +08:00
|
|
|
if (!tempFont)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
tempFont->setCurrentGlyphCollection(glyphs, customGlyphs);
|
|
|
|
|
2013-09-13 11:46:46 +08:00
|
|
|
if (!tempFont->createFontObject(fontName, fontSize))
|
2013-08-07 04:43:29 +08:00
|
|
|
{
|
|
|
|
delete tempFont;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return tempFont;
|
2013-08-06 06:56:18 +08:00
|
|
|
}
|
2013-07-17 06:18:39 +08:00
|
|
|
|
|
|
|
bool FontFreeType::initFreeType()
|
2013-07-12 06:43:45 +08:00
|
|
|
{
|
2013-07-17 06:18:39 +08:00
|
|
|
if (_FTInitialized == false)
|
|
|
|
{
|
|
|
|
// begin freetype
|
|
|
|
if (FT_Init_FreeType( &_FTlibrary ))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
_FTInitialized = true;
|
|
|
|
}
|
2013-07-12 06:43:45 +08:00
|
|
|
|
2013-07-17 06:18:39 +08:00
|
|
|
return _FTInitialized;
|
2013-07-12 06:43:45 +08:00
|
|
|
}
|
|
|
|
|
2013-07-17 06:18:39 +08:00
|
|
|
void FontFreeType::shutdownFreeType()
|
2013-07-12 06:43:45 +08:00
|
|
|
{
|
2013-07-17 06:18:39 +08:00
|
|
|
if (_FTInitialized == true)
|
|
|
|
{
|
|
|
|
FT_Done_FreeType(_FTlibrary);
|
2013-10-29 20:25:03 +08:00
|
|
|
_FTInitialized = false;
|
2013-07-17 06:18:39 +08:00
|
|
|
}
|
2013-07-12 06:43:45 +08:00
|
|
|
}
|
|
|
|
|
2013-07-17 06:18:39 +08:00
|
|
|
FT_Library FontFreeType::getFTLibrary()
|
2013-07-12 06:43:45 +08:00
|
|
|
{
|
2013-07-17 06:18:39 +08:00
|
|
|
initFreeType();
|
|
|
|
return _FTlibrary;
|
|
|
|
}
|
|
|
|
|
2014-01-20 10:32:12 +08:00
|
|
|
FontFreeType::FontFreeType()
|
2014-01-22 14:57:11 +08:00
|
|
|
: _fontRef(nullptr)
|
2014-01-21 10:36:32 +08:00
|
|
|
,_distanceFieldEnabled(false)
|
2013-07-17 06:18:39 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FontFreeType::createFontObject(const std::string &fontName, int fontSize)
|
|
|
|
{
|
2013-10-29 20:25:03 +08:00
|
|
|
FT_Face face;
|
|
|
|
|
2013-12-23 11:53:39 +08:00
|
|
|
_ttfData = FileUtils::getInstance()->getDataFromFile(fontName);
|
2013-12-18 14:58:17 +08:00
|
|
|
|
2013-12-23 11:53:39 +08:00
|
|
|
if (_ttfData.isNull())
|
2013-07-17 06:18:39 +08:00
|
|
|
return false;
|
2013-10-29 20:25:03 +08:00
|
|
|
|
2013-07-17 06:18:39 +08:00
|
|
|
// create the face from the data
|
2013-12-23 11:53:39 +08:00
|
|
|
if (FT_New_Memory_Face(getFTLibrary(), _ttfData.getBytes(), _ttfData.getSize(), 0, &face ))
|
2013-07-17 06:18:39 +08:00
|
|
|
return false;
|
2013-10-29 20:25:03 +08:00
|
|
|
|
2013-07-17 06:18:39 +08:00
|
|
|
//we want to use unicode
|
2013-09-13 11:46:46 +08:00
|
|
|
if (FT_Select_Charmap(face, FT_ENCODING_UNICODE))
|
2013-07-12 06:43:45 +08:00
|
|
|
return false;
|
2013-10-29 20:25:03 +08:00
|
|
|
|
2013-07-17 06:18:39 +08:00
|
|
|
// set the requested font size
|
2013-10-29 20:25:03 +08:00
|
|
|
int dpi = 72;
|
|
|
|
int fontSizePoints = (int)(64.f * fontSize);
|
|
|
|
if (FT_Set_Char_Size(face, fontSizePoints, fontSizePoints, dpi, dpi))
|
2013-07-17 06:18:39 +08:00
|
|
|
return false;
|
2013-07-12 06:43:45 +08:00
|
|
|
|
2013-07-17 06:18:39 +08:00
|
|
|
// store the face globally
|
|
|
|
_fontRef = face;
|
2013-07-12 06:43:45 +08:00
|
|
|
|
2013-07-30 04:43:23 +08:00
|
|
|
// save font name locally
|
|
|
|
_fontName = fontName;
|
|
|
|
|
2013-07-17 06:18:39 +08:00
|
|
|
// done and good
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
FontFreeType::~FontFreeType()
|
|
|
|
{
|
2013-10-29 20:25:03 +08:00
|
|
|
if (_fontRef)
|
|
|
|
{
|
|
|
|
FT_Done_Face(_fontRef);
|
|
|
|
}
|
2013-07-17 06:18:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-06 06:11:07 +08:00
|
|
|
FontAtlas * FontFreeType::createFontAtlas()
|
|
|
|
{
|
2014-01-20 10:32:12 +08:00
|
|
|
FontAtlas *atlas = new FontAtlas(*this);
|
|
|
|
if (_usedGlyphs != GlyphCollection::DYNAMIC)
|
2013-10-29 20:25:03 +08:00
|
|
|
{
|
2014-01-20 10:32:12 +08:00
|
|
|
atlas->prepareLetterDefinitions(cc_utf8_to_utf16(getCurrentGlyphCollection()));
|
|
|
|
}
|
|
|
|
this->release();
|
|
|
|
return atlas;
|
2013-08-06 06:11:07 +08:00
|
|
|
}
|
|
|
|
|
2014-01-21 17:55:49 +08:00
|
|
|
bool FontFreeType::getBBOXFotChar(unsigned short theChar, Rect &outRect, int &xAdvance) const
|
2013-07-17 06:18:39 +08:00
|
|
|
{
|
|
|
|
if (!_fontRef)
|
|
|
|
return false;
|
2013-07-12 06:43:45 +08:00
|
|
|
|
2013-07-17 06:18:39 +08:00
|
|
|
// get the ID to the char we need
|
|
|
|
int glyph_index = FT_Get_Char_Index(_fontRef, theChar);
|
2013-07-12 06:43:45 +08:00
|
|
|
|
2013-07-17 06:18:39 +08:00
|
|
|
if (!glyph_index)
|
|
|
|
return false;
|
2013-07-12 06:43:45 +08:00
|
|
|
|
2013-07-17 06:18:39 +08:00
|
|
|
// load glyph infos
|
|
|
|
if (FT_Load_Glyph(_fontRef, glyph_index, FT_LOAD_DEFAULT))
|
|
|
|
return false;
|
2013-07-12 06:43:45 +08:00
|
|
|
|
2013-07-17 06:18:39 +08:00
|
|
|
// store result in the passed rectangle
|
2014-01-17 14:04:52 +08:00
|
|
|
outRect.origin.x = _fontRef->glyph->metrics.horiBearingX >> 6;
|
2013-07-17 06:18:39 +08:00
|
|
|
outRect.origin.y = - (_fontRef->glyph->metrics.horiBearingY >> 6);
|
|
|
|
outRect.size.width = (_fontRef->glyph->metrics.width >> 6);
|
|
|
|
outRect.size.height = (_fontRef->glyph->metrics.height >> 6);
|
2013-07-12 06:43:45 +08:00
|
|
|
|
2014-01-21 17:55:49 +08:00
|
|
|
xAdvance = (static_cast<int>(_fontRef->glyph->metrics.horiAdvance >> 6));
|
|
|
|
|
2013-07-17 06:18:39 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-21 17:55:49 +08:00
|
|
|
int * FontFreeType::getHorizontalKerningForTextUTF16(unsigned short *text, int &outNumLetters) const
|
2013-07-12 06:43:45 +08:00
|
|
|
{
|
2013-09-13 11:46:46 +08:00
|
|
|
if (!text)
|
2013-07-12 06:43:45 +08:00
|
|
|
return 0;
|
|
|
|
|
2013-09-13 11:46:46 +08:00
|
|
|
outNumLetters = cc_wcslen(text);
|
2013-07-12 06:43:45 +08:00
|
|
|
|
|
|
|
if (!outNumLetters)
|
|
|
|
return 0;
|
|
|
|
|
2014-01-21 17:55:49 +08:00
|
|
|
int *sizes = new int[outNumLetters];
|
2013-09-13 11:46:46 +08:00
|
|
|
if (!sizes)
|
2013-07-17 06:18:39 +08:00
|
|
|
return 0;
|
2013-07-12 06:43:45 +08:00
|
|
|
|
2013-09-13 11:46:46 +08:00
|
|
|
for (int c = 0; c < outNumLetters; ++c)
|
2013-07-12 06:43:45 +08:00
|
|
|
{
|
2013-09-13 11:46:46 +08:00
|
|
|
if (c < (outNumLetters-1))
|
2014-01-21 17:55:49 +08:00
|
|
|
sizes[c] = getHorizontalKerningForChars(text[c], text[c+1]);
|
|
|
|
else
|
|
|
|
sizes[c] = 0;
|
2013-07-12 06:43:45 +08:00
|
|
|
}
|
|
|
|
|
2013-09-13 11:46:46 +08:00
|
|
|
return sizes;
|
2013-07-17 06:18:39 +08:00
|
|
|
}
|
|
|
|
|
2013-09-13 11:46:46 +08:00
|
|
|
int FontFreeType::getHorizontalKerningForChars(unsigned short firstChar, unsigned short secondChar) const
|
2013-07-17 06:18:39 +08:00
|
|
|
{
|
|
|
|
if (!_fontRef)
|
2013-07-18 08:31:28 +08:00
|
|
|
return 0;
|
|
|
|
|
2013-08-15 21:39:03 +08:00
|
|
|
bool hasKerning = FT_HAS_KERNING( _fontRef ) != 0;
|
2013-07-18 08:31:28 +08:00
|
|
|
|
|
|
|
if (!hasKerning)
|
|
|
|
return 0;
|
2013-07-12 06:43:45 +08:00
|
|
|
|
2013-07-17 06:18:39 +08:00
|
|
|
// get the ID to the char we need
|
2013-09-13 11:46:46 +08:00
|
|
|
int glyphIndex1 = FT_Get_Char_Index(_fontRef, firstChar);
|
2013-07-12 06:43:45 +08:00
|
|
|
|
2013-09-13 11:46:46 +08:00
|
|
|
if (!glyphIndex1)
|
2013-07-18 08:31:28 +08:00
|
|
|
return 0;
|
2013-07-12 06:43:45 +08:00
|
|
|
|
2013-07-17 06:18:39 +08:00
|
|
|
// get the ID to the char we need
|
2013-09-13 11:46:46 +08:00
|
|
|
int glyphIndex2 = FT_Get_Char_Index(_fontRef, secondChar);
|
2013-07-12 06:43:45 +08:00
|
|
|
|
2013-09-13 11:46:46 +08:00
|
|
|
if (!glyphIndex2)
|
2013-07-18 08:31:28 +08:00
|
|
|
return 0;
|
2013-07-12 06:43:45 +08:00
|
|
|
|
2013-07-17 06:18:39 +08:00
|
|
|
FT_Vector kerning;
|
2013-07-12 06:43:45 +08:00
|
|
|
|
2013-09-13 11:46:46 +08:00
|
|
|
if (FT_Get_Kerning( _fontRef, glyphIndex1, glyphIndex2, FT_KERNING_DEFAULT, &kerning))
|
2013-07-18 08:31:28 +08:00
|
|
|
return 0;
|
2013-07-12 06:43:45 +08:00
|
|
|
|
2013-12-06 16:32:06 +08:00
|
|
|
return (static_cast<int>(kerning.x >> 6));
|
2013-07-12 06:43:45 +08:00
|
|
|
}
|
|
|
|
|
2013-09-13 11:46:46 +08:00
|
|
|
int FontFreeType::getFontMaxHeight() const
|
2013-07-20 01:33:26 +08:00
|
|
|
{
|
2013-12-06 16:32:06 +08:00
|
|
|
return (static_cast<int>(_fontRef->size->metrics.height >> 6));
|
2013-07-20 01:33:26 +08:00
|
|
|
}
|
|
|
|
|
2013-12-13 12:42:15 +08:00
|
|
|
unsigned char * FontFreeType::getGlyphBitmap(unsigned short theChar, int &outWidth, int &outHeight) const
|
2013-07-12 06:43:45 +08:00
|
|
|
{
|
2013-07-17 06:18:39 +08:00
|
|
|
if (!_fontRef)
|
2013-07-12 06:43:45 +08:00
|
|
|
return 0;
|
|
|
|
|
2013-12-13 12:42:15 +08:00
|
|
|
if (_distanceFieldEnabled)
|
|
|
|
{
|
|
|
|
if (FT_Load_Char(_fontRef,theChar,FT_LOAD_RENDER | FT_LOAD_NO_HINTING | FT_LOAD_NO_AUTOHINT))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (FT_Load_Char(_fontRef,theChar,FT_LOAD_RENDER))
|
|
|
|
return 0;
|
|
|
|
}
|
2013-07-12 06:43:45 +08:00
|
|
|
|
2013-07-17 06:18:39 +08:00
|
|
|
outWidth = _fontRef->glyph->bitmap.width;
|
|
|
|
outHeight = _fontRef->glyph->bitmap.rows;
|
2013-07-12 06:43:45 +08:00
|
|
|
|
2013-07-17 06:18:39 +08:00
|
|
|
// return the pointer to the bitmap
|
|
|
|
return _fontRef->glyph->bitmap.buffer;
|
2013-07-12 06:43:45 +08:00
|
|
|
}
|
|
|
|
|
2014-01-21 10:36:32 +08:00
|
|
|
unsigned char * makeDistanceMap( unsigned char *img, unsigned int width, unsigned int height)
|
|
|
|
{
|
|
|
|
unsigned int pixelAmount = (width + 2 * FontFreeType::DistanceMapSpread) * (height + 2 * FontFreeType::DistanceMapSpread);
|
|
|
|
|
|
|
|
short * xdist = (short *) malloc( pixelAmount * sizeof(short) );
|
|
|
|
short * ydist = (short *) malloc( pixelAmount * sizeof(short) );
|
|
|
|
double * gx = (double *) calloc( pixelAmount, sizeof(double) );
|
|
|
|
double * gy = (double *) calloc( pixelAmount, sizeof(double) );
|
|
|
|
double * data = (double *) calloc( pixelAmount, sizeof(double) );
|
|
|
|
double * outside = (double *) calloc( pixelAmount, sizeof(double) );
|
|
|
|
double * inside = (double *) calloc( pixelAmount, sizeof(double) );
|
|
|
|
unsigned int i,j;
|
|
|
|
|
|
|
|
// Convert img into double (data) rescale image levels between 0 and 1
|
|
|
|
unsigned int outWidth = width + 2 * FontFreeType::DistanceMapSpread;
|
|
|
|
for (i = 0; i < width; ++i)
|
|
|
|
{
|
|
|
|
for (j = 0; j < height; ++j)
|
|
|
|
{
|
|
|
|
data[j * outWidth + FontFreeType::DistanceMapSpread + i] = img[j * width + i] / 255.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
width += 2 * FontFreeType::DistanceMapSpread;
|
|
|
|
height += 2 * FontFreeType::DistanceMapSpread;
|
|
|
|
|
|
|
|
// Transform background (outside contour, in areas of 0's)
|
|
|
|
computegradient( data, width, height, gx, gy);
|
|
|
|
edtaa3(data, gx, gy, width, height, xdist, ydist, outside);
|
|
|
|
for( i=0; i< pixelAmount; i++)
|
|
|
|
if( outside[i] < 0.0 )
|
|
|
|
outside[i] = 0.0;
|
|
|
|
|
|
|
|
// Transform foreground (inside contour, in areas of 1's)
|
|
|
|
for( i=0; i< pixelAmount; i++)
|
|
|
|
data[i] = 1 - data[i];
|
|
|
|
computegradient( data, width, height, gx, gy);
|
|
|
|
edtaa3(data, gx, gy, width, height, xdist, ydist, inside);
|
|
|
|
for( i=0; i< pixelAmount; i++)
|
|
|
|
if( inside[i] < 0.0 )
|
|
|
|
inside[i] = 0.0;
|
|
|
|
|
|
|
|
// The bipolar distance field is now outside-inside
|
|
|
|
double dist;
|
|
|
|
/* Single channel 8-bit output (bad precision and range, but simple) */
|
|
|
|
unsigned char *out = (unsigned char *) malloc( pixelAmount * sizeof(unsigned char) );
|
|
|
|
for( i=0; i < pixelAmount; i++)
|
|
|
|
{
|
|
|
|
dist = outside[i] - inside[i];
|
|
|
|
dist = 128.0 - dist*16;
|
|
|
|
if( dist < 0 ) dist = 0;
|
|
|
|
if( dist > 255 ) dist = 255;
|
|
|
|
out[i] = (unsigned char) dist;
|
|
|
|
}
|
|
|
|
/* Dual channel 16-bit output (more complicated, but good precision and range) */
|
|
|
|
/*unsigned char *out = (unsigned char *) malloc( pixelAmount * 3 * sizeof(unsigned char) );
|
|
|
|
for( i=0; i< pixelAmount; i++)
|
|
|
|
{
|
|
|
|
dist = outside[i] - inside[i];
|
|
|
|
dist = 128.0 - dist*16;
|
|
|
|
if( dist < 0.0 ) dist = 0.0;
|
|
|
|
if( dist >= 256.0 ) dist = 255.999;
|
|
|
|
// R channel is a copy of the original grayscale image
|
|
|
|
out[3*i] = img[i];
|
|
|
|
// G channel is fraction
|
|
|
|
out[3*i + 1] = (unsigned char) ( 256 - (dist - floor(dist)* 256.0 ));
|
|
|
|
// B channel is truncated integer part
|
|
|
|
out[3*i + 2] = (unsigned char)dist;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
free( xdist );
|
|
|
|
free( ydist );
|
|
|
|
free( gx );
|
|
|
|
free( gy );
|
|
|
|
free( data );
|
|
|
|
free( outside );
|
|
|
|
free( inside );
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FontFreeType::setDistanceFieldEnabled(bool distanceFieldEnabled)
|
|
|
|
{
|
|
|
|
_distanceFieldEnabled = distanceFieldEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FontFreeType::renderCharAt(unsigned short int charToRender, int posX, int posY, unsigned char *destMemory, int destSize)
|
|
|
|
{
|
|
|
|
unsigned char *sourceBitmap = 0;
|
|
|
|
int sourceWidth = 0;
|
|
|
|
int sourceHeight = 0;
|
|
|
|
|
|
|
|
sourceBitmap = getGlyphBitmap(charToRender, sourceWidth, sourceHeight);
|
|
|
|
|
|
|
|
if (!sourceBitmap)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (_distanceFieldEnabled)
|
|
|
|
{
|
|
|
|
unsigned char * out = makeDistanceMap(sourceBitmap,sourceWidth,sourceHeight);
|
|
|
|
|
|
|
|
int iX = posX;
|
|
|
|
int iY = posY;
|
|
|
|
|
|
|
|
sourceWidth += 2 * DistanceMapSpread;
|
|
|
|
sourceHeight += 2 * DistanceMapSpread;
|
|
|
|
|
|
|
|
for (int y = 0; y < sourceHeight; ++y)
|
|
|
|
{
|
|
|
|
int bitmap_y = y * sourceWidth;
|
|
|
|
|
|
|
|
for (int x = 0; x < sourceWidth; ++x)
|
|
|
|
{
|
|
|
|
/* Dual channel 16-bit output (more complicated, but good precision and range) */
|
|
|
|
/*int index = (iX + ( iY * destSize )) * 3;
|
|
|
|
int index2 = (bitmap_y + x)*3;
|
|
|
|
destMemory[index] = out[index2];
|
|
|
|
destMemory[index + 1] = out[index2 + 1];
|
|
|
|
destMemory[index + 2] = out[index2 + 2];*/
|
|
|
|
|
|
|
|
//Single channel 8-bit output
|
|
|
|
destMemory[iX + ( iY * destSize )] = out[bitmap_y + x];
|
|
|
|
|
|
|
|
iX += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
iX = posX;
|
|
|
|
iY += 1;
|
|
|
|
}
|
|
|
|
free(out);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int iX = posX;
|
|
|
|
int iY = posY;
|
|
|
|
|
|
|
|
for (int y = 0; y < sourceHeight; ++y)
|
|
|
|
{
|
|
|
|
int bitmap_y = y * sourceWidth;
|
|
|
|
|
|
|
|
for (int x = 0; x < sourceWidth; ++x)
|
|
|
|
{
|
|
|
|
unsigned char cTemp = sourceBitmap[bitmap_y + x];
|
|
|
|
|
|
|
|
// the final pixel
|
|
|
|
destMemory[(iX + ( iY * destSize ) )] = cTemp;
|
|
|
|
|
|
|
|
iX += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
iX = posX;
|
|
|
|
iY += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//everything good
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-12 06:43:45 +08:00
|
|
|
NS_CC_END
|