本文整理汇总了C++中ImageData类的典型用法代码示例。如果您正苦于以下问题:C++ ImageData类的具体用法?C++ ImageData怎么用?C++ ImageData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ImageData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: w_ImageData_encode
int w_ImageData_encode(lua_State *L)
{
std::string ext;
const char *fmt;
ImageData::Format format = ImageData::FORMAT_MAX_ENUM;
ImageData *t = luax_checkimagedata(L, 1);
if (lua_isstring(L, 2))
luax_convobj(L, 2, "filesystem", "newFile");
love::filesystem::File *file = luax_checktype<love::filesystem::File>(L, 2, "File", FILESYSTEM_FILE_T);
if (lua_isnoneornil(L, 3))
{
ext = file->getExtension();
fmt = ext.c_str();
ImageData::getConstant(fmt, format);
}
else
{
fmt = luaL_checkstring(L, 3);
if (!ImageData::getConstant(fmt, format))
luaL_error(L, "Invalid image format.");
}
try
{
t->encode(file, format);
}
catch(love::Exception &e)
{
return luaL_error(L, e.what());
}
return 0;
}
示例2: ReadLUTFile
ImageData ReadLUTFile(const char *lutfile)
{
PathSeperator sep(lutfile);
if(sep.extension == "jpg") {
return ReadJPEGFile(lutfile);
}
else {
std::string fn = lutfile;
fn = std::string(fn.begin(), fn.begin()+fn.find('#'));
std::string num( ++( sep.extension.begin() + sep.extension.find('#') ), sep.extension.end());
int lutIndex = atoi(num.c_str());
int nbeads, nplanes, nsteps;
FILE *f = fopen(fn.c_str(), "rb");
if (!f)
throw std::runtime_error("Can't open " + fn);
fread(&nbeads, 4, 1, f);
fread(&nplanes, 4, 1, f);
fread(&nsteps, 4, 1, f);
fseek(f, 12 + 4* (nsteps*nplanes * lutIndex), SEEK_SET);
ImageData lut = ImageData::alloc(nsteps,nplanes);
fread(lut.data, 4, nsteps*nplanes,f);
fclose(f);
lut.normalize();
return lut;
}
}
示例3: w_ImageData_setPixel
int w_ImageData_setPixel(lua_State *L)
{
ImageData *t = luax_checkimagedata(L, 1);
int x = luaL_checkint(L, 2);
int y = luaL_checkint(L, 3);
pixel c;
if (lua_istable(L, 4))
{
for (int i = 1; i <= 4; i++)
lua_rawgeti(L, 4, i);
c.r = (unsigned char)luaL_checkinteger(L, -4);
c.g = (unsigned char)luaL_checkinteger(L, -3);
c.b = (unsigned char)luaL_checkinteger(L, -2);
c.a = (unsigned char)luaL_optinteger(L, -1, 255);
lua_pop(L, 4);
}
else
{
c.r = (unsigned char)luaL_checkinteger(L, 4);
c.g = (unsigned char)luaL_checkinteger(L, 5);
c.b = (unsigned char)luaL_checkinteger(L, 6);
c.a = (unsigned char)luaL_optinteger(L, 7, 255);
}
luax_catchexcept(L, [&](){ t->setPixel(x, y, c); });
return 0;
}
示例4: w_ImageData_mapPixel
int w_ImageData_mapPixel(lua_State *L)
{
ImageData *t = luax_checkimagedata(L, 1);
if (!lua_isfunction(L, 2))
return luaL_error(L, "Function expected");
int w = t->getWidth();
int h = t->getHeight();
for (int i = 0; i < w; i++)
{
for (int j = 0; j < h; j++)
{
lua_pushvalue(L, 2);
lua_pushnumber(L, i);
lua_pushnumber(L, j);
pixel c = t->getPixel(i, j);
lua_pushnumber(L, c.r);
lua_pushnumber(L, c.g);
lua_pushnumber(L, c.b);
lua_pushnumber(L, c.a);
lua_call(L, 6, 4);
c.r = luaL_optint(L, -4, 0);
c.g = luaL_optint(L, -3, 0);
c.b = luaL_optint(L, -2, 0);
c.a = luaL_optint(L, -1, 0);
t->setPixel(i, j, c);
lua_pop(L, 4);
}
}
return 0;
}
示例5: AreImagesEqual
bool AreImagesEqual(
const ImageData& image1,
const ImageData& image2,
const double diff_tolerance) {
const int num_channels = image1.GetNumChannels();
if (num_channels != image2.GetNumChannels()) {
std::cout << "Images do not have the same number of channels: "
<< num_channels << " vs. "
<< image2.GetNumChannels() << std::endl;
return false;
}
// If the given diff_tolerance is zero, use "epsilon" to account for possible
// double precision numerical errors.
double applied_diff_tolerance = diff_tolerance;
if (diff_tolerance < std::numeric_limits<double>::epsilon()) {
applied_diff_tolerance = std::numeric_limits<double>::epsilon();
}
for (int channel_index = 0; channel_index < num_channels; ++channel_index) {
if (!AreMatricesEqual(
image1.GetChannelImage(channel_index),
image2.GetChannelImage(channel_index),
applied_diff_tolerance)) {
return false;
}
}
return true;
}
示例6: w_ImageData_mapPixel
// Thread-safe wrapper for the above function.
int w_ImageData_mapPixel(lua_State *L)
{
ImageData *t = luax_checkimagedata(L, 1);
luaL_checktype(L, 2, LUA_TFUNCTION);
int sx = luaL_optint(L, 3, 0);
int sy = luaL_optint(L, 4, 0);
int w = luaL_optint(L, 5, t->getWidth());
int h = luaL_optint(L, 6, t->getHeight());
lua_pushcfunction(L, w_ImageData_mapPixelUnsafe);
lua_pushvalue(L, 1);
lua_pushvalue(L, 2);
lua_pushinteger(L, sx);
lua_pushinteger(L, sy);
lua_pushinteger(L, w);
lua_pushinteger(L, h);
int ret = 0;
// Lock this ImageData's mutex during the entire mapPixel. We pcall instead
// of call because lua_error longjmp's without calling object destructors.
{
love::thread::Lock lock(t->getMutex());
ret = lua_pcall(L, 6, 0, 0);
}
if (ret != 0)
return lua_error(L);
return 0;
}
示例7: assert
ImageData NativeTextureGLES::lock(lock_flags flags, const Rect* src)
{
assert(_lockFlags == 0);
_lockFlags = flags;
Rect r(0, 0, _width, _height);
if (src)
r = *src;
OX_ASSERT(r.getX() + r.getWidth() <= _width);
OX_ASSERT(r.getY() + r.getHeight() <= _height);
_lockRect = r;
assert(_lockFlags != 0);
if (_lockRect.isEmpty())
{
OX_ASSERT(!"_lockRect.IsEmpty()");
return ImageData();
}
if (_data.empty())
{
//_data.resize(_width)
}
ImageData im = ImageData(_width, _height, (int)(_data.size() / _height), _format, &_data.front());
return im.getRect(_lockRect);
}
示例8: w_ImageData_getDimensions
int w_ImageData_getDimensions(lua_State *L)
{
ImageData *t = luax_checkimagedata(L, 1);
lua_pushinteger(L, t->getWidth());
lua_pushinteger(L, t->getHeight());
return 2;
}
示例9: jsImageDataHeight
JSValue jsImageDataHeight(ExecState* exec, JSValue slotBase, const Identifier&)
{
JSImageData* castedThis = static_cast<JSImageData*>(asObject(slotBase));
UNUSED_PARAM(exec);
ImageData* imp = static_cast<ImageData*>(castedThis->impl());
JSValue result = jsNumber(imp->height());
return result;
}
示例10: w_ImageData_getPixel
int w_ImageData_getPixel(lua_State *L)
{
ImageData *t = luax_checkimagedata(L, 1);
int x = luaL_checkint(L, 2);
int y = luaL_checkint(L, 3);
pixel c;
EXCEPT_GUARD(c = t->getPixel(x, y);)
示例11: w_newEncodedImageData
int w_newEncodedImageData(lua_State * L) {
ImageData * t = luax_checkimagedata(L, 1);
const char * fmt = luaL_checkstring(L, 2);
EncodedImageData::Format f;
EncodedImageData::getConstant(fmt, f);
EncodedImageData * eid = t->encode(f);
luax_newtype(L, "EncodedImageData", IMAGE_ENCODED_IMAGE_DATA_T, (void*)eid);
return 1;
}
示例12: QTrkBuildLUTFromFrame
CDLL_EXPORT void DLL_CALLCONV QTrkBuildLUTFromFrame(QueuedTracker* qtrk, ImageData* frame, QTRK_PixelDataType pdt, int plane, ROIPosition* roipos, int numroi)
{
ImageData extracted = ImageData::alloc(qtrk->cfg.width, qtrk->cfg.height*numroi);
for (int i=0;i<numroi;i++){
frame->copyTo(extracted, roipos[i].x, roipos[i].y, 0, i*qtrk->cfg.height, qtrk->cfg.width,qtrk->cfg.height);
}
qtrk->BuildLUT(extracted.data, sizeof(float)*qtrk->cfg.width, QTrkFloat, plane);
extracted.free();
}
示例13: w_ImageData_mapPixelUnsafe
// ImageData:mapPixel. Not thread-safe! See the wrapper function below.
static int w_ImageData_mapPixelUnsafe(lua_State *L)
{
ImageData *t = luax_checkimagedata(L, 1);
luaL_checktype(L, 2, LUA_TFUNCTION);
// No optints because we assume they're done in the wrapper function.
int sx = (int) lua_tonumber(L, 3);
int sy = (int) lua_tonumber(L, 4);
int w = (int) lua_tonumber(L, 5);
int h = (int) lua_tonumber(L, 6);
if (!(t->inside(sx, sy) && t->inside(sx+w-1, sy+h-1)))
return luaL_error(L, "Invalid rectangle dimensions.");
// Cache-friendlier loop. :)
for (int y = sy; y < sy+h; y++)
{
for (int x = sx; x < sx+w; x++)
{
lua_pushvalue(L, 2);
lua_pushnumber(L, x);
lua_pushnumber(L, y);
pixel c = t->getPixel(x, y);
lua_pushnumber(L, c.r);
lua_pushnumber(L, c.g);
lua_pushnumber(L, c.b);
lua_pushnumber(L, c.a);
lua_call(L, 6, 4);
// If we used luaL_checkX / luaL_optX then we would get messy error
// messages (e.g. Error: bad argument #-1 to '?'), so while this is
// messier code, at least the errors are a bit more descriptive.
// Treat the pixel as an array for less code duplication. :(
unsigned char *parray = (unsigned char *) &c;
for (int i = 0; i < 4; i++)
{
int ttype = lua_type(L, -4 + i);
if (ttype == LUA_TNUMBER)
parray[i] = (unsigned char) lua_tonumber(L, -4 + i);
else if (i == 3 && (ttype == LUA_TNONE || ttype == LUA_TNIL))
parray[i] = 255; // Alpha component defaults to 255.
else
// Error (level 2 because this is function will be wrapped.)
return luax_retnumbererror(L, 2, i + 1, ttype);
}
// Pop return values.
lua_pop(L, 4);
// We're locking the entire function, instead of each setPixel call.
t->setPixelUnsafe(x, y, c);
}
}
return 0;
}
示例14: ImageData
void RawImageReader::updateResult(DataContainer& data) {
size_t dimensionality = 3;
if (p_size.getValue().z == 1) {
dimensionality = (p_size.getValue().y == 1) ? 1 : 2;
}
ImageData* image = new ImageData(dimensionality, p_size.getValue(), p_numChannels.getValue());
ImageRepresentationDisk::create(image, p_url.getValue(), p_baseType.getOptionValue(), p_offset.getValue(), p_endianness.getOptionValue());
image->setMappingInformation(ImageMappingInformation(p_size.getValue(), p_imageOffset.getValue(), p_voxelSize.getValue()));
data.addData(p_targetImageID.getValue(), image);
}
示例15: ImageToBuffer
buffer_t ImageToBuffer(const ImageData &im) {
buffer_t buf;
memset(&buf, 0, sizeof(buffer_t));
buf.host = (uint8_t *)im.data();
buf.extent[0] = im.size().width();
buf.stride[0] = 1;
buf.extent[1] = im.size().height();
buf.stride[1] = im.stride()/4;
buf.elem_size = 4;
return buf;
}