基本信息
源码名称:双线性插值求亚像素
源码大小:0.38M
文件格式:.rar
开发语言:C/C++
更新时间:2019-04-09
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
对像素之间的颜色或灰度进行插值
对像素之间的颜色或灰度进行插值
// SubPDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SubP.h"
#include "SubPDlg.h"
#include "okapi32.h"
#include "math.h"
#include <assert.h>
#include <stdio.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define M_SOI 0xd8
#define M_APP0 0xe0
#define M_APP1 0xe1
#define M_APPF 0xef
#define M_DQT 0xdb
#define M_SOF0 0xc0
#define M_DHT 0xc4
#define M_SOS 0xda
#define M_EOI 0xd9
#define xf 5
struct PNT{BYTE b,g,r;};
union COLOR{COLORREF c;BYTE b[4];PNT p;};
struct DXY{short x,y;};
struct XYPNT{
DXY q;
PNT pnt;};
HANDLE hBrd;LPVOID lpLine;
HWND hWnd;
CWnd *p;
LPVOID lpbuff;
BYTE *b8,*b9;
DWORD *dwd;
unsigned int HEight,WIdth,HEIGHT,WIDTH;
XYPNT qdot(XYPNT d[4],XYPNT a);
int GetJPEGWidthHeight(FILE *pfRead, unsigned int *punWidth, unsigned int *punHeight);
/////////////////////////////////////////////////////////////////////////////
// CSubPDlg dialog
CSubPDlg::CSubPDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSubPDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSubPDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSubPDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSubPDlg)
DDX_Control(pDX, IDC_PICTURE, m_image);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSubPDlg, CDialog)
//{{AFX_MSG_MAP(CSubPDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSubPDlg message handlers
BOOL CSubPDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
long lss;
CString ctr;
char str[20];
//图象采集卡初始化
//#################################数据模型测试使用##########################################
long lIndex=-1212;
hBrd=okOpenBoard(&lIndex);
p=AfxGetMainWnd();
SetWindowPos(NULL,0,0,1024,768,NULL);//窗口最大化
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CSubPDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon 1) / 2;
int y = (rect.Height() - cyIcon 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
long wk;
int i,j;
PNT *pnt,p0;
DWORD k;
COLOR cb;
CWnd* pWnd = GetDlgItem(IDC_PICTURE);
CDC * pDC= pWnd->GetDC(); //得到CStatic的DC
CDC MemDC;
if(!MemDC.CreateCompatibleDC(pDC)){pWnd->ReleaseDC(pDC);return ;}
/* pnt=(PNT *)byt;
for(k=0;k<H2W;k )
{
p0=*(pnt k);
cb.p.b=p0.b;
cb.p.g=p0.g;
cb.p.r=p0.r;
*(dwd k)=cb.c;
}*/
pnt=(PNT *)b8;
for(i=0;i<HEight;i )for(j=0;j<WIdth;j )
{
p0=*(pnt i*WIdth j);
cb.p.b=p0.b;
cb.p.g=p0.g;
cb.p.r=p0.r;
*(dwd i*WIDTH j)=cb.c;
}
pnt=(PNT *)b9;
for(i=0;i<HEIGHT;i )for(j=0;j<WIDTH;j )
{
p0=*(pnt i*WIDTH j);
cb.p.b=p0.b;
cb.p.g=p0.g;
cb.p.r=p0.r;
*(dwd (i HEight)*WIDTH j)=cb.c;
}
CBitmap bmp;
bmp.CreateCompatibleBitmap(pDC, WIDTH, HEIGHT HEight);
bmp.SetBitmapBits(WIDTH*(HEIGHT HEight)*4,dwd);
CBitmap* pOldBmp = MemDC.SelectObject(&bmp);
pDC->BitBlt(1, 1, WIDTH, HEIGHT HEight, &MemDC, 0, 0, SRCCOPY);
MemDC.SelectObject(pOldBmp);
MemDC.DeleteDC();
bmp.DeleteObject();
pWnd->ReleaseDC(pDC);
CDialog::OnPaint();
}
}
HCURSOR CSubPDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSubPDlg::OnButton1()
{
// TODO: Add your control notification handler code here
RECT rect;char st[80];
int i,j,i0,j0;long sr;
XYPNT d[4],aa,rr;
CString DIR;
PNT *buf,*Buf;
BLOCKINFO blk,blj,bli;
/* CFileDialog aDlg(true);
aDlg.DoModal();
DIR=aDlg.GetPathName();
sprintf(st,"%s",DIR);*/
FILE *pfRead;char *strFileName = "test.jpg";
if (NULL == (pfRead = fopen(strFileName, "rb"))){SetWindowText("文件打开失败");return;}
if (1 == GetJPEGWidthHeight(pfRead, &WIdth, &HEight)){printf("文件已损坏!");return;}
sprintf(st,"%d %d",HEight,WIdth);SetWindowText(st);
fclose(pfRead);
if(b8==NULL) b8 = (BYTE *)malloc(HEight*WIdth*3);
blj.iBitCount=24;
blj.iFormType=FORM_RGB888;
blj.iHeight=HEight;
blj.iWidth=WIdth;
blj.lpBits=b8;
okLoadImageFile(hBrd,"test.jpg",0,TARGET(&blj),0,1);
// SetRect(&rect,4,32,WIdth 4,HEight 32);//定义一个rect
// okSetTargetRect(hBrd,SCREEN,&rect); //定义SCREEN的RECT
// okConvertRect(hBrd,SCREEN,0,TARGET(&blj),0,1);
//==============================取得原始图片
HEIGHT=HEight*xf;WIDTH=WIdth*xf;
if(b9==NULL) b9 = (BYTE *)malloc(HEIGHT*WIDTH*3);
buf=(PNT *)b8;
Buf=(PNT *)b9;
blk.iBitCount=24;
blk.iFormType=FORM_RGB888;
blk.iHeight=HEIGHT;
blk.iWidth=WIDTH;
blk.lpBits=b9;
//==============================进行处理
for(i=0;i<HEight-1;i )for(j=0;j<WIdth-1;j ){
d[0].q.x=j*xf ; d[0].q.y=i*xf; d[0].pnt=*(buf i*WIdth j);
d[1].q.x=(j 1)*xf; d[1].q.y=i*xf; d[1].pnt=*(buf i*WIdth j 1);
d[2].q.x=(j 1)*xf; d[2].q.y=(i 1)*xf; d[2].pnt=*(buf (i 1)*WIdth j 1);
d[3].q.x=j*xf ; d[3].q.y=(i 1)*xf; d[3].pnt=*(buf (i 1)*WIdth j);
for(i0=0;i0<xf;i0 )for(j0=0;j0<xf;j0 ){
aa.q.x=j*xf j0;aa.q.y=i*xf i0;
rr=qdot(d,aa);
*(Buf aa.q.y*WIDTH aa.q.x)=rr.pnt;
}
}
// SetRect(&rect,4,HEight 34,WIDTH 4,HEight HEIGHT 34);//定义一个rect
// okSetTargetRect(hBrd,SCREEN,&rect); //定义SCREEN的RECT
// okConvertRect(hBrd,SCREEN,0,TARGET(&blk),0,1);
if(dwd==NULL)dwd=(DWORD *)new DWORD[(HEIGHT HEight)*WIDTH];
okSaveImageFile(hBrd,"z.jpg",0,TARGET(&blk),0,1);
Invalidate(false);
}
XYPNT qdot(XYPNT d[4],XYPNT a){ //d[4] 顺时针排列
XYPNT r;
int i;
float x0,y0,x1,y1;
PNT z[4];
float ap,bt,ax,ay;
x0=d[0].q.x;y0=d[0].q.y;
x1=d[2].q.x;y1=d[2].q.y;
r=a;
ax=a.q.x;ay=a.q.y;
for(i=0;i<4;i )z[i]=d[i].pnt;
ap=(ax-x0)/(x1-x0);bt=(ay-y0)/(y1-y0);
r.pnt.r=(1.-ap)*(1.-bt)*z[0].r bt*(1.-ap)*z[3].r ap*(1.-bt)*z[1].r ap*bt*z[2].r;
r.pnt.g=(1.-ap)*(1.-bt)*z[0].g bt*(1.-ap)*z[3].g ap*(1.-bt)*z[1].g ap*bt*z[2].g;
r.pnt.b=(1.-ap)*(1.-bt)*z[0].b bt*(1.-ap)*z[3].b ap*(1.-bt)*z[1].b ap*bt*z[2].b;
return r;
}
void CSubPDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
free(b8);free(b9);
delete [] dwd;
CDialog::OnClose();
}
int GetJPEGWidthHeight(FILE *pfRead, unsigned int *punWidth, unsigned int *punHeight)
{
int nFinish = 0;
unsigned char id, ucHigh, ucLow;
assert(pfRead != NULL && punWidth != NULL && punHeight != NULL);
fseek(pfRead, 1L, SEEK_SET);
while (!nFinish)
{
fread(&id, sizeof(char), 1, pfRead);
if (id >= M_APP1 && id <= M_APPF)
{
fread(&ucHigh, sizeof(char), 1, pfRead);
fread(&ucLow, sizeof(char), 1, pfRead);
fseek(pfRead, (long)(MAKEWORD(ucLow, ucHigh) - 1), SEEK_CUR);
continue;
}
switch (id)
{
case M_SOI:
fseek(pfRead, 1L, SEEK_CUR);
break;
case M_APP0:
case M_DQT:
fread(&ucHigh, sizeof(char), 1, pfRead);
fread(&ucLow, sizeof(char), 1, pfRead);
fseek(pfRead, (long)(MAKEWORD(ucLow, ucHigh) - 1), SEEK_CUR);
break;
case M_SOF0:
fseek(pfRead, 3L, SEEK_CUR);
fread(&ucHigh, sizeof(char), 1, pfRead);
fread(&ucLow, sizeof(char), 1, pfRead);
*punHeight = (unsigned int)MAKEWORD(ucLow, ucHigh);
fread(&ucHigh, sizeof(char), 1, pfRead);
fread(&ucLow, sizeof(char), 1, pfRead);
*punWidth = (unsigned int)MAKEWORD(ucLow, ucHigh);
nFinish = 1;
return 0;
case M_DHT:
case M_SOS:
case M_EOI:
default:
return 1;//jpg 文件已损坏,文件内容有错误
break;
}
}
return 1;
}