MFC CScrollBar拖动完后总跑到零位置

原因是

  1. 要处理SB_ENDSCROLL事件。
  2. 一定要在适当的地方GetScrollPos或SetScrollPos。

正确示例如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
void SampleDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
	int iMin = 0, iMax = 0;
	pScrollBar->GetScrollRange(&iMin, &iMax);
 
	// nPos = pScrollBar->GetScrollPos(); // 此处这句话一定不能有
 
	switch (nSBCode)
	{
	case SB_THUMBTRACK:
		break;
	case SB_LINELEFT:
		nPos = pScrollBar->GetScrollPos(); // 此处这句话一定要有
		nPos--;
		if (nPos < (UINT)iMin)
			nPos = 0;
		break;
	case SB_LINERIGHT:
		nPos = pScrollBar->GetScrollPos(); // 此处这句话一定要有
		nPos++;
		if (nPos >= (UINT)iMax)
			nPos = iMax - 1;
		break;
	case SB_ENDSCROLL:
		nPos = pScrollBar->GetScrollPos(); // 此处这句话一定要有
		break;
	default:
		break;
	}
 
	pScrollBar->SetScrollPos(nPos, 1); // 此处这句话也一定要有
 
	// Todo real work with nPos.
 
	CDialogEx::OnHScroll(nSBCode, nPos, pScrollBar);
}

error C4839: 作为可变参数函数的参数的非标准用法

报错语句为:

1
	_stprintf_s(filepath, _T("%s\\%s"), curpath, CA2T(iniFilePath));

改为如下就不报错了:

1
2
	CString iniFilePathT = CA2T(iniFilePath);
	_stprintf_s(filepath, _T("%s\\%s"), curpath, (LPCTSTR)iniFilePathT);

targetSdkVersion未安装应用程式

发布后在Android 6.1的手机上安装不了,显示“未安装应用程序”,检查源码发现build.gradle文件中

1
2
3
4
    defaultConfig {
        minSdkVersion 14
	targetSdkVersion 27
    }

于是,把targetSdkVersion改为23,而发布release版时,Signature Versions只选V1(Jar Signature)。
再将生成的apk包在安卓6.1手机上装,顺利安装成功。

HLSL显示贴图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
float4x4 worldViewProj : WorldViewProjection;
 
struct VS_INPUT
{
	float3 pos : POSITION;
	float2 tex : TEXCOORD0;
};
 
struct VS_OUTPUT
{
	float4 pos : POSITION;
	float2 tex : TEXCOORD0;  
};
 
VS_OUTPUT mainVS(VS_INPUT input)
{
	VS_OUTPUT vsOut;	
	vsOut.pos = mul(float4(input.pos, 1), worldViewProj);
	vsOut.tex = input.tex;
//	vsOut.tex.xy = vsOut.pos.zw;
	return vsOut;
}
 
texture tex0;
 
sampler2D sample0 = 
sampler_state
{
	Texture = <tex0>;
/*	MipFilter = LINEAR;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
 
	AddressU = CLAMP;
	AddressV = CLAMP;
*/
};
 
float4 mainPS(float2 tex : TEXCOORD0) : COLOR
{
	return tex2D(sample0, tex);
//	return tex.x / tex.y;
}
 
technique technique0 {
	pass p0 {
		VertexShader = compile vs_3_0 mainVS();
		PixelShader = compile ps_3_0 mainPS();
	}
}

yv12 to nv21

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
void nv212Yv12(char *nv21, char *yv12, int width, int height)
{
    int frameSize = width * height;
    memcpy(yv12, nv21, frameSize);
    nv21 += frameSize;
    yv12 += frameSize;
    int halfWidth = width / 2;
    int halfHeight = height / 2;
    int quadFrame = halfWidth * halfHeight;
    for (int i = 0; i < halfHeight; i++) {
        for (int j = 0; j < halfWidth; j++) {
            *(yv12 + i * halfWidth + j) = *nv21++;
            *(yv12 + quadFrame + i * halfWidth + j) = *nv21++;
        }
    }
}
 
