📄 reg20.c
字号:
/*************************************************************************/
/* */
/* Copyright (c) 1997 - 1999 Accelerated Technology, Inc. */
/* */
/* PROPRIETARY RIGHTS of Accelerated Technology are involved in the */
/* subject matter of this material. All manufacturing, reproduction, */
/* use, and sales rights pertaining to this subject matter are governed */
/* by the license agreement. The recipient of this software implicitly */
/* accepts the terms of the license. */
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* FILE NAME VERSION */
/* */
/* REG20.c 1.9 */
/* */
/* COMPONENT */
/* */
/* All */
/* */
/* DESCRIPTION */
/* */
/* This file contains the BitmapToRegion function. */
/* */
/* AUTHOR */
/* */
/* Giac Dinh, Accelerated Technology, Inc. */
/* */
/* DATA STRUCTURES */
/* */
/* None */
/* */
/* FUNCTIONS */
/* */
/* None */
/* */
/* DEPENDENCIES */
/* */
/* None */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* */
/*************************************************************************/
#include "meta_wnd.h"
#include "metconst.h" /* MetaWINDOW Constant & Stucture Definitions */
#include "metports.h" /* MetaWINDOW Port & Bitmap Definitions */
#include "grafdata.h"
#include "metmacs3.h"
/* Function BitmapToRegion() creates a region from the non-transparent data contained
within an area of the current bitmap. SRCRECT specifies the rectangular
area to create the region from. If SRCRECT is NULL, the entire bitmap is
processed. XPARCOLOR specifies the background transparent color that
identifies the areas *not* to be included in the region.
BitmapToRegion() returns with a pointer to the new region, or a NULL
pointer if the region creation fails (eg. insufficient memory). */
region *BitmapToRegion( rect *srcRect, int xPARCOLOR )
{
void OpenRegion(void);
region *CloseRegion(void);
void GrafFree(void *freePtr);
int GetPixel(int argX, int argY);
region *UnionRegion(region *rgn1, region *rgn2);
void PaintRect(rect *argR);
region *tempRegion;
region *totalRegion;
region *rasterRegion;
int x, y , i , inrun;
rect sRect, tRect;
if(srcRect == 0)
sRect = grafPort.portRect;
else
sRect = *srcRect;
/* Start of with empty region */
OpenRegion();
totalRegion =(region *) CloseRegion();
for(y = sRect.Ymin; y < sRect.Ymax; y++)
{
tRect.Ymin = y;
tRect.Ymax = y + 1;
OpenRegion();
inrun = 0;
/* For each x in question */
for(x = sRect.Xmin; x < sRect.Xmax ; x++)
{
i = GetPixel( x, y);
if( i != xPARCOLOR)
{
if(inrun != 0)
tRect.Xmax++;
else
{
tRect.Xmin = x;
tRect.Xmax = x + 1;
inrun = 1;
}
}
else
{
if(inrun != 0)
{
PaintRect(&tRect);
inrun = 0;
}
}
}
if(inrun != 0)
PaintRect(&tRect);
/* Close and compress the partial region */
rasterRegion = (region *) CloseRegion();
if(rasterRegion == 0 )
{
GrafFree(totalRegion);
return(0);
}
/* Accumulate running total region */
tempRegion = (region *) UnionRegion(rasterRegion, totalRegion);
/* Discard partial regions */
GrafFree(rasterRegion);
GrafFree(totalRegion);
if(tempRegion == 0)
return(0);
totalRegion = tempRegion ;
}
return(totalRegion);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -