|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzCore includes
|
|
Toshihiro Shimizu |
890ddd |
#include "tcommon.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "timageinfo.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "timage_io.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tlevel_io.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "ttoonzimage.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tvectorimage.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "trastercm.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tvectorrenderdata.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tpalette.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tgl.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tvectorgl.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tofflinegl.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "timagecache.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzLib includes
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshleveltypes.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/levelproperties.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshsimplelevel.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/fill.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Qt includes
|
|
Toshihiro Shimizu |
890ddd |
#include <qglcontext></qglcontext>
|
|
Toshihiro Shimizu |
890ddd |
#include <qglpixelbuffer></qglpixelbuffer>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "imagebuilders.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//***************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// Global stuff
|
|
Toshihiro Shimizu |
890ddd |
//***************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
extern TOfflineGL *currentOfflineGL;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QGLPixelBuffer *imageRasterizerPixelBuffer = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void DV_EXPORT_API initializeImageRasterizer()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(QGLPixelBuffer::hasOpenGLPbuffers());
|
|
Toshihiro Shimizu |
890ddd |
if (!QGLPixelBuffer::hasOpenGLPbuffers()) {
|
|
Toshihiro Shimizu |
890ddd |
imageRasterizerPixelBuffer = 0;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
imageRasterizerPixelBuffer = new QGLPixelBuffer(QSize(1024, 1024));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//***************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// ImageLoader implementation
|
|
Toshihiro Shimizu |
890ddd |
//***************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ImageLoader::ImageLoader(const TFilePath &path, const TFrameId &fid)
|
|
Toshihiro Shimizu |
890ddd |
: m_path(path), m_fid(fid), m_subsampling(0), m_64bitCompatible(false)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool ImageLoader::getInfo(TImageInfo &info, int imFlags, void *extData)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
try {
|
|
Toshihiro Shimizu |
890ddd |
TLevelReaderP lr(m_path);
|
|
Toshihiro Shimizu |
890ddd |
TImageReaderP fr = lr->getFrameReader(m_fid);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// NOTE: Currently not changing imageInfo's bpp stuff...
|
|
Toshihiro Shimizu |
890ddd |
// Ignoring subsampling too...
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return ImageBuilder::setImageInfo(info, fr.getPointer());
|
|
Toshihiro Shimizu |
890ddd |
} catch (TException &e) {
|
|
Toshihiro Shimizu |
890ddd |
QString msg = QString::fromStdWString(e.getMessage());
|
|
Toshihiro Shimizu |
890ddd |
if (msg == QString("Old 4.1 Palette"))
|
|
Toshihiro Shimizu |
890ddd |
throw;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline int ImageLoader::buildSubsampling(int imFlags, BuildExtData *data)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return (imFlags & ImageManager::toBeModified) ? 1 : (data->m_subs > 0) ? data->m_subs : (m_subsampling > 0) ? m_subsampling : data->m_sl->getProperties()->getSubsampling();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageP ImageLoader::build(int imFlags, void *extData)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(extData);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Extract external data
|
|
Toshihiro Shimizu |
890ddd |
BuildExtData *data = static_cast<buildextdata *="">(extData);</buildextdata>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int subsampling = buildSubsampling(imFlags, data);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
try {
|
|
Toshihiro Shimizu |
890ddd |
// Initialize level reader
|
|
Toshihiro Shimizu |
890ddd |
TLevelReaderP lr(m_path);
|
|
Toshihiro Shimizu |
890ddd |
if (!lr)
|
|
Toshihiro Shimizu |
890ddd |
return TImageP();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Load info in cases where it's required first
|
|
Toshihiro Shimizu |
890ddd |
lr->doReadPalette(false);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if ((m_path.getType() == "pli") || (m_path.getType() == "svg") || (m_path.getType() == "psd"))
|
|
Toshihiro Shimizu |
890ddd |
lr->loadInfo();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
lr->doReadPalette(true); // Allow palette loading
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageReaderP ir = lr->getFrameReader(m_fid);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool enable64bit = (imFlags & ImageManager::is64bitEnabled);
|
|
Toshihiro Shimizu |
890ddd |
ir->enable16BitRead(enable64bit); // Set 64-bit loading if required
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Load the image
|
|
Toshihiro Shimizu |
890ddd |
TImageP img;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (data->m_icon && m_path.getType() == "tlv")
|
|
Toshihiro Shimizu |
890ddd |
img = ir->loadIcon(); // TODO: Why just in the tlv case??
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
ir->setShrink(subsampling);
|
|
Toshihiro Shimizu |
890ddd |
img = ir->load();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ir->enable16BitRead(false);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!img)
|
|
Toshihiro Shimizu |
890ddd |
return img; // There was an error loading the image.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPalette *palette = data->m_sl->getPalette();
|
|
Toshihiro Shimizu |
890ddd |
if (palette)
|
|
Toshihiro Shimizu |
890ddd |
img->setPalette(palette);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (subsampling > 1) {
|
|
Toshihiro Shimizu |
890ddd |
// Store the subsampling info in the image
|
|
Toshihiro Shimizu |
890ddd |
if (TRasterImageP ri = img)
|
|
Toshihiro Shimizu |
890ddd |
ri->setSubsampling(subsampling);
|
|
Toshihiro Shimizu |
890ddd |
else if (TToonzImageP ti = img)
|
|
Toshihiro Shimizu |
890ddd |
ti->setSubsampling(subsampling);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// In case the image will be cached, store its subsampling and 64 bit compatibility
|
|
Toshihiro Shimizu |
890ddd |
if (!(imFlags & ImageManager::dontPutInCache)) {
|
|
Toshihiro Shimizu |
890ddd |
m_subsampling = subsampling;
|
|
Toshihiro Shimizu |
890ddd |
m_64bitCompatible = data->m_sl->is16BitChannelLevel() ? enable64bit : true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return img;
|
|
Toshihiro Shimizu |
890ddd |
} catch (...) {
|
|
Toshihiro Shimizu |
890ddd |
return TImageP();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool ImageLoader::isImageCompatible(int imFlags, void *extData)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(extData);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
BuildExtData *data = static_cast<buildextdata *="">(extData);</buildextdata>
|
|
Toshihiro Shimizu |
890ddd |
const TXshSimpleLevel *sl = data->m_sl;
|
|
Toshihiro Shimizu |
890ddd |
if (sl->getType() == PLI_XSHLEVEL)
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int subsampling = buildSubsampling(imFlags, data);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_subsampling <= 0 || subsampling != m_subsampling)
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return (m_64bitCompatible || !(imFlags & ImageManager::is64bitEnabled));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void ImageLoader::invalidate()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
ImageBuilder::invalidate();
|
|
Toshihiro Shimizu |
890ddd |
m_subsampling = 0;
|
|
Toshihiro Shimizu |
890ddd |
m_64bitCompatible = false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*-- ImageBuilder仮想関数の実装。アイコン、画像をLoad時に全てキャッシュに格納する --*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void ImageLoader::buildAllIconsAndPutInCache(TXshSimpleLevel *level,
|
|
Toshihiro Shimizu |
890ddd |
std::vector<tframeid> fids,</tframeid>
|
|
Toshihiro Shimizu |
890ddd |
std::vector<std::string> iconIds,</std::string>
|
|
Toshihiro Shimizu |
890ddd |
bool cacheImagesAsWell)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_path.getType() != "tlv")
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
if (fids.empty() || iconIds.empty())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
/*- fidとアイコンidの数は同じはず -*/
|
|
Toshihiro Shimizu |
890ddd |
if ((int)fids.size() != (int)iconIds.size())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
try {
|
|
Toshihiro Shimizu |
890ddd |
TLevelReaderP lr(m_path);
|
|
Toshihiro Shimizu |
890ddd |
if (!lr)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < (int)fids.size(); i++) {
|
|
Toshihiro Shimizu |
890ddd |
lr->doReadPalette(false);
|
|
Toshihiro Shimizu |
890ddd |
TImageReaderP ir = lr->getFrameReader(fids[i]);
|
|
Toshihiro Shimizu |
890ddd |
lr->doReadPalette(true);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageInfo info;
|
|
Toshihiro Shimizu |
890ddd |
TPalette *palette = level->getPalette();
|
|
Toshihiro Shimizu |
890ddd |
std::string fullImgId = level->getImageId(fids[i]);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*- 画像データも一緒にキャッシュする場合 -*/
|
|
Toshihiro Shimizu |
890ddd |
if (cacheImagesAsWell) {
|
|
Toshihiro Shimizu |
890ddd |
ir->enable16BitRead(m_64bitCompatible);
|
|
Toshihiro Shimizu |
890ddd |
ir->setShrink(1);
|
|
Toshihiro Shimizu |
890ddd |
TImageP fullImg = ir->load();
|
|
Toshihiro Shimizu |
890ddd |
if (fullImg) {
|
|
Toshihiro Shimizu |
890ddd |
if (palette)
|
|
Toshihiro Shimizu |
890ddd |
fullImg->setPalette(palette);
|
|
Toshihiro Shimizu |
890ddd |
TImageCache::instance()->add(fullImgId, fullImg, true);
|
|
Toshihiro Shimizu |
890ddd |
setImageInfo(info, fullImg.getPointer());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*- アイコンのロード -*/
|
|
Toshihiro Shimizu |
890ddd |
TImageP img = ir->loadIcon();
|
|
Toshihiro Shimizu |
890ddd |
ir->enable16BitRead(false);
|
|
Toshihiro Shimizu |
890ddd |
if (img) {
|
|
Toshihiro Shimizu |
890ddd |
if (palette)
|
|
Toshihiro Shimizu |
890ddd |
img->setPalette(palette);
|
|
Toshihiro Shimizu |
890ddd |
TImageCache::instance()->add(iconIds[i], img, true);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} catch (...) {
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//***************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// ImageRasterizer implementation
|
|
Toshihiro Shimizu |
890ddd |
//***************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool ImageRasterizer::getInfo(TImageInfo &info, int imFlags, void *extData)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(false); // None should get these... in case, TODO
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageP ImageRasterizer::build(int imFlags, void *extData)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(!(imFlags & ~(ImageManager::dontPutInCache | ImageManager::forceRebuild)));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TDimension d(10, 10);
|
|
Toshihiro Shimizu |
890ddd |
TPoint off(0, 0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Fetch image
|
|
Toshihiro Shimizu |
890ddd |
assert(extData);
|
|
Toshihiro Shimizu |
890ddd |
ImageLoader::BuildExtData *data = (ImageLoader::BuildExtData *)extData;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const std::string &srcImgId = data->m_sl->getImageId(data->m_fid);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageP img = ImageManager::instance()->getImage(srcImgId, imFlags, extData);
|
|
Toshihiro Shimizu |
890ddd |
if (img) {
|
|
Toshihiro Shimizu |
890ddd |
TVectorImageP vi = img;
|
|
Toshihiro Shimizu |
890ddd |
if (vi) {
|
|
Toshihiro Shimizu |
890ddd |
TRectD bbox = vi->getBBox();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
d = TDimension(tceil(bbox.getLx()) + 1, tceil(bbox.getLy()) + 1);
|
|
Toshihiro Shimizu |
890ddd |
off = TPoint((int)bbox.x0, (int)bbox.y0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPalette *vpalette = vi->getPalette();
|
|
Toshihiro Shimizu |
890ddd |
TVectorRenderData rd(TTranslation(-off.x, -off.y), TRect(TPoint(0, 0), d), vpalette, 0, true, true);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TGlContext oldContext = tglGetCurrentContext();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (imageRasterizerPixelBuffer == 0) {
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P ras(d);
|
|
Toshihiro Shimizu |
890ddd |
TRasterImageP ri(ras);
|
|
Toshihiro Shimizu |
890ddd |
ri->setOffset(off + ras->getCenter());
|
|
Toshihiro Shimizu |
890ddd |
return ri;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QGLPixelBuffer *gl = imageRasterizerPixelBuffer; // (QSize(d.lx, d.ly));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
gl->makeCurrent();
|
|
Toshihiro Shimizu |
890ddd |
assert(glGetError() == 0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glViewport(0, 0, 1024, 1024); // d.lx,d.ly);
|
|
Toshihiro Shimizu |
890ddd |
glMatrixMode(GL_PROJECTION);
|
|
Toshihiro Shimizu |
890ddd |
glLoadIdentity();
|
|
Toshihiro Shimizu |
890ddd |
gluOrtho2D(0, d.lx, 0, d.ly);
|
|
Toshihiro Shimizu |
890ddd |
glMatrixMode(GL_MODELVIEW);
|
|
Toshihiro Shimizu |
890ddd |
glLoadIdentity();
|
|
Toshihiro Shimizu |
890ddd |
glTranslatef(0.375, 0.375, 0.0);
|
|
Toshihiro Shimizu |
890ddd |
glClearColor(0, 0, 0, 0);
|
|
Toshihiro Shimizu |
890ddd |
glClear(GL_COLOR_BUFFER_BIT);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(glGetError() == 0);
|
|
Toshihiro Shimizu |
890ddd |
tglDraw(rd, vi.getPointer());
|
|
Toshihiro Shimizu |
890ddd |
assert(glGetError() == 0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(glGetError() == 0);
|
|
Toshihiro Shimizu |
890ddd |
glFlush();
|
|
Toshihiro Shimizu |
890ddd |
assert(glGetError() == 0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QImage img = gl->toImage().scaled(QSize(d.lx, d.ly), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P ras(d);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int wrap = ras->getLx() * sizeof(TPixel32);
|
|
Toshihiro Shimizu |
890ddd |
uchar *srcPix = img.bits();
|
|
Toshihiro Shimizu |
890ddd |
uchar *dstPix = ras->getRawData() + wrap * (d.ly - 1);
|
|
Toshihiro Shimizu |
890ddd |
for (int y = 0; y < d.ly; y++) {
|
|
Toshihiro Shimizu |
890ddd |
memcpy(dstPix, srcPix, wrap);
|
|
Toshihiro Shimizu |
890ddd |
dstPix -= wrap;
|
|
Toshihiro Shimizu |
890ddd |
srcPix += wrap;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
gl->doneCurrent();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
tglMakeCurrent(oldContext);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRasterImageP ri = TRasterImageP(ras);
|
|
Toshihiro Shimizu |
890ddd |
ri->setOffset(off + ras->getCenter());
|
|
Toshihiro Shimizu |
890ddd |
return ri;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Error case: return a dummy image (is it really required?)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P ras(d);
|
|
Toshihiro Shimizu |
890ddd |
ras->fill(TPixel32(127, 0, 127, 127));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return TRasterImageP(ras);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//***************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// ImageFiller implementation
|
|
Toshihiro Shimizu |
890ddd |
//***************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool ImageFiller::getInfo(TImageInfo &info, int imFlags, void *extData)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(false); // None should get these... in case, TODO
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageP ImageFiller::build(int imFlags, void *extData)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(imFlags == ImageManager::none);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Fetch image
|
|
Toshihiro Shimizu |
890ddd |
assert(extData);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ImageLoader::BuildExtData *data = (ImageLoader::BuildExtData *)extData;
|
|
Toshihiro Shimizu |
890ddd |
assert(data->m_subs == 0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const std::string &srcImgId = data->m_sl->getImageId(data->m_fid);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageP img = ImageManager::instance()->getImage(srcImgId, imFlags, extData);
|
|
Toshihiro Shimizu |
890ddd |
if (img) {
|
|
Toshihiro Shimizu |
890ddd |
TRasterImageP ri = img;
|
|
Toshihiro Shimizu |
890ddd |
if (ri) {
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P ras = ri->getRaster();
|
|
Toshihiro Shimizu |
890ddd |
if (ras) {
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P newRas = ras->clone();
|
|
Toshihiro Shimizu |
890ddd |
FullColorAreaFiller filler(newRas);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPaletteP palette = new TPalette();
|
|
Toshihiro Shimizu |
890ddd |
int styleId = palette->getPage(0)->addStyle(TPixel32::White);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
FillParameters params;
|
|
Toshihiro Shimizu |
890ddd |
params.m_palette = palette.getPointer();
|
|
Toshihiro Shimizu |
890ddd |
params.m_styleId = styleId;
|
|
Toshihiro Shimizu |
890ddd |
params.m_minFillDepth = 0;
|
|
Toshihiro Shimizu |
890ddd |
params.m_maxFillDepth = 15;
|
|
Toshihiro Shimizu |
890ddd |
filler.rectFill(newRas->getBounds(), params, false);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRasterImageP ri = TRasterImageP(newRas);
|
|
Toshihiro Shimizu |
890ddd |
return ri;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Error case: return a dummy image (is it really required?)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P ras(10, 10);
|
|
Toshihiro Shimizu |
890ddd |
ras->fill(TPixel32(127, 0, 127, 127));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return TRasterImageP(ras);
|
|
Toshihiro Shimizu |
890ddd |
}
|