当前位置: 首页>>代码示例>>C++>>正文


C++ array_view类代码示例

本文整理汇总了C++中array_view的典型用法代码示例。如果您正苦于以下问题:C++ array_view类的具体用法?C++ array_view怎么用?C++ array_view使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了array_view类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: render_box_

static bool
render_box_ (ImageBuf &dst, array_view<const float> color,
             ROI roi=ROI(), int nthreads=1)
{
    if (nthreads != 1 && roi.npixels() >= 1000) {
        // Lots of pixels and request for multi threads? Parallelize.
        ImageBufAlgo::parallel_image (
            OIIO::bind(render_box_<T>, OIIO::ref(dst), color,
                        _1 /*roi*/, 1 /*nthreads*/),
            roi, nthreads);
        return true;
    }

    // Serial case
    float alpha = 1.0f;
    if (dst.spec().alpha_channel >= 0 && dst.spec().alpha_channel < int(color.size()))
        alpha = color[dst.spec().alpha_channel];
    else if (int(color.size()) == roi.chend+1)
        alpha = color[roi.chend];

    if (alpha == 1.0f) {
        for (ImageBuf::Iterator<T> r (dst, roi);  !r.done();  ++r)
            for (int c = roi.chbegin;  c < roi.chend;  ++c)
                r[c] = color[c];
    } else {
        for (ImageBuf::Iterator<T> r (dst, roi);  !r.done();  ++r)
            for (int c = roi.chbegin;  c < roi.chend;  ++c)
                r[c] = color[c] + r[c] * (1.0f-alpha);  // "over"
    }
    return true;
}
开发者ID:ElaraFX,项目名称:oiio,代码行数:31,代码来源:imagebufalgo_draw.cpp

示例2: if

bool
ImageBufAlgo::render_line (ImageBuf &dst, int x1, int y1, int x2, int y2,
                           array_view<const float> color,
                           bool skip_first_point,
                           ROI roi, int nthreads)
{
    if (! IBAprep (roi, &dst))
        return false;

    if (int(color.size()) < roi.chend) {
        dst.error ("Not enough channels for the color (needed %d)", roi.chend);
        return false;   // Not enough color channels specified
    }
    const ImageSpec &spec (dst.spec());

    // Alpha: if the image's spec designates an alpha channel, use it if
    // it's within the range specified by color. Otherwise, if color
    // includes more values than the highest channel roi says we should
    // modify, assume the first extra value is alpha. If all else fails,
    // make the line opaque (alpha=1.0).
    float alpha = 1.0f;
    if (spec.alpha_channel >= 0 && spec.alpha_channel < int(color.size()))
        alpha = color[spec.alpha_channel];
    else if (int(color.size()) == roi.chend+1)
        alpha = color[roi.chend];

    bool ok;
    OIIO_DISPATCH_TYPES (ok, "render_line", render_line_, dst.spec().format,
                         dst, x1, y1, x2, y2, color, alpha, skip_first_point,
                         roi, nthreads);
    return ok;
}
开发者ID:ElaraFX,项目名称:oiio,代码行数:32,代码来源:imagebufalgo_draw.cpp

示例3: DetectTga

	bool DetectTga(array_view<uint8_t> data, ImageFileInfo& info) {

		if (data.size() < sizeof(TgaHeader)) {
			return false;
		}

		auto header = reinterpret_cast<const TgaHeader*>(data.data());

		if (header->colorMapType != TgaColorMapType::TrueColor) {
			return false; // We don't supported index TGA
		}

		if (header->dataType != TgaDataType::UncompressedRgb) {
			return false; // We only support uncompressed RGB
		}

		if (header->bpp != 24 && header->bpp != 32) {
			return false; // We only support 24 or 32 bit TGAs
		}

		info.width = header->width;
		info.height = header->height;
		info.hasAlpha = (header->bpp == 32);
		info.format = ImageFileFormat::TGA;
		return true;

	}
开发者ID:ema29,项目名称:TemplePlus,代码行数:27,代码来源:images_tga.cpp

示例4: DetectImageFormat

	ImageFileInfo DetectImageFormat(array_view<uint8_t> data) {
		ImageFileInfo info;

		stbi__context ctx;
		stbi__start_mem(&ctx, &data[0], data.bytes());

		int comp;
		if (stbi__bmp_info(&ctx, &info.width, &info.height, &comp)) {
			info.hasAlpha = (comp == 4);
			info.format = ImageFileFormat::BMP;
			return info;
		}

		TjDecompressHandle handle;
		if (tjDecompressHeader(handle, &data[0], data.bytes(), &info.width, &info.height) == 0) {
			info.hasAlpha = false;
			info.format = ImageFileFormat::JPEG;
			return info;
		}

		if (DetectTga(data, info)) {
			return info;
		}

		// Not a very good heuristic
		if (data.size() == 256 * 256) {
			info.width = 256;
			info.height = 256;
			info.hasAlpha = true;
			info.format = ImageFileFormat::FNTART;
			return info;
		}

		return info;
	}
开发者ID:ema29,项目名称:TemplePlus,代码行数:35,代码来源:images.cpp

示例5: SetFeatureMatrix

void ClipFacade::SetFeatureMatrix(array_view<ArmatureFrame> frames, double duration, bool cyclic)
{
	assert(m_pParts != nullptr && m_flag != NotInitialize);

	m_inited = false;

	auto& parts = *m_pParts;
	int fLength = m_partDim.back() + m_partSt.back();

	auto dt = duration / (frames.size() - (size_t)(!cyclic));
	bool useVelocity = dt > 0;

	m_X.resize(frames.size(), fLength);
	for (int f = 0; f < frames.size(); f++)
	{
		auto& lastFrame = frames[f>0?f-1:frames.size()-1];
		auto& frame = frames[f];
		for (int i = 0; i < parts.size(); i++)
		{
			auto part = parts[i];

			auto fv = m_X.block(f, m_partSt[i], 1, m_partDim[i]);

			if (!useVelocity)
				fv = m_pFeature->Get(*part, frame);
			else
				fv = m_pFeature->Get(*part, frame, lastFrame, dt);
		}
	}
}
开发者ID:flair2005,项目名称:OpenAvataring,代码行数:30,代码来源:ClipMetric.cpp

示例6: DecodeTga

	std::unique_ptr<uint8_t[]> DecodeTga(array_view<uint8_t> data) {

		if (data.size() < sizeof(TgaHeader)) {
			throw TempleException("Not enough data for TGA header");
		}

		auto header = reinterpret_cast<const TgaHeader*>(data.data());

		if (header->colorMapType != TgaColorMapType::TrueColor) {
			throw TempleException("Only true color TGA images are supported.");
		}

		if (header->dataType != TgaDataType::UncompressedRgb) {
			throw TempleException("Only uncompressed RGB TGA images are supported.");
		}

		if (header->bpp != 24 && header->bpp != 32) {
			throw TempleException("Only uncompressed RGB 24-bpp or 32-bpp TGA images are supported.");
		}

		auto result(std::make_unique<uint8_t[]>(header->width * header->height * 4));
		auto dest = result.get();

		// Points to the start of the TGA image data
		auto srcStart = data.data() + sizeof(TgaHeader) + header->imageIdLength;
		auto srcSize = data.size() - sizeof(TgaHeader) - header->imageIdLength;		

		if (header->bpp == 24) {
			auto srcPitch = header->width * 3;
			Expects((int) srcSize >= header->height * srcPitch);			
			for (int y = 0; y < header->height; ++y) {
				auto src = srcStart + (header->height - y - 1) * srcPitch;
				for (int x = 0; x < header->width; ++x) {
					*dest++ = *src++;
					*dest++ = *src++;
					*dest++ = *src++;
					*dest++ = 0xFF; // Fixed alpha
				}
			}
		} else {
			auto srcPitch = header->width * 4;
			Expects((int) srcSize >= header->height * srcPitch);
			for (int y = 0; y < header->height; ++y) {
				auto src = srcStart + (header->height - y - 1) * srcPitch;
				for (int x = 0; x < header->width; ++x) {
					*dest++ = *src++;
					*dest++ = *src++;
					*dest++ = *src++;
					*dest++ = *src++;
				}
			}
		}

		return result;
	}