void yv122Nv21(char *yv12, char *nv21, int width, int height)
{
    int frameSize = width * height;
    memcpy(nv21, yv12, frameSize);
    nv21 += frameSize;
    yv12 += frameSize;
    int halfWidth = width / 2;
    int halfHeight = height / 2;
    int quadFrame = halfWidth * halfHeight;
    for (int i = 0; i < halfHeight; i++) {
        for (int j = 0; j < halfWidth; j++) {
            *nv21++ = *(yv12 + i * halfWidth + j);
            *nv21++ = *(yv12 + quadFrame + i * halfWidth + j);
        }
    }
}

NDK硬解h264

有几点须注意,

  1. 不要让硬解码器自已绘制表面,也就是AMediaCodec_configure传入的surface应设为空。否则运行时间长了,会出现“weak global reference table overflow”的崩机错误。
  2. 我之前文章里也说过了,不要静态链编libmediandk.so,老的安卓机上没有这个库,要动态检测加载,详细过程见之后代码。
  3. AMediaCodec_dequeueInputBuffer不是每一次都返回成功,如果失败了而丢弃h264数据帧,则最终的播放效果就时不时出现花屏,正确处理见之后代码。
  4. 硬解码器解出的数据默认可能是NV12格式也可能是YV12格式,不同的手机不一样,预先配置解码器的"color-format"为19,也没用。为了与ffmpeg解出的数据一致为YU12格式,统一地我们自已转。

以下是源码,摘选自EuhatRtsp开源软件,经历过长时间拷机运行没问题。其网址是:http://euhat.com/rtsp.html


DecoderHard.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once
 
#include "DecodeOp.h"
 
class AMediaCodec;
 
class EuhatDecoderHard : public EuhatDecoderBase
{
    int updateSpsAndPps();
 
    int spsChanged_;
    int ppsChanged_;
    char *sps_;
    char *pps_;
    int width_;
    int height_;
    int oriHeight_;
    int colorFormat_;
    int stride_;
    int sliceHeight_;
    int cropTop_;
    int cropBottom_;
    int cropLeft_;
    int cropRight_;
    int isCodecInited_;
    void *surface_;
    int surfaceChanged_;
 
public:
    EuhatDecoderHard();
    virtual ~EuhatDecoderHard();
 
    virtual int init(EuhatDecoderCallback callback, void *context);
    virtual int fini();
    virtual int updateSps(const char *sps);
    virtual int updatePps(const char *pps);
    virtual int updateWH(int width, int height);
    virtual int updateSurface(void *surface);
    virtual int decode(char *frame, int frameLen);
 
    static int canWork();
 
    AMediaCodec *mediaCodec_;
};

Read more

数据结构好文推荐

红黑树演示
https://sandbox.runjs.cn/show/2nngvn8w
 
有哪些最新的机器学习可视化工具?
https://www.toutiao.com/a6567983574299967757/
 
NDK-FFmpeg视频解码
http://www.imooc.com/article/80058
 
RSA加密原理
http://blog.jobbole.com/42699/

https://github.com/fredericgermain/LeakTracer

学英语之来自巴菲特

A simple rule dictates my buying: Be fearful when others are greedy, and be greedy when others are fearful. And most certainly, fear is now widespread, gripping even seasoned investors. To be sure, investors are right to be wary of highly leveraged entities or businesses in weak competitive positions. But fears regarding the long-term prosperity of the nation's many sound companies make no sense. These businesses will indeed suffer earnings hiccups, as they always have. But most major companies will be setting new profit records 5, 10 and 20 years from now.

U.S. Corporate Debt Outstanding as a % of GDP

for a spin

IBM’s acquisition of Red Hat is huge news for the Linux world

We are devastated to learn of the tragic passing of a member of our Googler family. On Monday night, our colleague Emily Hong passed away after being struck by a shuttle bus on our Mountain View campus. Emily worked in the finance organization and was beloved by her colleagues -- she brought an incredible spark to Google. She was inquisitive, creative, analytical, positive, generous and kind -- our deepest condolences are with

