Skip to content

Commit

Permalink
20200423
Browse files Browse the repository at this point in the history
  • Loading branch information
cflw committed Apr 23, 2020
1 parent aef0704 commit 7a1a056
Show file tree
Hide file tree
Showing 24 changed files with 134 additions and 112 deletions.
18 changes: 9 additions & 9 deletions cflw代码库/cflw图形_d2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ ComPtr<ID2D1SolidColorBrush> C二维::fc纯色画笔(const 数学::S颜色 &a颜
return v画笔;
}
ComPtr<ID2D1Bitmap> C二维::fc位图(const dx纹理::I纹理 &a纹理) {
const D2D1_SIZE_U v大小 = {a纹理.fg宽(), a纹理.fg宽()};
const D2D1_SIZE_U v大小 = {(UINT32)a纹理.fg宽(), (UINT32)a纹理.fg宽()};
const D2D1_BITMAP_PROPERTIES v属性 = {{a纹理.fg格式(), D2D1_ALPHA_MODE_STRAIGHT}, 96, 96};
ComPtr<ID2D1Bitmap> v位图;
HRESULT hr = m渲染目标->CreateBitmap(v大小, a纹理.fg数据(), a纹理.fg行距(), v属性, &v位图);
HRESULT hr = m渲染目标->CreateBitmap(v大小, a纹理.fg数据(), (UINT32)a纹理.fg行距(), v属性, &v位图);
return v位图;
}
ComPtr<ID2D1Bitmap> C二维::fc位图(const ComPtr<IWICBitmapSource> &a源) {
Expand All @@ -192,7 +192,7 @@ ComPtr<ID2D1BitmapBrush> C二维::fc位图画笔(const ComPtr<ID2D1Bitmap> &a位
ComPtr<ID2D1GradientStopCollection> C二维::fc渐变点集(const std::vector<S渐变点> &a) const {
std::vector<D2D1_GRADIENT_STOP> va渐变点 = C类型转换::f渐变点(a);
ComPtr<ID2D1GradientStopCollection> v渐变点集;
m渲染目标->CreateGradientStopCollection(va渐变点.data(), va渐变点.size(), &v渐变点集);
m渲染目标->CreateGradientStopCollection(va渐变点.data(), (UINT32)va渐变点.size(), &v渐变点集);
return v渐变点集;
}
ComPtr<ID2D1LinearGradientBrush> C二维::fc线性渐变画笔(const std::vector<S渐变点> &a) const {
Expand Down Expand Up @@ -444,7 +444,7 @@ void C画文本::fs区域(const 数学::S矩形 &a) {
m矩形 = m坐标计算->f矩形_中心半径(a.m坐标, a.m半尺寸);
}
void C画文本::f绘制文本(const std::wstring_view &a文本) const {
m渲染目标->DrawTextW(a文本.data(), a文本.size(), m格式.Get(), m矩形, m画笔.Get());
m渲染目标->DrawTextW(a文本.data(), (UINT32)a文本.size(), m格式.Get(), m矩形, m画笔.Get());
}
void C画文本::f绘制文本布局(IDWriteTextLayout *a布局) const {
m渲染目标->DrawTextLayout({m矩形.left, m矩形.top}, a布局, m画笔.Get());
Expand All @@ -471,9 +471,9 @@ D2D1_COLOR_F C类型转换::f颜色(const 数学::S颜色 &a) {
return {a.r, a.g, a.b, a.a};
}
std::vector<D2D1_GRADIENT_STOP> C类型转换::f渐变点(const std::vector<S渐变点> &a) {
const int n = a.size();
const size_t n = a.size();
std::vector<D2D1_GRADIENT_STOP> v数组(n);
for (int i = 0; i != n; ++i) {
for (size_t i = 0; i != n; ++i) {
const S渐变点 &v0 = a[i];
D2D1_GRADIENT_STOP &v1 = v数组[i];
v1.position = v0.m位置;
Expand Down Expand Up @@ -594,8 +594,8 @@ void C修改路径几何::f连续直线(const std::vector<数学::S向量2> &a)
} else {
m几何槽->AddLine(m坐标计算->f点(a[0]));
}
const int n = a.size();
for (int i = 1; i != n; ++i) {
const size_t n = a.size();
for (size_t i = 1; i != n; ++i) {
m几何槽->AddLine(m坐标计算->f点(a[i]));
}
}
Expand Down Expand Up @@ -667,7 +667,7 @@ tp文本布局 C文本工厂::fc文本布局(const std::wstring_view &a文本, I
a格式 = C二维::g这->fg默认文本格式().Get();
}
ComPtr<IDWriteTextLayout> v布局;
HRESULT hr = m写字工厂->CreateTextLayout(a文本.data(), a文本.size(), a格式, 0, 0, &v布局);
HRESULT hr = m写字工厂->CreateTextLayout(a文本.data(), (UINT32)a文本.size(), a格式, 0, 0, &v布局);
return v布局;
}
tp文本布局 C文本工厂::fc文本布局(const std::wstring_view &a文本, const S文本格式参数 &a格式) const {
Expand Down
22 changes: 11 additions & 11 deletions cflw代码库/cflw图形_d2d助手.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <assert.h>
#include <assert.h>
#include <vector>
#include <d2d1.h>
#include <wrl.h>
Expand All @@ -13,18 +13,18 @@ void GetFirstControlPoints(
__in const std::vector<FLOAT>& rhs,
__out std::vector<FLOAT>& x) {
assert(rhs.size() == x.size());
int n = rhs.size();
size_t n = rhs.size();
std::vector<FLOAT> tmp(n); // Temp workspace.

FLOAT b = 2.0f;
x[0] = rhs[0] / b;
for (int i = 1; i < n; i++) // Decomposition and forward substitution.
for (size_t i = 1; i < n; i++) // Decomposition and forward substitution.
{
tmp[i] = 1 / b;
b = (i < n - 1 ? 4.0f : 3.5f) - tmp[i];
x[i] = (rhs[i] - x[i - 1]) / b;
}
for (int i = 1; i < n; i++) {
for (size_t i = 1; i < n; i++) {
x[n - i - 1] -= tmp[n - i] * x[n - i]; // Back substitution.
}
}
Expand All @@ -43,7 +43,7 @@ void GetCurveControlPoints(
assert((firstCtrlPt.size() == secondCtrlPt.size())
&& (knots.size() == firstCtrlPt.size() + 1));

int n = knots.size() - 1;
size_t n = knots.size() - 1;
assert(n >= 1);

if (n == 1) {
Expand All @@ -52,7 +52,7 @@ void GetCurveControlPoints(
firstCtrlPt[0].x = (2 * knots[0].x + knots[1].x) / 3.0f;
firstCtrlPt[0].y = (2 * knots[0].y + knots[1].y) / 3.0f;

// P2 = 2P1 ¨C P0
// P2 = 2P1 C P0
secondCtrlPt[0].x = 2 * firstCtrlPt[0].x - knots[0].x;
secondCtrlPt[0].y = 2 * firstCtrlPt[0].y - knots[0].y;
return;
Expand All @@ -63,7 +63,7 @@ void GetCurveControlPoints(
std::vector<FLOAT> rhs(n);

// Set right hand side X values
for (int i = 1; i < (n - 1); ++i) {
for (size_t i = 1; i < (n - 1); ++i) {
rhs[i] = 4 * knots[i].x + 2 * knots[i + 1].x;
}
rhs[0] = knots[0].x + 2 * knots[1].x;
Expand All @@ -73,7 +73,7 @@ void GetCurveControlPoints(
GetFirstControlPoints(rhs, x);

// Set right hand side Y values
for (int i = 1; i < (n - 1); ++i) {
for (size_t i = 1; i < (n - 1); ++i) {
rhs[i] = 4 * knots[i].y + 2 * knots[i + 1].y;
}
rhs[0] = knots[0].y + 2 * knots[1].y;
Expand All @@ -83,7 +83,7 @@ void GetCurveControlPoints(
GetFirstControlPoints(rhs, y);

// Fill output arrays.
for (int i = 0; i < n; ++i) {
for (size_t i = 0; i < n; ++i) {
// First control point
firstCtrlPt[i] = D2D1::Point2F(x[i], y[i]);
// Second control point
Expand All @@ -103,7 +103,7 @@ HRESULT CreateBezierSpline(
assert(ppPathGeometry != nullptr);
assert(points.size()>1);

int n = points.size();
size_t n = points.size();
std::vector<D2D1_POINT_2F> firstCtrlPt(n - 1);
std::vector<D2D1_POINT_2F> secondCtrlPt(n - 1);
GetCurveControlPoints(points, firstCtrlPt, secondCtrlPt);
Expand All @@ -119,7 +119,7 @@ HRESULT CreateBezierSpline(
if (SUCCEEDED(hr)) {
spSink->SetFillMode(D2D1_FILL_MODE_WINDING);
spSink->BeginFigure(points[0], D2D1_FIGURE_BEGIN_FILLED);
for (int i = 1; i<n; i++)
for (size_t i = 1; i<n; i++)
spSink->AddBezier(D2D1::BezierSegment(firstCtrlPt[i - 1], secondCtrlPt[i - 1], points[i]));
spSink->EndFigure(D2D1_FIGURE_END_OPEN);
spSink->Close();
Expand Down
2 changes: 1 addition & 1 deletion cflw代码库/cflw图形_d3d11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ HRESULT C三维::f创建域着色器(tp域着色器 &a, const std::span<const st
return m设备->CreateDomainShader(a代码.data(), a代码.size(), nullptr, &a);
}
HRESULT C三维::f创建输入布局(tp输入布局 &a, const std::span<const std::byte> &a代码, const C顶点格式 &a顶点格式) {
return m设备->CreateInputLayout(a顶点格式.m数组.data(), a顶点格式.m数组.size(), a代码.data(), a代码.size(), &a);
return m设备->CreateInputLayout(a顶点格式.m数组.data(), (UINT)a顶点格式.m数组.size(), a代码.data(), a代码.size(), &a);
}
HRESULT C三维::f创建图形管线(tp图形管线 &a, const S图形管线参数 &a参数) {
HRESULT hr;
Expand Down
2 changes: 1 addition & 1 deletion cflw代码库/cflw图形_d3d着色器.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ class C着色器工厂 {
std::string m顶点着色模型, m像素着色模型, m几何着色模型, m外壳着色模型, m域着色模型, m计算着色模型;
};
inline std::span<std::byte> fc跨度(const ComPtr<ID3DBlob> &a) {
return {(std::byte*)a->GetBufferPointer(), (std::span<std::byte>::index_type)a->GetBufferSize()};
return {(std::byte*)a->GetBufferPointer(), (std::span<std::byte>::size_type)a->GetBufferSize()};
}
} //namespace cflw::图形::d3d着色器
2 changes: 1 addition & 1 deletion cflw代码库/cflw图形_dx着色器.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ class C着色器工厂 {
ComPtr<IDxcLibrary> m库;
};
inline std::span<std::byte> fc跨度(const ComPtr<IDxcBlob> &a) {
return {(std::byte*)a->GetBufferPointer(), (std::span<std::byte>::index_type)a->GetBufferSize()};
return {(std::byte*)a->GetBufferPointer(), (std::span<std::byte>::size_type)a->GetBufferSize()};
}
} //namespace cflw::图形::dx着色器
26 changes: 13 additions & 13 deletions cflw代码库/cflw图形_dx纹理.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ HRESULT C图像工厂::f初始化() {
}
return S_OK;
}
HRESULT C图像工厂::f读取图像(const wchar_t *a文件, IWICBitmapFrameDecode **a帧) {
HRESULT C图像工厂::f读取图像(const std::wstring_view &a文件, IWICBitmapFrameDecode **a帧) const {
HRESULT hr;
ComPtr<IWICBitmapDecoder> v解码器;
hr = m工厂->CreateDecoderFromFilename(a文件, 0, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &v解码器);
hr = m工厂->CreateDecoderFromFilename(a文件.data(), 0, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &v解码器);
if (FAILED(hr)) {
return hr;
}
Expand All @@ -38,13 +38,13 @@ HRESULT C图像工厂::f读取图像(const wchar_t *a文件, IWICBitmapFrameDeco
}
return S_OK;
}
std::unique_ptr<std::byte[]> C图像工厂::f复制像素数据(IWICBitmapSource *a帧, size_t *ap像素大小, size_t *ap行距, size_t *ap图像大小) {
std::unique_ptr<std::byte[]> C图像工厂::f复制像素数据(IWICBitmapSource *a帧, size_t *ap像素大小, size_t *ap行距, size_t *ap图像大小) const {
const WICBitmapPlaneDescription v描述 = f取图像描述(a帧);
const size_t v像素大小 = f像素大小(v描述.Format);
const size_t v一排大小 = v描述.Width * v像素大小;
const size_t v数据大小 = v一排大小 * v描述.Height;
std::unique_ptr<std::byte[]> v数据 = std::make_unique<std::byte[]>(v数据大小);
a帧->CopyPixels(0, v一排大小, v数据大小, (BYTE*)v数据.get());
a帧->CopyPixels(0, (UINT)v一排大小, (UINT)v数据大小, (BYTE*)v数据.get());
if (ap像素大小) {
*ap像素大小 = v像素大小;
}
Expand All @@ -56,13 +56,13 @@ std::unique_ptr<std::byte[]> C图像工厂::f复制像素数据(IWICBitmapSource
}
return v数据;
}
WICBitmapPlaneDescription C图像工厂::f取图像描述(IWICBitmapSource *a帧) {
WICBitmapPlaneDescription C图像工厂::f取图像描述(IWICBitmapSource *a帧) const {
WICBitmapPlaneDescription v;
a帧->GetPixelFormat(&v.Format);
a帧->GetSize(&v.Width, &v.Height);
return v;
}
size_t C图像工厂::f像素大小(const GUID &guid) {
size_t C图像工厂::f像素大小(const GUID &guid) const {
HRESULT hr;
ComPtr<IWICComponentInfo> v组件信息;
hr = m工厂->CreateComponentInfo(guid, &v组件信息);
Expand All @@ -83,7 +83,7 @@ size_t C图像工厂::f像素大小(const GUID &guid) {
v格式信息->GetBitsPerPixel(&bpp);
return bpp;
}
HRESULT C图像工厂::f图像尺寸变换(IWICBitmapSource *a帧, size_t a宽, size_t a高, IWICBitmapScaler **a输出) {
HRESULT C图像工厂::f图像尺寸变换(IWICBitmapSource *a帧, size_t a宽, size_t a高, IWICBitmapScaler **a输出) const {
HRESULT hr;
ComPtr<IWICBitmapScaler> v缩放;
hr = m工厂->CreateBitmapScaler(&v缩放);
Expand All @@ -97,7 +97,7 @@ HRESULT C图像工厂::f图像尺寸变换(IWICBitmapSource *a帧, size_t a宽,
*a输出 = v缩放.Detach();
return S_OK;
}
HRESULT C图像工厂::f图像格式变换(IWICBitmapSource *a图像, const GUID &a格式, IWICFormatConverter **a输出) {
HRESULT C图像工厂::f图像格式变换(IWICBitmapSource *a图像, const GUID &a格式, IWICFormatConverter **a输出) const {
HRESULT hr;
ComPtr<IWICFormatConverter> v转换;
hr = m工厂->CreateFormatConverter(&v转换);
Expand All @@ -111,7 +111,7 @@ HRESULT C图像工厂::f图像格式变换(IWICBitmapSource *a图像, const GUID
*a输出 = v转换.Detach();
return S_OK;
}
ComPtr<IWICBitmapSource> C图像工厂::f高级读取(const wchar_t *a文件名, const std::function<GUID(const GUID &)> &af格式) {
ComPtr<IWICBitmapSource> C图像工厂::f高级读取(const std::wstring_view &a文件名, const std::function<GUID(const GUID &)> &af格式) const {
ComPtr<IWICBitmapFrameDecode> v图像;
HRESULT hr = f读取图像(a文件名, &v图像);
if (FAILED(hr)) {
Expand All @@ -130,7 +130,7 @@ ComPtr<IWICBitmapSource> C图像工厂::f高级读取(const wchar_t *a文件名,
}
return v格式转换;
}
std::unique_ptr<C只读纹理> C图像工厂::fc纹理(IWICBitmapSource *a源) {
std::unique_ptr<C只读纹理> C图像工厂::fc纹理(IWICBitmapSource *a源) const {
std::unique_ptr<C只读纹理> v纹理 = std::make_unique<C只读纹理>();
v纹理->mp数据 = f复制像素数据(a源, &v纹理->m像素大小, &v纹理->m行距, nullptr);
if (!v纹理->mp数据) {
Expand All @@ -142,7 +142,7 @@ std::unique_ptr<C只读纹理> C图像工厂::fc纹理(IWICBitmapSource *a源) {
v纹理->m格式 = 格式::f到dxgi(v描述.Format);
return v纹理;
}
std::unique_ptr<C只读纹理> C图像工厂::f一键读取(const wchar_t *a文件名) {
std::unique_ptr<C只读纹理> C图像工厂::f一键读取(const std::wstring_view &a文件名) const {
auto v源 = f高级读取(a文件名, 格式::f到通用格式);
return fc纹理(v源.Get());
}
Expand Down Expand Up @@ -413,8 +413,8 @@ const 数学::S颜色 &C自定义纹理::fg像素(size_t u, size_t v) const {
return mp像素[v * m宽 + u];
}
数学::S颜色 C自定义纹理::f线性采样(float u, float v) const {
const float v限制u = 数学::f求余(u, m宽);
const float v限制v = 数学::f求余(v, m高);
const float v限制u = 数学::f求余(u, (float)m宽);
const float v限制v = 数学::f求余(v, (float)m高);
const float v地板u = floor(u);
const float v地板v = floor(v);
const size_t u0 = (size_t)v地板u;
Expand Down
20 changes: 11 additions & 9 deletions cflw代码库/cflw图形_dx纹理.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <memory>
#include <functional>
#include <string_view>
#include <wincodec.h>
#include <wrl.h>
#include <dxgi.h>
Expand Down Expand Up @@ -35,20 +36,21 @@ using Microsoft::WRL::ComPtr;
class C只读纹理;
//==============================================================================
// 工厂
// 注意:图像工厂尽量不要作为局部变量存在。一旦最后一个CoUninitialize被调用,所有创建的对象将被释放
//==============================================================================
class C图像工厂 {
public:
~C图像工厂();
HRESULT f初始化();
HRESULT f读取图像(const wchar_t *, IWICBitmapFrameDecode **);
std::unique_ptr<std::byte[]> f复制像素数据(IWICBitmapSource *, size_t *像素大小 = nullptr, size_t *行距 = nullptr, size_t *图像大小 = nullptr);
size_t f像素大小(const GUID &);
WICBitmapPlaneDescription f取图像描述(IWICBitmapSource *);
HRESULT f图像尺寸变换(IWICBitmapSource *, size_t, size_t, IWICBitmapScaler **);
HRESULT f图像格式变换(IWICBitmapSource *, const GUID &, IWICFormatConverter **);
ComPtr<IWICBitmapSource> f高级读取(const wchar_t *, const std::function<GUID(const GUID &)> &格式转换 = 格式::f不转换);
std::unique_ptr<C只读纹理> fc纹理(IWICBitmapSource *);
std::unique_ptr<C只读纹理> f一键读取(const wchar_t *);
HRESULT f读取图像(const std::wstring_view &, IWICBitmapFrameDecode **) const;
std::unique_ptr<std::byte[]> f复制像素数据(IWICBitmapSource *, size_t *像素大小 = nullptr, size_t *行距 = nullptr, size_t *图像大小 = nullptr) const;
size_t f像素大小(const GUID &) const;
WICBitmapPlaneDescription f取图像描述(IWICBitmapSource *) const;
HRESULT f图像尺寸变换(IWICBitmapSource *, size_t, size_t, IWICBitmapScaler **) const;
HRESULT f图像格式变换(IWICBitmapSource *, const GUID &, IWICFormatConverter **) const;
ComPtr<IWICBitmapSource> f高级读取(const std::wstring_view &, const std::function<GUID(const GUID &)> &格式转换 = 格式::f不转换) const;
std::unique_ptr<C只读纹理> fc纹理(IWICBitmapSource *) const;
std::unique_ptr<C只读纹理> f一键读取(const std::wstring_view &) const;
public:
ComPtr<IWICImagingFactory> m工厂;
};
Expand Down
6 changes: 3 additions & 3 deletions cflw代码库/cflw工具.inl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ template<typename t> t C文本::f文本_整数(const t字符串 &s) {
//取负号
if (!辅助::fi无符号(v)) {
if (s[v读取位] == L'-') {
v符号 = -1;
v符号 = (t)(-1);
++v读取位;
}
}
Expand Down Expand Up @@ -157,10 +157,10 @@ template<typename t> t C文本::f文本_浮点数(const t字符串 &s) {
if (v读取字符 == L'.') {
continue;
}
v += (v读取字符 - L'0') * pow((t)10, v当前位);
v += (v读取字符 - L'0') * (t)pow((t)10, v当前位);
++v当前位;
}
v *= pow((t)10, v小数位置 - v位数);
v *= (t)pow((t)10, v小数位置 - v位数);
return v * v符号;
}
//==============================================================================
Expand Down
4 changes: 2 additions & 2 deletions cflw代码库/cflw异常.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include "cflw异常.h"
#include "cflw工具.h"
namespace cflw::异常 {
X未实现::X未实现():
std::runtime_error("该函数未实现") {
X未实现::X未实现(const std::string &a文本):
std::runtime_error(a文本) {
}
X视窗::X视窗(long a):
std::runtime_error(std::string("HRESULT:") + std::to_string(a)) {
Expand Down
3 changes: 2 additions & 1 deletion cflw代码库/cflw异常.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#pragma once
#include <exception>
#include <stdexcept>
#include <string>
namespace cflw::异常 {
//标准库异常别名
using X参数 = std::invalid_argument;
//未实现
class X未实现 : public std::runtime_error {
public:
X未实现();
X未实现(const std::string & = "未实现");
};
//HRESULT
class X视窗 : public std::runtime_error {
Expand Down
Loading

0 comments on commit 7a1a056

Please sign in to comment.