开发者ID:ema29,项目名称:TemplePlus,代码行数:55,代码来源:images_tga.cpp

示例7: key_qvalue_pairs

inline std::string key_qvalue_pairs(array_view<kv_pair> pairs)
{
    std::string buffer;
    // Ensure string is large enough for our use, to avoid useless internal resize
    size_t maj = std::accumulate(pairs.begin(), pairs.end(), size_t{0},
        [](size_t acc, kv_pair p){return acc + p.key.size()+p.value.size()+8;});
    // reserve some space for 8 quoted chars inside value
    // if there is more string is on it's own and will spend slightly more time
    buffer.reserve(maj+8);
    return key_qvalue_pairs(buffer, pairs);
}
开发者ID:pykoder,项目名称:redemption,代码行数:11,代码来源:key_qvalue_pairs.hpp

示例8: DecodeJpeg

	std::unique_ptr<uint8_t[]> DecodeJpeg(const array_view<uint8_t> data) {
		TjDecompressHandle handle;

		int w, h;
		tjDecompressHeader(handle, &data[0], data.bytes(), &w, &h);

		std::unique_ptr<uint8_t[]> result(new uint8_t[w * h * 4]);
		auto status = tjDecompress2(handle, &data[0], data.bytes(), &result[0], w, w * 4, h, TJPF_BGRX, 0);
		if (status != 0) {
			throw TempleException("Unable to decompress jpeg image: {}",
			                      tjGetErrorStr());
		}
		return result;
	}
开发者ID:ema29,项目名称:TemplePlus,代码行数:14,代码来源:images.cpp

示例9: render_line

bool
ImageBufAlgo::render_box (ImageBuf &dst, int x1, int y1, int x2, int y2,
                          array_view<const float> color, bool fill,
                          ROI roi, int nthreads)
{
    if (! IBAprep (roi, &dst))
        return false;
    if (int(color.size()) < roi.chend) {
        dst.error ("Not enough channels for the color (needed %d)", roi.chend);
        return false;   // Not enough color channels specified
    }

    // Filled case
    if (fill) {
        roi = roi_intersection (roi, ROI(x1, x2+1, y1, y2+1, 0, 1, 0, roi.chend));
        bool ok;
        OIIO_DISPATCH_TYPES (ok, "render_box", render_box_, dst.spec().format,
                             dst, color, roi, nthreads);
        return ok;
    }

    // Unfilled case: use IBA::render_line
    return ImageBufAlgo::render_line (dst, x1, y1, x2, y1, color,true, roi, nthreads)
        && ImageBufAlgo::render_line (dst, x2, y1, x2, y2, color,true, roi, nthreads)
        && ImageBufAlgo::render_line (dst, x2, y2, x1, y2, color,true, roi, nthreads)
        && ImageBufAlgo::render_line (dst, x1, y2, x1, y1, color,true, roi, nthreads);
}
开发者ID:ElaraFX,项目名称:oiio,代码行数:27,代码来源:imagebufalgo_draw.cpp

示例10: DecodeImage

	DecodedImage DecodeImage(const array_view<uint8_t> data) {

		DecodedImage result;
		result.info = DetectImageFormat(data);

		stbi__context ctx;
		stbi__start_mem(&ctx, &data[0], data.bytes());
		int w, h, comp;

		switch (result.info.format) {
		case ImageFileFormat::BMP:
			result.data.reset(stbi__bmp_load(&ctx, &w, &h, &comp, 4));
			break;
		case ImageFileFormat::JPEG:
			result.data = DecodeJpeg(data);
			break;
		case ImageFileFormat::TGA:
			result.data = DecodeTga(data);
			break;
		case ImageFileFormat::FNTART:
			return DecodeFontArt(data);
		default:
		case ImageFileFormat::Unknown:
			throw TempleException("Unrecognized image format.");
		}

		return result;
	}