why ea is committed to the amiga.

As illustrated in below, draw rays from 0 through Z(t) and Z(t+1), together with circular arcs (centred at 0) through those points.

Recovering from our feigned bout of amnesia concerning complex numbers and their geometric interpretation, Cotes' result becomes simple to understand and to prove.

striped triangle

However, not any old mapping qualifies as motion, for we must also capture the idea of the sheet remaining rigid while it moves.
Armed with this precise concept of motion, our final definition of geometric equality becomes...
buf for the moment we wish only to explain how Klein was able to generalize the above ideas so as to embrace such new geometries.
But will this type of equality behave in the way we would like and expect?
If M and N are members of G then so is the composite transformation.
If two transformations do not alter distances, then applying them in succession will not alter distances either.

Pythons kill by tightening their coils so that their victim cannot breathe.
Many private colleges are coining it.
Jaron Lanier coined the term 'virtual reality' and pioneered its early development.
These findings are a reminder that low pay is the other side of the coin of falling unemployment.
Plant them in a coarse, well-draining soil mix with lots of coir and sphagnum moss.

In a full-throated defence of America’s forward-leaning stance abroad, John F. Kerry, US Secretary of State, hit back at critics who have claimed that the United States is disengaging from world affairs. “I want to make it clear that nothing could be further from the truth,” said Kerry.

produce the two segments till they meet at M.
the chord AA' subtends the same angle at every point of the circular arc.

They are just two examples of hapless mathematicians who would have been dismayed to examine the notebooks.
The image f(z) of a point z may be described by its distance |f(z)| from the origin, and the angle arg[f(z)] it makes with the real axis.
This readily comprehensible result is illustrated in below, ignore the shaded disc for the time being.

it would smack of circular reasoning if we were to assume it while following our new approach.

empirically, appeal to the familiar reflection property of the conic sections.

if n is an integer then the branch point is (n - 1), More generally, the same is true for any fraction.
Notice, incidentally, that all three branches display the by now ubiquitous (yet mysterious) preservation of small squares.
Provisionally, we now take S to be the plane with the points of C removed.
the branch cut C is the work of man - the multifunction is oblivious to our desire to dissect it into three functions.
rays go due west.

intimadate
intimate

he first studied the transformations that now bear his name, it is fair to say that the rich vein of knowledge which he thereby exposed is still far from being exhausted. For this reason, we shall investigate the transformations in considerably greater depth than is customary.

Check for yourself that the order in which we apply these mappings is immaterial.
the result is true without qualification.
We should explain that this is not generalization for its own sake; soon we will see how this three-dimensional inversion sheds new light on two-dimensional inversion.

If the conformality of an otherwise conformal mapping breaks down at a particular point p, then p is called a critical point of the mapping.

Thus instead of merely saying that f(z) "dies away to zero like (1/(z^2)) as z tends to infinity", we can now say (more precisely) that f(z) has a double root at z = infinity.

From the similarity of the illustrated right triangles with hypotenuses Nz1 and Nz, we immediately deduce that.

beside oneself

how is it that you can't count?

Android Handler and Runnable

Runnable并不是一个线程,它是Thread运行过程中的一个片断。

以下例子是创建子线程获取图片后发送给UI线程显示,第一个Runnable运行在子线程中,第二个Runnable运行在UI线程中:

1
2
3
4
5
6
7
8
9
10
11
12
public void onClick(View v) {
    new Thread(new Runnable() { // 第一个Runnable
        public void run() {
            final Bitmap bitmap = loadImageFromNetwork("http://example.com/image.png");
            mImageView.post(new Runnable() { // 第二个Runnable
                public void run() {
                    mImageView.setImageBitmap(bitmap);
                }
            });
        }
    }).start();
}

而Handler与线程的绑定有两种方式。
第一种是与当前线程绑定:

1
public Handler handler = new Handler();

第二种是指定线程绑定:

1
handler = new Handler(thread.getLooper());