开发者ID:ema29,项目名称:TemplePlus,代码行数:28,代码来源:images.cpp

示例11: equal

    bool operator == (const array_view & other) const noexcept
    {
        // Pointers to same memory (or both null).
        if (data() == other.data())
        {
            return true;
        }

        // Different sizes, whole sequence can't be identical.
        if (size() != other.size())
        {
            return false;
        }

        // Compare each element:
        return std::equal(begin(), end(), other.begin());
    }
开发者ID:glampert,项目名称:array_view,代码行数:17,代码来源:array_view.hpp

示例12: Decode

void AbsoluteLnQuaternionDecoder::Decode(array_view<DirectX::Quaternion> rots, const VectorType & x)
{
	int n = rots.size();

	Eigen::Vector4f qs;
	XMVECTOR q;
	qs.setZero();
	for (int i = 0; i < n; i++)
	{
		qs.segment<3>(0) = x.segment<3>(i * 3).cast<float>();
		q = XMLoadFloat4A(qs.data());
		q = XMQuaternionExp(q); // revert the log map
		XMStoreA(rots[i], q);
	}
}
开发者ID:flair2005,项目名称:OpenAvataring,代码行数:15,代码来源:StylizedIK+-+Copy.cpp

示例13: Encode

void AbsoluteEulerAngleDecoder::Encode(array_view<const DirectX::Quaternion> rots, VectorType & x)
{
	int n = rots.size();

	Eigen::Vector4f qs;
	XMVECTOR q;
	qs.setZero();
	x.resize(n * 3);
	for (int i = 0; i < n; i++)
	{
		q = XMLoad(rots[i]);
		q = XMQuaternionEulerAngleYawPitchRoll(q); // Decompsoe in to euler angle
		XMStoreFloat4(qs.data(), q);
		x.segment<3>(i * 3) = qs.head<3>();
	}
}
开发者ID:flair2005,项目名称:OpenAvataring,代码行数:16,代码来源:StylizedIK+-+Copy.cpp

示例14: ASSERT

void
DeepData::set_all_samples (array_view<const unsigned int> samples)
{
    if (samples.size() != size_t(m_npixels))
        return;
    ASSERT (m_impl);
    if (m_impl->m_allocated) {
        // Data already allocated: set pixels individually
        for (int p = 0; p < m_npixels; ++p)
            set_samples (p, int(samples[p]));
    } else {
        // Data not yet allocated: copy in one shot
        m_impl->m_nsamples.assign (&samples[0], &samples[m_npixels]);
        m_impl->m_capacity.assign (&samples[0], &samples[m_npixels]);
    }
}
开发者ID:KelSolaar,项目名称:oiio,代码行数:16,代码来源:deepdata.cpp

示例15: wal_decode

wal_bitmap xtk::wal_decode (const array_view<std::uint8_t>& data, const array_view<bitmap::value_type>& colormap) {
    const auto& header = *(const wal_header*)data.data ();
    
    auto _bitmap = wal_bitmap {
        make_bitmap_level (data, colormap, 0, header),
        make_bitmap_level (data, colormap, 1, header),
        make_bitmap_level (data, colormap, 2, header),
        make_bitmap_level (data, colormap, 3, header),
        std::string (header.name,
            strnlen (header.name,
                sizeof (header.name))),
        std::string (header.next_name,
            strnlen (header.next_name,
                sizeof (header.next_name)))
    };
    
    return std::move (_bitmap);
}
开发者ID:Coldberg,项目名称:q2bsp_experiment,代码行数:18,代码来源:wal.cpp


注:本文中的array_view类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。