automatic commit - 25-11-2022
This commit is contained in:
852
tools/vision/ldv/src/bhole/bhole.c
Normal file
852
tools/vision/ldv/src/bhole/bhole.c
Normal file
@@ -0,0 +1,852 @@
|
||||
/*
|
||||
*
|
||||
*
|
||||
* Version PureC / Gcc
|
||||
*/
|
||||
|
||||
#define PCGEMLIB 1 /* mettre 1 si les utilisateurs de Pure C
|
||||
* utilise les librairies GEM Pure C */
|
||||
|
||||
/* Fichiers headers */
|
||||
|
||||
#include <stdio.h> /* Forget this and sprintf will badly format numbers */
|
||||
#include <portab.h>
|
||||
#if PCGEMLIB
|
||||
#include <aes.h>
|
||||
#include <vdi.h>
|
||||
#else
|
||||
#include <aesbind.h>
|
||||
#include <vdibind.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
#include "..\..\ldg.h"
|
||||
#include "..\..\vapi.h"
|
||||
#include "..\..\ldv.h"
|
||||
#include "..\..\mt_aes.h"
|
||||
|
||||
/* Prototypages */
|
||||
LDV_INFOS * cdecl GetLDVCapabilities(VAPI *vapi) ;
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
LDV_STATUS cdecl Preview(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
|
||||
void OnClose(void) ;
|
||||
|
||||
/* Variables globales */
|
||||
PROC Proc[] = {
|
||||
"GetLDVCapabilities", "LDV Capabilities", (void *)GetLDVCapabilities,
|
||||
"PreRun", "Run Initiliaze", (void *)PreRun,
|
||||
"Run", "LDV Feature", (void *)Run,
|
||||
"Preview", "Preview", (void *)Preview,
|
||||
} ;
|
||||
|
||||
char Info[] = "LDV";
|
||||
|
||||
LDGLIB Ldg[] = {
|
||||
0x0101, /* LDV version */
|
||||
4, /* Number of functions in the lib */
|
||||
Proc, /* Pointers to LDV functions */
|
||||
Info, /* Library Information */
|
||||
0x0, /* Lib flags, mandatory */
|
||||
OnClose, /* Closing, free VDIHandle */
|
||||
};
|
||||
|
||||
#define BP_CAPS (LDVF_ATARIFORMAT | LDVF_SUPPORTPREVIEW | LDVF_SUPPORTPROG | LDVF_REALTIMEPARAMS | LDVF_SUPPORTCANCEL | LDVF_NOSELECTION)
|
||||
#define TC_CAPS (LDVF_SPECFORMAT | LDVF_SUPPORTPREVIEW | LDVF_SUPPORTPROG | LDVF_REALTIMEPARAMS | LDVF_SUPPORTCANCEL | LDVF_NOSELECTION)
|
||||
|
||||
LDV_INFOS LdvInfos = {
|
||||
(short) sizeof(LDV_INFOS), /* Size of this structure */
|
||||
TLDV_MODIFYIMG, /* LDV Type */
|
||||
"Jean Lusetti", /* Authors */
|
||||
{
|
||||
{ 1, 1, BP_CAPS }, /* 1 bit-plane capabilities */
|
||||
{ 2, 2, BP_CAPS }, /* 2 bit-plane capabilities */
|
||||
{ 4, 4, BP_CAPS }, /* 4 bit-plane capabilities */
|
||||
{ 8, 8, BP_CAPS }, /* 8 bit-plane capabilities */
|
||||
{ 16, 16, TC_CAPS }, /* 16 bit-plane capabilities */
|
||||
{ 32, 32, TC_CAPS }, /* 32 bit-plane capabilities */
|
||||
{ 0, 0, 0UL } /* End of capabilities list */
|
||||
},
|
||||
} ;
|
||||
VAPI *Vapi = NULL ;
|
||||
|
||||
#define ITRIGO_ARRAY_NBITS 14
|
||||
#define ITRIGO_ARRAY_SIZE (1 << ITRIGO_ARRAY_NBITS)
|
||||
#define ITRIGO_ANGLE_MAX (ITRIGO_ARRAY_SIZE-1)
|
||||
|
||||
#define QUARTER (ITRIGO_ARRAY_SIZE/4)
|
||||
#define ANGLE_ADD (M_PI/2.0/(double)QUARTER) ;
|
||||
|
||||
long* pre_cosin = NULL ; /* Array of pre-computed cosinus/sinus values */
|
||||
long* pre_loffset = NULL ; /* To hold pre-computation of line offsets */
|
||||
int lo_w=0, lo_h=0, lo_nplanes=0 ; /* Current parameters for line offset */
|
||||
unsigned long VapiLogLevel = LL_DISABLED ;
|
||||
unsigned long ProcMask = 0L ;
|
||||
short UseSym = -1 ; /* By default use symmetry to save CPU calculations */
|
||||
/* On Aranym, this is usually slower, so there is a */
|
||||
/* Setting in bhole.ini to force no symetry usage */
|
||||
|
||||
/* Macro to access pre-computed cosinus/sinus array */
|
||||
/* Sinus is right after cosinus value */
|
||||
#define COS(i) (pre_cosin[(i)<<1])
|
||||
#define SIN(i) (pre_cosin[1 + ( (i)<<1 )])
|
||||
|
||||
/* Back Hole computation parameters are not passed to speed up calculations, */
|
||||
/* They are global to the module */
|
||||
/* Black Hole symmetry rotation */
|
||||
typedef struct _RECT
|
||||
{
|
||||
short x ;
|
||||
short y ;
|
||||
short w ;
|
||||
short h ;
|
||||
}
|
||||
RECT, *PRECT ;
|
||||
|
||||
typedef struct _BH_SPROPERTIES
|
||||
{
|
||||
short estdpc ; /* Estimated duration in % (100 being the one without using symmetry) */
|
||||
short nrect ;
|
||||
short nsym ;
|
||||
RECT rect[9] ;
|
||||
}
|
||||
BH_SPROPERTIES, *PBH_SPROPERTIES ;
|
||||
|
||||
extern long bh_xd, bh_yd, bh_rd2, bh_xs, bh_ys, bh_ref ;
|
||||
extern long bh_xc, bh_yc ;
|
||||
extern short bh_out_w, bh_out_h, bh_in_w, bh_in_h ;
|
||||
extern short bh_out_x, bh_out_y ;
|
||||
short bh_pc, bh_nrect ;
|
||||
|
||||
/* This is the routine address that will operate on a line basis */
|
||||
static void (*BHLRoutine)(short use_sym, void* in, void* out) ;
|
||||
|
||||
/* Specific 68030 and FPU routines */
|
||||
/* In BHOLE.S */
|
||||
extern void BHL32_68030(short use_sym, void* in, void* out) ;
|
||||
extern void BHL16_68030(short use_sym, void* in, void* out) ;
|
||||
extern void BHLInd_68030(short use_sym, void* in, void* out) ;
|
||||
extern void BHL32_F68030(short use_sym, void* in, void* out) ;
|
||||
extern void BHL16_F68030(short use_sym, void* in, void* out) ;
|
||||
extern void BHLInd_F68030(short use_sym, void* in, void* out) ;
|
||||
extern void lcosin_fpu(long i, long* pcs) ;
|
||||
|
||||
|
||||
/* GET/SET pixel macros for True Color 16 and 32bit */
|
||||
#define SET_TCPIXEL(p,x,y,val) (p[pre_loffset[y]+x]=val)
|
||||
#define GET_TCPIXEL(p,x,y) (p[pre_loffset[y]+x])
|
||||
|
||||
/* Rotation by 90° macro */
|
||||
#define R90(x,y) { long _x=x; x=-y; y=_x; }
|
||||
|
||||
/* Macro to initialize calculations for a line */
|
||||
#define BH_INIT_LINE\
|
||||
bh_xd = bh_out_x-bh_xc ;\
|
||||
bh_rd2 = (bh_xd*bh_xd + bh_yd*bh_yd) ;\
|
||||
|
||||
/* This is the routine that computes the resulting pixel (bh_xs,bh_ys) in source image */
|
||||
/* From the pixel (bh_xd, bh_yd) in destination image */
|
||||
/* (bh_xc,bh_yc) is the center pixel of the back hole */
|
||||
/* This routine also returns if the resulting pixel is in the source image */
|
||||
int rBH_68000(void)
|
||||
{
|
||||
int not_in_range = 1 ;
|
||||
long alpha ;
|
||||
|
||||
bh_rd2 += ( bh_xd << 1 ) + 1 ;
|
||||
alpha = bh_ref / (1+bh_rd2) ;
|
||||
alpha &= ITRIGO_ANGLE_MAX ;
|
||||
bh_xs = bh_xd * COS(alpha) - bh_yd * SIN(alpha) ;
|
||||
bh_xs >>= 16 ;
|
||||
if ( (bh_xs >= -bh_xc) && (bh_xs < -bh_xc+bh_in_w) )
|
||||
{
|
||||
bh_ys = bh_xd * SIN(alpha) + bh_yd * COS(alpha) ;
|
||||
bh_ys >>= 16 ;
|
||||
if ( (bh_ys >= -bh_yc) && (bh_ys < -bh_yc+bh_in_h) )
|
||||
not_in_range = 0 ;
|
||||
}
|
||||
|
||||
return not_in_range ;
|
||||
}
|
||||
|
||||
/* For 68000/bit-planes organization: */
|
||||
/* This routine returns the value of the pixel index in the source image */
|
||||
/* Assuming (bh_xs,bh_ys) is within the source image */
|
||||
#pragma warn -par
|
||||
void BHLInd_68000(short use_sym, void* in, void* out)
|
||||
{
|
||||
unsigned char* in_ptr = (unsigned char*) in ;
|
||||
unsigned char* out_ptr = (unsigned char*) out ;
|
||||
short x ;
|
||||
|
||||
for ( x = bh_out_x; x < bh_out_w; x++, bh_xd++ )
|
||||
{
|
||||
if ( rBH_68000() == 0 )
|
||||
out_ptr[x] = in_ptr[pre_loffset[bh_ys+bh_yc] + bh_xs+bh_xc] ;
|
||||
else
|
||||
out_ptr[x] = 0 ;
|
||||
}
|
||||
}
|
||||
#pragma warn +par
|
||||
|
||||
/* For 68000/16bit TrueColor organization: */
|
||||
/* This routine returns the value of the pixel index in the source image */
|
||||
/* Assuming (bh_xs,bh_ys) is within the source image */
|
||||
void BHL16_68000(short use_sym, void* in, void* out)
|
||||
{
|
||||
unsigned int* in_ptr = (unsigned int*) in ;
|
||||
unsigned int* out_ptr = (unsigned int*) out ;
|
||||
short x ;
|
||||
|
||||
if (use_sym)
|
||||
{
|
||||
unsigned long save_bh_xd, save_bh_yd ;
|
||||
short n ;
|
||||
|
||||
for ( x = bh_out_x; x <= bh_out_x+(bh_out_w>>1); x++, bh_xd++ )
|
||||
{
|
||||
/* Save bh_xd and bh_yd as they will change */
|
||||
save_bh_xd = bh_xd ;
|
||||
save_bh_yd = bh_yd ;
|
||||
|
||||
if ( rBH_68000() == 0 ) /* Compute 1st pixel with Black Hole formula */
|
||||
SET_TCPIXEL(out_ptr, bh_xd+bh_xc, bh_yd+bh_yc, GET_TCPIXEL(in_ptr, bh_xs+bh_xc, bh_ys+bh_yc)) ;
|
||||
else
|
||||
SET_TCPIXEL(out_ptr, bh_xd+bh_xc, bh_yd+bh_yc, 0xFFFF) ;
|
||||
|
||||
/* Deduce 2nd, 3rd and 4th pixel */
|
||||
for (n=0; n < 3; n++)
|
||||
{
|
||||
R90(bh_xd, bh_yd) ;
|
||||
R90(bh_xs, bh_ys) ;
|
||||
if ( (bh_xd>=-bh_xc) && (bh_xd < -bh_xc+bh_in_w) && (bh_yd >= -bh_yc) && (bh_yd < -bh_yc+bh_in_h))
|
||||
{
|
||||
if ( (bh_xs>=-bh_xc) && (bh_xs < -bh_xc+bh_in_w) && (bh_ys >= -bh_yc) && (bh_ys < -bh_yc+bh_in_h))
|
||||
SET_TCPIXEL(out_ptr, bh_xd+bh_xc, bh_yd+bh_yc, GET_TCPIXEL(in_ptr, bh_xs+bh_xc, bh_ys+bh_yc)) ;
|
||||
else
|
||||
SET_TCPIXEL(out_ptr, bh_xd+bh_xc, bh_yd+bh_yc, 0xFFFF) ;
|
||||
}
|
||||
}
|
||||
/* Restore bh_xd and bh_yd */
|
||||
bh_xd = save_bh_xd ;
|
||||
bh_yd = save_bh_yd ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( x = bh_out_x; x < bh_out_x+bh_out_w; x++, bh_xd++ )
|
||||
{
|
||||
if ( rBH_68000() == 0 )
|
||||
out_ptr[x] = in_ptr[pre_loffset[bh_ys+bh_yc] + bh_xs+bh_xc] ;
|
||||
else
|
||||
out_ptr[x] = 0xFFFF ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* For 68000/32bit TrueColor organization: */
|
||||
/* This routine returns the value of the pixel index in the source image */
|
||||
/* Assuming (bh_xs,bh_ys) is within the source image */
|
||||
void BHL32_68000(short use_sym, void* in, void* out)
|
||||
{
|
||||
unsigned long* in_ptr = (unsigned long*) in ;
|
||||
unsigned long* out_ptr = (unsigned long*) out ;
|
||||
short x ;
|
||||
|
||||
if (use_sym)
|
||||
{
|
||||
unsigned long save_bh_xd, save_bh_yd ;
|
||||
short n ;
|
||||
|
||||
for ( x = bh_out_x; x <= bh_out_x+(bh_out_w>>1); x++, bh_xd++ )
|
||||
{
|
||||
/* Save bh_xd and bh_yd as they will change */
|
||||
save_bh_xd = bh_xd ;
|
||||
save_bh_yd = bh_yd ;
|
||||
|
||||
if ( rBH_68000() == 0 ) /* Compute 1st pixel with Black Hole formula */
|
||||
SET_TCPIXEL(out_ptr, bh_xd+bh_xc, bh_yd+bh_yc, GET_TCPIXEL(in_ptr, bh_xs+bh_xc, bh_ys+bh_yc)) ;
|
||||
else
|
||||
SET_TCPIXEL(out_ptr, bh_xd+bh_xc, bh_yd+bh_yc, 0xFFFFFFFFL) ;
|
||||
|
||||
/* Deduce 2nd, 3rd and 4th pixel */
|
||||
for (n=0; n < 3; n++)
|
||||
{
|
||||
R90(bh_xd, bh_yd) ;
|
||||
R90(bh_xs, bh_ys) ;
|
||||
if ( (bh_xd>=-bh_xc) && (bh_xd < -bh_xc+bh_in_w) && (bh_yd >= -bh_yc) && (bh_yd < -bh_yc+bh_in_h))
|
||||
{
|
||||
if ( (bh_xs>=-bh_xc) && (bh_xs < -bh_xc+bh_in_w) && (bh_ys >= -bh_yc) && (bh_ys < -bh_yc+bh_in_h))
|
||||
SET_TCPIXEL(out_ptr, bh_xd+bh_xc, bh_yd+bh_yc, GET_TCPIXEL(in_ptr, bh_xs+bh_xc, bh_ys+bh_yc)) ;
|
||||
else
|
||||
SET_TCPIXEL(out_ptr, bh_xd+bh_xc, bh_yd+bh_yc, 0xFFFFFFFFL) ;
|
||||
}
|
||||
}
|
||||
/* Restore bh_xd and bh_yd */
|
||||
bh_xd = save_bh_xd ;
|
||||
bh_yd = save_bh_yd ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( x = bh_out_x; x < bh_out_x+bh_out_w; x++, bh_xd++ )
|
||||
{
|
||||
if ( rBH_68000() == 0 )
|
||||
out_ptr[x] = in_ptr[pre_loffset[bh_ys+bh_yc] + bh_xs+bh_xc] ;
|
||||
else
|
||||
out_ptr[x] = 0xFFFFFFFFL ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void lcosin(long i, long* pcs)
|
||||
{
|
||||
double angle = i*ANGLE_ADD ;
|
||||
|
||||
pcs[0] = (long) (65536.0 * cos(angle)) ;
|
||||
pcs[1] = (long) (65536.0 * sin(angle)) ;
|
||||
}
|
||||
|
||||
int InitTrigo(int fpu)
|
||||
{
|
||||
void (*rlcosin)(long i, long* pcs) ;
|
||||
long cs[2] ;
|
||||
long q, i;
|
||||
clock_t t0 ;
|
||||
|
||||
/* if ( pre_cosin[0] == 65536L ) return 0 ; Used to detect init done before dynamic allocation design */
|
||||
if ( pre_cosin ) return 0 ;
|
||||
pre_cosin = (long*) calloc( ITRIGO_ARRAY_SIZE, 2*sizeof(long) ) ;
|
||||
if ( pre_cosin == NULL ) return -1 ;
|
||||
|
||||
t0 = clock() ;
|
||||
if (fpu) rlcosin = lcosin_fpu ;
|
||||
else rlcosin = lcosin ;
|
||||
for ( i = 0; i < QUARTER; i++ )
|
||||
{
|
||||
rlcosin( i, cs ) ;
|
||||
COS(i) = cs[0] ;
|
||||
SIN(i) = cs[1] ;
|
||||
|
||||
q = QUARTER ;
|
||||
/* Set [PI/2;PI] */
|
||||
COS(q+i) = -SIN(i) ;
|
||||
SIN(q+i) = COS(i) ;
|
||||
|
||||
q += QUARTER ;
|
||||
/* Set [PI;3*PI/2] */
|
||||
COS(q+i) = -COS(i) ;
|
||||
SIN(q+i) = -SIN(i) ;
|
||||
|
||||
q += QUARTER ;
|
||||
/* Set [3*PI/2; 2*PI] */
|
||||
COS(q+i) = COS(i) ;
|
||||
SIN(q+i) = -SIN(i) ;
|
||||
}
|
||||
if (Vapi && Vapi->LoDoLog)
|
||||
Vapi->LoDoLog(LL_INFO, "IniTrigo%s done in %ldms", fpu ? "(FPU)":"", 1000L * (clock()-t0)/CLK_TCK) ;
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
/* Called when LDV is loaded, take this opportunity to get some */
|
||||
/* Info about system: VAPI version and CPU/FPU availability */
|
||||
LDV_INFOS * cdecl GetLDVCapabilities(VAPI *vapi)
|
||||
{
|
||||
Vapi = vapi ;
|
||||
VapiLogLevel = LL_DISABLED ;
|
||||
if ( Vapi && (Vapi->Header.Version >= 0x0104) && Vapi->LoDoLog && Vapi->LoGetLogLevel )
|
||||
{
|
||||
VapiLogLevel = Vapi->LoGetLogLevel() ;
|
||||
if (Vapi->CoGetProcessors)
|
||||
ProcMask = Vapi->CoGetProcessors() ;
|
||||
|
||||
if (ProcMask & CO_HAS_030)
|
||||
Vapi->LoDoLog(LL_INFO, "%s", "68030 processor available") ;
|
||||
|
||||
if (ProcMask & CO_HAS_FPU)
|
||||
Vapi->LoDoLog(LL_INFO, "%s", "Floating Point unit available") ;
|
||||
}
|
||||
|
||||
return( &LdvInfos ) ;
|
||||
}
|
||||
|
||||
/* Free allocated RunTime stuff */
|
||||
void OnClose(void)
|
||||
{
|
||||
if ( pre_cosin ) free( pre_cosin ) ;
|
||||
pre_cosin = NULL ;
|
||||
if ( pre_loffset ) free( pre_loffset ) ;
|
||||
pre_loffset = NULL ;
|
||||
}
|
||||
|
||||
/* Pre-compute line offsets from source to speed-up computations */
|
||||
int compute_loffset(MFDB* in, long** ppre_lo, int* plo_w, int* plo_h, int* plo_nplanes)
|
||||
{
|
||||
/* Sanity checks */
|
||||
if ( (ppre_lo == NULL) || (plo_w == NULL) || (plo_h == NULL) || (plo_nplanes == NULL) )
|
||||
return -2 ;
|
||||
|
||||
if ( *ppre_lo && (*plo_w == in->fd_w) && (*plo_h == in->fd_h) && (*plo_nplanes == in->fd_nplanes) )
|
||||
{
|
||||
/* Current line offsets are still valid */
|
||||
return 0 ;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Need to compute line offsets */
|
||||
*plo_w = *plo_h = *plo_nplanes = 0 ;
|
||||
if (*ppre_lo) free(*ppre_lo) ;
|
||||
*ppre_lo = (long*) malloc(sizeof(long) * (long)in->fd_h) ;
|
||||
if (*ppre_lo)
|
||||
{
|
||||
long* pt_off ;
|
||||
long add = (long) ALIGN16( in->fd_w ) ;
|
||||
long offset = 0L ;
|
||||
int y ;
|
||||
|
||||
pt_off = *ppre_lo ;
|
||||
for ( y = 0; y < in->fd_h; y++ )
|
||||
{
|
||||
*pt_off++ = offset ;
|
||||
offset += add ;
|
||||
}
|
||||
*plo_w = in->fd_w ;
|
||||
*plo_h = in->fd_h ;
|
||||
*plo_nplanes = in->fd_nplanes ;
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
}
|
||||
|
||||
return -1 ;
|
||||
}
|
||||
|
||||
#pragma warn -par
|
||||
/* Just say that output image has same width/length than source */
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
out->Raster.fd_w = in->Raster.fd_w ;
|
||||
out->Raster.fd_h = in->Raster.fd_h ;
|
||||
|
||||
return( ELDV_NOERROR ) ;
|
||||
}
|
||||
#pragma warn +par
|
||||
|
||||
/* Update progression window 1 time on 16 */
|
||||
char check_prog(short y, short ymax)
|
||||
{
|
||||
char cancel = 0 ;
|
||||
|
||||
if ( ( y & 0x0F ) == 0 )
|
||||
{
|
||||
short pc = (short)((y*100L)/ymax) ;
|
||||
|
||||
cancel = Vapi->PrSetProgEx( bh_pc+pc/bh_nrect ) ;
|
||||
}
|
||||
|
||||
return cancel ;
|
||||
}
|
||||
|
||||
/* Initialize global variables for calculation */
|
||||
void init_computation(short xc, short yc, long angle, MFDB* in, RECT* rect)
|
||||
{
|
||||
long maxrd2 ;
|
||||
|
||||
bh_xd = -xc ;
|
||||
bh_yd = -yc ;
|
||||
maxrd2 = bh_xd*bh_xd + bh_yd*bh_yd ;
|
||||
if ( (ProcMask & (CO_HAS_030|CO_HAS_FPU)) == (CO_HAS_030|CO_HAS_FPU) )
|
||||
maxrd2 = (long) sqrt(maxrd2) ;
|
||||
bh_ref = (angle * maxrd2) ;
|
||||
bh_xc = xc ;
|
||||
bh_yc = yc ;
|
||||
bh_in_w = in->fd_w ;
|
||||
bh_in_h = in->fd_h ;
|
||||
bh_out_x = rect->x ;
|
||||
bh_out_y = rect->y ;
|
||||
bh_out_w = rect->w ;
|
||||
bh_out_h = rect->h ;
|
||||
|
||||
bh_yd = bh_out_y-bh_yc ;
|
||||
}
|
||||
|
||||
/* 68000 routine for bit-plane images */
|
||||
LDV_STATUS bpRun(MFDB *in, long angle, short xc, short yc, MFDB *out, RECT* rect, short use_sym)
|
||||
{
|
||||
MFDB dst_line ;
|
||||
LDV_STATUS status = ELDV_NOERROR ;
|
||||
size_t size_indexes, size_dst_line ;
|
||||
short y ;
|
||||
long wout, sizelout ;
|
||||
unsigned char *index_in, *index_out, *out_ptr ;
|
||||
char cancel = 0 ;
|
||||
|
||||
/* We will convert the whole image in indexes */
|
||||
/* Allocate memory to convert then to bitplanes */
|
||||
/* A line to destination tion */
|
||||
size_indexes = (long) ALIGN16( in->fd_w ) ;
|
||||
size_indexes *= (long) in->fd_h ;
|
||||
size_dst_line = (long) ALIGN16( out->fd_w ) ;
|
||||
index_in = (unsigned char *) malloc( size_indexes ) ;
|
||||
if ( index_in == NULL ) return ELDV_NOTENOUGHMEMORY ;
|
||||
index_out = (unsigned char *) malloc(size_dst_line) ;
|
||||
if ( index_out == NULL )
|
||||
{
|
||||
free(index_in) ;
|
||||
return ELDV_NOTENOUGHMEMORY ;
|
||||
}
|
||||
|
||||
/* Convert all source to indexes */
|
||||
Vapi->RaRaster2Ind( in->fd_addr, size_indexes, (long)in->fd_nplanes, index_in ) ;
|
||||
|
||||
memcpy( &dst_line, out, sizeof(MFDB) ) ;
|
||||
dst_line.fd_wdwidth = out->fd_w / 16 ;
|
||||
if ( out->fd_w % 16 ) dst_line.fd_wdwidth++ ;
|
||||
dst_line.fd_h = 1 ;
|
||||
wout = (long) ALIGN16( out->fd_w ) ;
|
||||
out_ptr = out->fd_addr ;
|
||||
sizelout = Vapi->RaGetImgSize( (long) dst_line.fd_w, (long) dst_line.fd_h, (long) out->fd_nplanes ) ;
|
||||
init_computation(xc, yc, angle, in, rect) ;
|
||||
for ( y = 0; !cancel && (y < out->fd_h); y++, bh_yd++, out_ptr += sizelout )
|
||||
{
|
||||
BH_INIT_LINE ;
|
||||
BHLRoutine(use_sym, index_in, index_out) ;
|
||||
dst_line.fd_addr = out_ptr ;
|
||||
Vapi->RaInd2RasterInit( &dst_line, wout ) ;
|
||||
Vapi->RaInd2Raster( index_out, wout ) ;
|
||||
cancel = check_prog(y, out->fd_h) ;
|
||||
}
|
||||
|
||||
free(index_in) ;
|
||||
free(index_out) ;
|
||||
if ( cancel ) status = ELDV_CANCELLED ;
|
||||
|
||||
return( status ) ;
|
||||
}
|
||||
|
||||
/* 68000 routine for 16bit True Color images */
|
||||
LDV_STATUS Run16(MFDB *in, long angle, short xc, short yc, MFDB *out, RECT* rect, short use_sym)
|
||||
{
|
||||
LDV_STATUS status = ELDV_NOERROR ;
|
||||
unsigned int *in_ptr, *out_ptr ;
|
||||
unsigned long sizelout = 0 ;
|
||||
short y, hy ;
|
||||
char cancel = 0 ;
|
||||
|
||||
in_ptr = (unsigned int*) in->fd_addr ;
|
||||
out_ptr = (unsigned int*) out->fd_addr ;
|
||||
init_computation(xc, yc, angle, in, rect) ;
|
||||
hy = bh_out_y+(bh_out_h>>1) ;
|
||||
if (!use_sym)
|
||||
{
|
||||
sizelout = (long) ALIGN16( out->fd_w ) ;
|
||||
out_ptr += sizelout*(long)rect->y ;
|
||||
hy = bh_out_y+bh_out_h ;
|
||||
}
|
||||
for ( y = bh_out_y; !cancel && (y < hy); y++, bh_yd++, out_ptr += sizelout )
|
||||
{
|
||||
BH_INIT_LINE ;
|
||||
BHLRoutine(use_sym, in_ptr, out_ptr) ;
|
||||
cancel = check_prog(y, hy-bh_out_y) ;
|
||||
}
|
||||
|
||||
if ( cancel ) status = ELDV_CANCELLED ;
|
||||
|
||||
return( status ) ;
|
||||
}
|
||||
|
||||
/* 68000 routine for 32bit True Color images */
|
||||
LDV_STATUS Run32(MFDB *in, long angle, short xc, short yc, MFDB *out, RECT* rect, short use_sym)
|
||||
{
|
||||
LDV_STATUS status = ELDV_NOERROR ;
|
||||
unsigned long *in_ptr, *out_ptr ;
|
||||
unsigned long sizelout = 0 ;
|
||||
short y, hy ;
|
||||
char cancel = 0 ;
|
||||
|
||||
in_ptr = (unsigned long*) in->fd_addr ;
|
||||
out_ptr = (unsigned long*) out->fd_addr ;
|
||||
init_computation(xc, yc, angle, in, rect) ;
|
||||
hy = bh_out_y+(bh_out_h>>1) ;
|
||||
if (!use_sym)
|
||||
{
|
||||
sizelout = (long) ALIGN16( out->fd_w ) ;
|
||||
out_ptr += sizelout*(long)rect->y ;
|
||||
hy = bh_out_y+bh_out_h ;
|
||||
}
|
||||
for ( y = bh_out_y; !cancel && (y < hy); y++, bh_yd++, out_ptr += sizelout )
|
||||
{
|
||||
BH_INIT_LINE ;
|
||||
BHLRoutine(use_sym, in_ptr, out_ptr) ;
|
||||
cancel = check_prog(y, hy-bh_out_y) ;
|
||||
}
|
||||
|
||||
if ( cancel ) status = ELDV_CANCELLED ;
|
||||
|
||||
return( status ) ;
|
||||
}
|
||||
|
||||
int MayAddRect(RECT* subRect, BH_SPROPERTIES* sgProps)
|
||||
{
|
||||
int add = (subRect->w && subRect->h) ;
|
||||
|
||||
if (Vapi->LoDoLog)
|
||||
Vapi->LoDoLog(LL_DEBUG,"MayAddRect (%d,%d,%d,%d)", subRect->x, subRect->y, subRect->w, subRect->h);
|
||||
if ( add ) /* Sub Rectangle not empty */
|
||||
memcpy( &sgProps->rect[sgProps->nrect++], subRect, sizeof(RECT) ) ;
|
||||
|
||||
return( add ) ;
|
||||
}
|
||||
|
||||
/* Estimation of the expected gain by using rotation symmetry */
|
||||
void SymmetrySplit(MFDB* img, short xc, short yc, BH_SPROPERTIES* sgProps)
|
||||
{
|
||||
long npts_insym, npts_total, npts_to_compute ;
|
||||
short sw = 0 ;
|
||||
|
||||
if ( UseSym && ( (img->fd_nplanes == 16) || (img->fd_nplanes == 32) ) )
|
||||
{
|
||||
/* Bitplane organization would have make things too complicated */
|
||||
/* By the way, who is using bitplanes nowadays ? */
|
||||
sw = xc ;
|
||||
if ( img->fd_w-xc < sw ) sw = img->fd_w-xc ;
|
||||
if ( yc < sw ) sw = yc ;
|
||||
if ( img->fd_h-yc < sw ) sw = img->fd_h-yc ;
|
||||
if ( img->fd_h-yc < sw ) sw = img->fd_h-yc ;
|
||||
|
||||
/* Let's build the rectangle arrays to define the image */
|
||||
/* First rectangle (square actually) is the one to use for symmetry */
|
||||
/* On this one only 25% of pixels will be computed with Black Hole formula */
|
||||
sgProps->nrect = 1 ;
|
||||
sgProps->nsym = 0 ;
|
||||
|
||||
sgProps->rect[0].x = xc-sw ;
|
||||
sgProps->rect[0].y = yc-sw ;
|
||||
sgProps->rect[0].w = 2*sw ;
|
||||
sgProps->rect[0].h = 2*sw ;
|
||||
}
|
||||
|
||||
npts_total = (long)img->fd_w*(long)img->fd_h ;
|
||||
npts_insym = 4L*(long)sw*(long)sw ;
|
||||
npts_to_compute = npts_total-((3L*npts_insym)>>2) ;
|
||||
sgProps->estdpc = (100L*npts_to_compute)/npts_total ;
|
||||
if ( sgProps->estdpc > 70 )
|
||||
{
|
||||
/* Not worth make things complicated for that gain */
|
||||
sgProps->nrect = 1 ;
|
||||
sgProps->nsym = -1 ;
|
||||
sgProps->rect[0].x = 0 ;
|
||||
sgProps->rect[0].y = 0 ;
|
||||
sgProps->rect[0].w = img->fd_w ;
|
||||
sgProps->rect[0].h = img->fd_h ;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Let's build the remaining rectangles */
|
||||
RECT* sRect = &sgProps->rect[0] ; /* Symmetry Rectangle */
|
||||
RECT subRect ;
|
||||
/*
|
||||
|----------------------------------------|
|
||||
| R1 | R2 | R3 |
|
||||
|----------------------------------------|
|
||||
| ****** |
|
||||
| R4 ****** R5 |
|
||||
| ****** |
|
||||
| ****** |
|
||||
|----------------------------------------|
|
||||
| R6 | R7 | R8 |
|
||||
|----------------------------------------|
|
||||
*/
|
||||
|
||||
/* R1 */
|
||||
subRect.x = 0 ; subRect.y = 0 ;
|
||||
subRect.w = sRect->x ; subRect.h = sRect->y ;
|
||||
if (MayAddRect( &subRect, sgProps ))
|
||||
if (Vapi->LoDoLog)
|
||||
Vapi->LoDoLog(LL_DEBUG,"Adding R1(%d,%d,%d,%d)", subRect.x, subRect.y, subRect.w, subRect.h);
|
||||
|
||||
/* R2 */
|
||||
subRect.x = sRect->x ; subRect.y = 0 ;
|
||||
subRect.w = sRect->w ; subRect.h = sRect->y ;
|
||||
if (MayAddRect( &subRect, sgProps ))
|
||||
if (Vapi->LoDoLog)
|
||||
Vapi->LoDoLog(LL_DEBUG,"Adding R2(%d,%d,%d,%d)", subRect.x, subRect.y, subRect.w, subRect.h);
|
||||
|
||||
/* R3 */
|
||||
subRect.x = sRect->x+sRect->w ; subRect.y = 0 ;
|
||||
subRect.w = img->fd_w-sRect->x-sRect->w ; subRect.h = sRect->y ;
|
||||
if (MayAddRect( &subRect, sgProps ))
|
||||
if (Vapi->LoDoLog)
|
||||
Vapi->LoDoLog(LL_DEBUG,"Adding R3(%d,%d,%d,%d)", subRect.x, subRect.y, subRect.w, subRect.h);
|
||||
|
||||
/* R4 */
|
||||
subRect.x = 0 ; subRect.y = sRect->y ;
|
||||
subRect.w = sRect->x ; subRect.h = sRect->h ;
|
||||
if (MayAddRect( &subRect, sgProps ))
|
||||
if (Vapi->LoDoLog)
|
||||
Vapi->LoDoLog(LL_DEBUG,"Adding R4(%d,%d,%d,%d)", subRect.x, subRect.y, subRect.w, subRect.h);
|
||||
|
||||
/* R5 */
|
||||
subRect.x = sRect->x+sRect->w ; subRect.y = sRect->y ;
|
||||
subRect.w = img->fd_w-sRect->x-sRect->w ; subRect.h = sRect->h ;
|
||||
if (MayAddRect( &subRect, sgProps ))
|
||||
if (Vapi->LoDoLog)
|
||||
Vapi->LoDoLog(LL_DEBUG,"Adding R5(%d,%d,%d,%d)", subRect.x, subRect.y, subRect.w, subRect.h);
|
||||
|
||||
/* R6 */
|
||||
subRect.x = 0 ; subRect.y = sRect->y+sRect->h ;
|
||||
subRect.w = sRect->x ; subRect.h = img->fd_h-sRect->y-sRect->h ;
|
||||
if (MayAddRect( &subRect, sgProps ))
|
||||
if (Vapi->LoDoLog)
|
||||
Vapi->LoDoLog(LL_DEBUG,"Adding R6(%d,%d,%d,%d)", subRect.x, subRect.y, subRect.w, subRect.h);
|
||||
|
||||
/* R7 */
|
||||
subRect.x = sRect->x ; subRect.y = sRect->y+sRect->h ;
|
||||
subRect.w = sRect->w ; subRect.h = img->fd_h-sRect->y-sRect->h ;
|
||||
if (MayAddRect( &subRect, sgProps ))
|
||||
if (Vapi->LoDoLog)
|
||||
Vapi->LoDoLog(LL_DEBUG,"Adding R7(%d,%d,%d,%d)", subRect.x, subRect.y, subRect.w, subRect.h);
|
||||
|
||||
/* R8 */
|
||||
subRect.x = sRect->x+sRect->w ; subRect.y = sRect->y+sRect->h ;
|
||||
subRect.w = img->fd_w-sRect->x-sRect->w ; subRect.h = img->fd_h-sRect->y-sRect->h ;
|
||||
if (MayAddRect( &subRect, sgProps ))
|
||||
if (Vapi->LoDoLog)
|
||||
Vapi->LoDoLog(LL_DEBUG,"Adding R8(%d,%d,%d,%d)", subRect.x, subRect.y, subRect.w, subRect.h);
|
||||
}
|
||||
}
|
||||
|
||||
short GetSymetryUsageFromIni(void)
|
||||
{
|
||||
short use_sym = 1 ; /* Unless INI file say no, assume symetry usage */
|
||||
long found = 0 ;
|
||||
char *path_ldv, *language ;
|
||||
char val_key[64] ;
|
||||
|
||||
path_ldv = Vapi->CoGetLDVPath() ;
|
||||
language = Vapi->CoGetCurrentLanguage() ;
|
||||
if ( path_ldv && language && Vapi->InGetKeyFromFile )
|
||||
{
|
||||
char filename[256] ;
|
||||
|
||||
sprintf( filename, "%s\\%s\\BHOLE.INI", path_ldv, language ) ;
|
||||
if ( Vapi->LoDoLog ) Vapi->LoDoLog(LL_INFO,"Looking into %s to see symetry usage...", filename) ;
|
||||
found = Vapi->InGetKeyFromFile( filename, "Private", "UseSym", val_key ) ;
|
||||
if ( !found )
|
||||
{
|
||||
sprintf( filename, "%s\\BHOLE.INI", path_ldv ) ;
|
||||
if ( Vapi->LoDoLog ) Vapi->LoDoLog(LL_INFO,"Looking into non language specific %s to see symetry usage...", filename) ;
|
||||
found = Vapi->InGetKeyFromFile( filename, "Private", "UseSym", val_key ) ;
|
||||
}
|
||||
}
|
||||
else if ( Vapi->LoDoLog ) Vapi->LoDoLog(LL_WARNING,"Can't access LDV (%s) or language path (%s)!", path_ldv, language) ;
|
||||
|
||||
if ( found ) use_sym = atoi( val_key ) ;
|
||||
if ( Vapi->LoDoLog ) Vapi->LoDoLog(LL_INFO,"Symetry usage: %d (found=%ld)", use_sym, found) ;
|
||||
|
||||
return use_sym ;
|
||||
}
|
||||
|
||||
/* LDV Run routine */
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
BH_SPROPERTIES sgProps ;
|
||||
LDV_STATUS (*RunRoutine)(MFDB *in, long angle, short xc, short yc, MFDB *out, RECT* rect, short use_sym) ;
|
||||
LDV_STATUS status = ELDV_NOERROR ;
|
||||
long angle, np=0 ;
|
||||
short xc, yc, n ;
|
||||
|
||||
if ( Vapi->Header.Version < 0x102 ) return ELDV_BADVAPIVERSION ;
|
||||
|
||||
if ( InitTrigo((ProcMask & CO_HAS_FPU) == CO_HAS_FPU) != 0 ) return ELDV_NOTENOUGHMEMORY ;
|
||||
if ( compute_loffset(&in->Raster, &pre_loffset, &lo_w, &lo_h, &lo_nplanes) ) return ELDV_NOTENOUGHMEMORY ;
|
||||
if ( UseSym == -1 ) UseSym = GetSymetryUsageFromIni() ;
|
||||
|
||||
if ( in->Raster.fd_nplanes <= 8 ) { BHLRoutine = BHLInd_68000 ; RunRoutine = bpRun ; }
|
||||
else if ( in->Raster.fd_nplanes == 16 ) { BHLRoutine = BHL16_68000 ; RunRoutine = Run16 ; }
|
||||
else if ( in->Raster.fd_nplanes == 32 ) { BHLRoutine = BHL32_68000 ; RunRoutine = Run32 ; }
|
||||
else return ELDV_IMGFORMATMISMATCH ;
|
||||
|
||||
if (ProcMask & CO_HAS_030)
|
||||
{
|
||||
if (ProcMask & CO_HAS_FPU)
|
||||
{
|
||||
/* Note that FPU requires also a 68030 here */
|
||||
/* To avoid having another set of macros in bhole.s */
|
||||
/* And convert even 68000 routines to ASM */
|
||||
/* FPU won't speed-up computations; it will just */
|
||||
/* Make the angle proportional to the distance to */
|
||||
/* Black Hole Center instead of its square */
|
||||
Vapi->PrOptimize(0x05) ;
|
||||
if ( in->Raster.fd_nplanes <= 8 ) BHLRoutine = BHLInd_F68030 ;
|
||||
else if ( in->Raster.fd_nplanes == 16 ) BHLRoutine = BHL16_F68030 ;
|
||||
else if ( in->Raster.fd_nplanes == 32 ) BHLRoutine = BHL32_F68030 ;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* CPU 030 'only', note that it is about 2 times faster than 68000 */
|
||||
/* Routine mostly because of 32x32x-->32 MULS.L instruction */
|
||||
Vapi->PrOptimize(0x01) ;
|
||||
if ( in->Raster.fd_nplanes <= 8 ) BHLRoutine = BHLInd_68030 ;
|
||||
else if ( in->Raster.fd_nplanes == 16 ) BHLRoutine = BHL16_68030 ;
|
||||
else if ( in->Raster.fd_nplanes == 32 ) BHLRoutine = BHL32_68030 ;
|
||||
}
|
||||
}
|
||||
|
||||
angle = (long) params->Param[0].s ;
|
||||
xc = ((long)params->Param[1].s * (long)in->Raster.fd_w)/100L ;
|
||||
yc = ((long)params->Param[2].s * (long)in->Raster.fd_h)/100L ;
|
||||
|
||||
SymmetrySplit(&in->Raster, xc, yc, &sgProps) ;
|
||||
if (Vapi->LoDoLog)
|
||||
{
|
||||
Vapi->LoDoLog(LL_DEBUG, "100 being the time without using symmetry, using symmetry would be %d", sgProps.estdpc) ;
|
||||
Vapi->LoDoLog(LL_DEBUG, "Image source : (0,0,+%d,+%d); %ld pixels", in->Raster.fd_w, in->Raster.fd_h, (long)in->Raster.fd_w * (long)in->Raster.fd_h) ;
|
||||
Vapi->LoDoLog(LL_DEBUG, "Symmetry zone : (%d,%d,+%d,+%d), index:%d", sgProps.rect[0].x, sgProps.rect[0].y, sgProps.rect[0].w, sgProps.rect[0].h, sgProps.nsym) ;
|
||||
}
|
||||
|
||||
bh_nrect = sgProps.nrect ;
|
||||
for ( n=0; (status != ELDV_CANCELLED) && (n < sgProps.nrect); n++)
|
||||
{
|
||||
long npix ;
|
||||
|
||||
bh_pc = (100*n)/sgProps.nrect ; /* For progression indicator as we may have multiple loops */
|
||||
npix = (long)sgProps.rect[n].w * (long)sgProps.rect[n].h ;
|
||||
np += npix ;
|
||||
if ( VapiLogLevel >= LL_PERF )
|
||||
{
|
||||
size_t t0, tms ;
|
||||
|
||||
t0 = clock() ;
|
||||
status = RunRoutine( &in->Raster, angle, xc, yc, &out->Raster, &sgProps.rect[n], (sgProps.nsym == n) ) ;
|
||||
tms = (1000L * (clock() - t0) ) / CLK_TCK ;
|
||||
if (tms == 0 ) tms = 1 ;
|
||||
if (Vapi->LoDoLog)
|
||||
Vapi->LoDoLog(LL_PERF, "Run zone %d: (%d,%d,+%d,+%d), use_sym=%d, %ld pixels, done in %ldms, %ld Kpixels/s",
|
||||
n, sgProps.rect[n].x, sgProps.rect[n].y, sgProps.rect[n].w, sgProps.rect[n].h, (sgProps.nsym == n), (long)sgProps.rect[n].w * (long)sgProps.rect[n].h, tms, npix/tms) ;
|
||||
}
|
||||
else
|
||||
status = RunRoutine( &in->Raster, angle, xc, yc, &out->Raster, &sgProps.rect[n], (sgProps.nsym == n) ) ;
|
||||
}
|
||||
if (Vapi->LoDoLog)
|
||||
Vapi->LoDoLog(LL_DEBUG, "%ld pixels computed or deduced", np) ;
|
||||
|
||||
return( status ) ;
|
||||
}
|
||||
|
||||
LDV_STATUS cdecl Preview(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
return( Run( in, params, out ) ) ;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ldg_init( Ldg ) ;
|
||||
|
||||
return( 0 ) ;
|
||||
}
|
||||
BIN
tools/vision/ldv/src/bhole/bhole.ldv
Normal file
BIN
tools/vision/ldv/src/bhole/bhole.ldv
Normal file
Binary file not shown.
15
tools/vision/ldv/src/bhole/bhole.prj
Normal file
15
tools/vision/ldv/src/bhole/bhole.prj
Normal file
@@ -0,0 +1,15 @@
|
||||
BHOLE.LDV
|
||||
.C [ ]
|
||||
.S [ -2 -8 ]
|
||||
.L [ ]
|
||||
|
||||
=
|
||||
|
||||
pcstart.o
|
||||
BHOLE.C
|
||||
BHOLES.S
|
||||
pcgemlib.lib
|
||||
pcstdlib.lib
|
||||
pctoslib.lib
|
||||
pcfltlib.lib
|
||||
..\..\ldg.lib
|
||||
635
tools/vision/ldv/src/bhole/bholes.s
Normal file
635
tools/vision/ldv/src/bhole/bholes.s
Normal file
@@ -0,0 +1,635 @@
|
||||
.IMPORT pre_cosin ; array of 2*ITRIGO_ARRAY_SIZE longs
|
||||
.IMPORT pre_loffset ; long*
|
||||
.EXPORT bh_xd, bh_yd, bh_rd2 ; long
|
||||
.EXPORT bh_xs, bh_ys, bh_ref ; long
|
||||
.EXPORT bh_xc, bh_yc ; long
|
||||
.EXPORT bh_out_w, bh_out_h ; short
|
||||
.EXPORT bh_in_w, bh_in_h ; short
|
||||
.EXPORT bh_out_x, bh_out_y ; short
|
||||
.EXPORT BHL32_68030,BHL16_68030,BHLInd_68030
|
||||
.EXPORT BHL32_F68030,BHL16_F68030,BHLInd_F68030
|
||||
.EXPORT lcosin_fpu
|
||||
|
||||
ITRIGO_ARRAY_SIZE EQU (1 << 14)
|
||||
ITRIGO_ANGLE_MAX EQU (ITRIGO_ARRAY_SIZE-1)
|
||||
QUARTER EQU (ITRIGO_ARRAY_SIZE/4)
|
||||
|
||||
; The black hole transformation consists of:
|
||||
; Rotate the destination pixel around the black hole center
|
||||
; The closest we are to the black hole, the bigger the rotation angle is
|
||||
; We have 2 or 3 parts of computation angle for black hole transformation:
|
||||
; 1: Just before dividing the maximum possible angle (depending on LDV paramter Rotation angle) by:
|
||||
; CPU: the square of distance to black hole center
|
||||
; FPU: the distance to black hole center; here we need 68881 instruction FSQRT
|
||||
; So there are 3 parts in macro calculations:
|
||||
; 1. Before dividing by distance or its square
|
||||
; 1a. (FPU only) Compute distance
|
||||
; 3. Divide by either distance or its square and state if the resulting pixel is in source image
|
||||
; Dividing by distance instead of its square gives better visual results
|
||||
MACRO BH_COMP_1
|
||||
MOVE.L A6,D0 ; Remember A6=bh_xd
|
||||
ADD.L D0,D0
|
||||
ADDQ.L #1,D0
|
||||
MOVE.L A5,D1 ; Remember A5=bh_rd2
|
||||
ADD.L D0,D1 ; bh_rd2(D1)=1+2*bh_xd(D0)
|
||||
MOVE.L bh_ref(PC),D2
|
||||
MOVE.L D1,A5 ; Save bh_rd2, free D1
|
||||
ADDQ.L #1,D1 ; We need bh_rd2+1 for divide
|
||||
ENDM
|
||||
|
||||
MACRO BH_COMP_2 bail_out_addr
|
||||
DIVU.L D1,D2 ; alpha(D2)=bh_ref/(1+bh_rd2)
|
||||
ANDI.L #ITRIGO_ANGLE_MAX,D2 ; alpha &= ITRIGO_ANGLE_MAX
|
||||
|
||||
LSL.L #3,D2 ; D2=offset for pre_cosin array
|
||||
MOVE.L A6,D0 ; D0=bh_xd
|
||||
MOVE.L bh_yd(PC),D1 ; D1=bh_yd
|
||||
MOVE.L 4(A2,D2.L),D3 ; A2->pre_cosin, D3.L=SIN(alpha)
|
||||
MOVE.L (A2,D2.L),D2 ; A2->pre_cosin, D2.L=COS(alpha)
|
||||
|
||||
MOVEQ.L #16,D6 ; Prepare shifts/assume not in range
|
||||
|
||||
MOVE.L D0,D4
|
||||
MULS.L D2,D4 ; D4=bh_xd * pre_cos[alpha]
|
||||
MOVE.L D1,D5
|
||||
MULS.L D3,D5 ; D5=bh_yd * pre_sin[alpha]
|
||||
SUB.L D5,D4 ; D4=bh_xd * pre_cos[alpha] - bh_yd * pre_sin[alpha]
|
||||
ASR.L D6,D4
|
||||
ADD.L bh_xc(PC),D4 ; D6=16, assume pixel not in range
|
||||
BLT.S bail_out_addr ; xs < 0: not in range
|
||||
CMP.W bh_in_w(PC),D4
|
||||
BGE.S bail_out_addr ; xs >= bh_in_w: not in range
|
||||
MOVE.L D4,A3 ; A3=bh_xs= (D4 >> 16)
|
||||
|
||||
MOVE.L D0,D4
|
||||
MULS.L D3,D4 ; D4=bh_xd * pre_sin[alpha]
|
||||
MOVE.L D1,D5
|
||||
MULS.L D2,D5 ; D5=bh_yd * pre_cos[alpha]
|
||||
ADD.L D5,D4 ; D4=bh_xd * pre_sin[alpha] + bh_yd * pre_cos[alpha]
|
||||
ASR.L D6,D4
|
||||
ADD.L bh_yc(PC),D4 ; D4.L=bh_ys
|
||||
BLT.S bail_out_addr ; ys < 0: not in range
|
||||
CMP.W bh_in_h(PC),D4
|
||||
BGE.S bail_out_addr ; ys >= bh_in_h: not in range
|
||||
MOVEQ.L #0,D6 ; pixel in range
|
||||
ENDM
|
||||
|
||||
; Macro for CPU 68030
|
||||
MACRO BH_COMPUTE_CPU bail_out_addr
|
||||
BH_COMP_1
|
||||
BH_COMP_2 bail_out_addr
|
||||
ENDM
|
||||
|
||||
; Macro for using FPU
|
||||
; What we do with FPU is to compute the square root of D1 which
|
||||
; Is then the distance to the back hole center instead of its square
|
||||
MACRO BH_COMPUTE_FPU bail_out_addr
|
||||
BH_COMP_1
|
||||
FMOVE.L D1,FP0
|
||||
FSQRT FP0
|
||||
FMOVE.L FP0,D1
|
||||
BH_COMP_2 bail_out_addr
|
||||
ENDM
|
||||
|
||||
; Init parameters valid for the entire call
|
||||
MACRO INIT_BHL
|
||||
MOVE.L pre_cosin,A2
|
||||
MOVE.L pre_loffset,A4 ; A4-->preoffset
|
||||
MOVE.L bh_rd2(PC),A5 ; A5=bh_rd2
|
||||
MOVE.L bh_xd(PC),A6 ; A6=bh_xd
|
||||
MOVE.W bh_out_w(PC),D7
|
||||
SUBQ.W #1,D7 ; For DBF
|
||||
ENDM
|
||||
|
||||
MACRO INIT_BHL_SYM
|
||||
MOVE.L pre_cosin,A2
|
||||
MOVE.L pre_loffset,A4 ; A4-->preoffset
|
||||
MOVE.L bh_rd2(PC),A5 ; A5=bh_rd2
|
||||
MOVE.L bh_xd(PC),A6 ; A6=bh_xd
|
||||
MOVE.W bh_out_w(PC),D7
|
||||
LSR.W #1,D7 ; loop to bh_out_w/2 counts
|
||||
ADD.W A6,D7 ; starting from bh_xd
|
||||
MOVE.W D7,last_xd
|
||||
ENDM
|
||||
|
||||
; Get pixel TC32 -->dest (Dx)
|
||||
; A4-->pre_loffset
|
||||
MACRO GET_TCPIXEL32 p,x,y,dest
|
||||
MOVE.L (A4,y.L*4),dest
|
||||
ADD.L x,dest
|
||||
MOVE.L (p,dest.L*4),dest
|
||||
ENDM
|
||||
|
||||
; Set pixel TC32 val(Dx) -->dest
|
||||
; A4-->pre_loffset
|
||||
; scratch_Dx scratch variable
|
||||
MACRO SET_TCPIXEL32 p,x,y,val,scratch_Dx
|
||||
MOVE.L (A4,y.L*4),scratch_Dx
|
||||
ADD.L x,scratch_Dx
|
||||
MOVE.L val,(p,scratch_Dx.L*4)
|
||||
ENDM
|
||||
|
||||
; Get pixel TC16 -->dest (Dx)
|
||||
; A4-->pre_loffset
|
||||
MACRO GET_TCPIXEL16 p,x,y,dest
|
||||
MOVE.L (A4,y.L*4),dest
|
||||
ADD.L x,dest
|
||||
MOVE.W (p,dest.L*2),dest
|
||||
ENDM
|
||||
|
||||
; Set pixel TC16 val(Dx) -->dest
|
||||
; A4-->pre_loffset
|
||||
; scratch_Dx scratch variable
|
||||
MACRO SET_TCPIXEL16 p,x,y,val,scratch_Dx
|
||||
MOVE.L (A4,y.L*4),scratch_Dx
|
||||
ADD.L x,scratch_Dx
|
||||
MOVE.W val,(p,scratch_Dx.L*2)
|
||||
ENDM
|
||||
|
||||
; Rotate 90
|
||||
; x,y,scratch_Dx : registers, y has to be Dx
|
||||
; #define R90(x,y) { long _x=x; x=-y; y=_x; }
|
||||
MACRO R90 x,y,scratch_Dx
|
||||
MOVE.L x,scratch_Dx
|
||||
NEG.L y
|
||||
MOVE.L y,x
|
||||
MOVE.L scratch_Dx,y
|
||||
ENDM
|
||||
|
||||
MACRO PIXINIMG x,y,w,h,bailout
|
||||
TST.W x
|
||||
BLT.S bailout
|
||||
TST.W y
|
||||
BLT.S bailout
|
||||
CMP.W w,x
|
||||
BGE.S bailout
|
||||
CMP.W h,y
|
||||
BGE.S bailout
|
||||
ENDM
|
||||
|
||||
; On sample file 00_1480ms.jpg, Aranym 32bit:
|
||||
; BHL32_68000 takes about 1450ms
|
||||
; BHL32_68030 takes about 740ms
|
||||
|
||||
; 68030 routine for True Color 32bit
|
||||
; BHL32_68030(short use_sym, void* in, void* out)
|
||||
; D0, A0 A1
|
||||
BHL32_68030:
|
||||
MOVEM.L D0-D7/A2-A6,-(SP) ; Save context
|
||||
|
||||
TST.W D0
|
||||
BNE BHL32_68030_sym
|
||||
|
||||
MOVEQ.L #0,D7
|
||||
MOVE.W bh_out_x(PC),D7
|
||||
LSL.L #2,D7
|
||||
ADD.L D7,A1 ; A1-->&out[bh_out_x]
|
||||
INIT_BHL
|
||||
bhl32_l030:
|
||||
BH_COMPUTE_CPU bhl32_tpir_030 ; -->D6=0:pixel in range
|
||||
bhl32_tpir_030:
|
||||
MOVEQ.L #-1,D0 ; Assume out of range
|
||||
TST.W D6
|
||||
BNE.S bhl32_setpix_030
|
||||
MOVE.L (A4,D4.L*4),D0 ; D4=bh_ys, D0=pre_loffset[bh_ys]
|
||||
ADD.L A3,D0 ; D0=pre_loffset[bh_ys] + bh_xs(A3)
|
||||
MOVE.L (A0,D0.L*4),D0 ; D0=in_ptr[pre_loffset[bh_ys] + bh_xs]
|
||||
bhl32_setpix_030:
|
||||
MOVE.L D0,(A1)+
|
||||
ADD.L #1,A6 ; bh_xd++
|
||||
DBF D7,bhl32_l030
|
||||
|
||||
MOVEM.L (SP)+,D0-D7/A2-A6 ; Restore context
|
||||
RTS
|
||||
|
||||
BHL32_68030_sym:
|
||||
INIT_BHL_SYM
|
||||
bhl32_l030_sym:
|
||||
BH_COMPUTE_CPU bhl32_tpir_030_sym ; -->D6=0:pixel in range
|
||||
bhl32_tpir_030_sym:
|
||||
MOVEQ.L #-1,D0 ; Assume out of range
|
||||
TST.W D6
|
||||
BNE.S bhl32_setpix_030_sym
|
||||
GET_TCPIXEL32 A0,A3,D4,D0 ; A0-->in_ptr, A3=bh_xs+bh_xc, D4=bh_ys+bh_yc
|
||||
; D0=GET_TCPIXEL(in_ptr, bh_xs+bh_xc, bh_ys+bh_yc)
|
||||
bhl32_setpix_030_sym:
|
||||
MOVE.L A6,-(SP) ; Save bh_xd
|
||||
MOVE.L bh_xc(PC),D2 ; D2=bh_xc
|
||||
MOVE.L bh_yc(PC),D3 ; D3=bh_yc
|
||||
ADD.L D2,A6 ; A6=bh_xd+bh_xc
|
||||
MOVE.L bh_yd(PC),D7
|
||||
ADD.L D3,D7 ; D7=bh_yd+bh_yc
|
||||
SET_TCPIXEL32 A1,A6,D7,D0,D5 ; SET_TCPIXEL(out_ptr, bh_xd+bh_xc, bh_yd+bh_yc, GET_TCPIXEL(in_ptr, bh_xs+bh_xc, bh_ys+bh_yc))
|
||||
|
||||
MOVEQ.L #2,D1 ; 3 loops, -1 for DBF
|
||||
deduc32_030:
|
||||
SUB.L D2,A3 ; We need now bh_xs(A3) and bh_ys(D4) relative to
|
||||
SUB.L D3,D4 ; Black Hole center to use R90
|
||||
SUB.L D2,A6 ; We need now bh_xd(A6) and bh_yd(D7) relative to
|
||||
SUB.L D3,D7 ; Black Hole center to use R90
|
||||
|
||||
R90 A6,D7,D0 ; Rotate (xd,yd) by PI/4
|
||||
R90 A3,D4,D0 ; Rotate (xs,ys) by PI/4
|
||||
|
||||
ADD.L D2,A3 ; Now we need coords in image raster
|
||||
ADD.L D3,D4
|
||||
ADD.L D2,A6
|
||||
ADD.L D3,D7
|
||||
|
||||
PIXINIMG A6,D7,bh_in_w(PC),bh_in_h(PC),dnotinimg32_030 ; Check if pixel in dest is within bounds
|
||||
MOVEQ.L #-1,D0 ; Assume out of range
|
||||
PIXINIMG A3,D4,bh_in_w(PC),bh_in_h(PC),plotdest32_030 ; Check if pixel in src is within bounds
|
||||
GET_TCPIXEL32 A0,A3,D4,D0 ; A0-->in_ptr, A3=bh_xs+bh_xc, D4=bh_ys+bh_yc
|
||||
; D0=GET_TCPIXEL(in_ptr, bh_xs+bh_xc, bh_ys+bh_yc)
|
||||
plotdest32_030:
|
||||
SET_TCPIXEL32 A1,A6,D7,D0,D5 ; SET_TCPIXEL(out_ptr, bh_xd+bh_xc, bh_yd+bh_yc, GET_TCPIXEL(in_ptr, bh_xs+bh_xc, bh_ys+bh_yc))
|
||||
dnotinimg32_030:
|
||||
DBF D1,deduc32_030
|
||||
|
||||
MOVE.L (SP)+,A6 ; Restore bh_xd
|
||||
ADD.L #1,A6 ; bh_xd++
|
||||
CMP.W last_xd(PC),A6
|
||||
BLE bhl32_l030_sym
|
||||
|
||||
MOVEM.L (SP)+,D0-D7/A2-A6 ; Restore context
|
||||
RTS
|
||||
|
||||
; 68030 routine for True Color 16bit
|
||||
; BHL16_68030(short use_sym, void* in, void* out)
|
||||
; D0, A0 A1
|
||||
BHL16_68030:
|
||||
MOVEM.L D0-D7/A2-A6,-(SP) ; Save context
|
||||
|
||||
TST.W D0
|
||||
BNE BHL16_68030_sym
|
||||
|
||||
MOVEQ.L #0,D7
|
||||
MOVE.W bh_out_x(PC),D7
|
||||
ADD.L D7,D7
|
||||
ADD.L D7,A1 ; A1-->&out[bh_out_x]
|
||||
INIT_BHL
|
||||
bhl16_l030:
|
||||
BH_COMPUTE_CPU bhl16_tpir_030 ; -->D6=0:pixel in range
|
||||
bhl16_tpir_030:
|
||||
MOVEQ.L #-1,D0 ; Assume out of range
|
||||
TST.W D6
|
||||
BNE.S bhl16_setpix_030
|
||||
MOVE.L (A4,D4.L*4),D0 ; D4=bh_ys, D0=pre_loffset[bh_ys]
|
||||
ADD.L A3,D0 ; D0=pre_loffset[bh_ys] + bh_xs(A3)
|
||||
MOVE.W (A0,D0.L*2),D0 ; D0=in_ptr[pre_loffset[bh_ys] + bh_xs]
|
||||
bhl16_setpix_030:
|
||||
MOVE.W D0,(A1)+
|
||||
ADD.L #1,A6 ; bh_xd++
|
||||
DBF D7,bhl16_l030
|
||||
|
||||
MOVEM.L (SP)+,D0-D7/A2-A6 ; Restore context
|
||||
RTS
|
||||
|
||||
BHL16_68030_sym:
|
||||
INIT_BHL_SYM
|
||||
bhl16_l030_sym:
|
||||
BH_COMPUTE_CPU bhl16_tpir_030_sym ; -->D6=0:pixel in range
|
||||
bhl16_tpir_030_sym:
|
||||
MOVEQ.L #-1,D0 ; Assume out of range
|
||||
TST.W D6
|
||||
BNE.S bhl16_setpix_030_sym
|
||||
GET_TCPIXEL16 A0,A3,D4,D0 ; A0-->in_ptr, A3=bh_xs+bh_xc, D4=bh_ys+bh_yc
|
||||
; D0=GET_TCPIXEL(in_ptr, bh_xs+bh_xc, bh_ys+bh_yc)
|
||||
bhl16_setpix_030_sym:
|
||||
MOVE.L A6,-(SP) ; Save bh_xd
|
||||
MOVE.L bh_xc(PC),D2 ; D2=bh_xc
|
||||
MOVE.L bh_yc(PC),D3 ; D3=bh_yc
|
||||
ADD.L D2,A6 ; A6=bh_xd+bh_xc
|
||||
MOVE.L bh_yd(PC),D7
|
||||
ADD.L D3,D7 ; D7=bh_yd+bh_yc
|
||||
SET_TCPIXEL16 A1,A6,D7,D0,D5 ; SET_TCPIXEL(out_ptr, bh_xd+bh_xc, bh_yd+bh_yc, GET_TCPIXEL(in_ptr, bh_xs+bh_xc, bh_ys+bh_yc))
|
||||
|
||||
MOVEQ.L #2,D1 ; 3 loops, -1 for DBF
|
||||
deduc16_030:
|
||||
SUB.L D2,A3 ; We need now bh_xs(A3) and bh_ys(D4) relative to
|
||||
SUB.L D3,D4 ; Black Hole center to use R90
|
||||
SUB.L D2,A6 ; We need now bh_xd(A6) and bh_yd(D7) relative to
|
||||
SUB.L D3,D7 ; Black Hole center to use R90
|
||||
|
||||
R90 A6,D7,D0 ; Rotate (xd,yd) by PI/4
|
||||
R90 A3,D4,D0 ; Rotate (xs,ys) by PI/4
|
||||
|
||||
ADD.L D2,A3 ; Now we need coords in image raster
|
||||
ADD.L D3,D4
|
||||
ADD.L D2,A6
|
||||
ADD.L D3,D7
|
||||
|
||||
PIXINIMG A6,D7,bh_in_w(PC),bh_in_h(PC),dnotinimg16_030 ; Check if pixel in dest is within bounds
|
||||
MOVEQ.L #-1,D0 ; Assume out of range
|
||||
PIXINIMG A3,D4,bh_in_w(PC),bh_in_h(PC),plotdest16_030 ; Check if pixel in src is within bounds
|
||||
GET_TCPIXEL16 A0,A3,D4,D0 ; A0-->in_ptr, A3=bh_xs+bh_xc, D4=bh_ys+bh_yc
|
||||
; D0=GET_TCPIXEL(in_ptr, bh_xs+bh_xc, bh_ys+bh_yc)
|
||||
plotdest16_030:
|
||||
SET_TCPIXEL16 A1,A6,D7,D0,D5 ; SET_TCPIXEL(out_ptr, bh_xd+bh_xc, bh_yd+bh_yc, GET_TCPIXEL(in_ptr, bh_xs+bh_xc, bh_ys+bh_yc))
|
||||
dnotinimg16_030:
|
||||
DBF D1,deduc16_030
|
||||
|
||||
MOVE.L (SP)+,A6 ; Restore bh_xd
|
||||
ADD.L #1,A6 ; bh_xd++
|
||||
CMP.W last_xd(PC),A6
|
||||
BLE bhl16_l030_sym
|
||||
|
||||
MOVEM.L (SP)+,D0-D7/A2-A6 ; Restore context
|
||||
RTS
|
||||
|
||||
; 68030 routine for bitplances images, converted to indexes
|
||||
; BHLInd_68030(short use_sym, void* in, void* out)
|
||||
; D0, A0 A1
|
||||
BHLInd_68030:
|
||||
MOVEM.L D0-D7/A2-A6,-(SP) ; Save context
|
||||
|
||||
INIT_BHL
|
||||
bhlind_l030:
|
||||
BH_COMPUTE_CPU bhlind_tpir_030 ; -->D6=0:pixel in range
|
||||
bhlind_tpir_030:
|
||||
MOVEQ.L #-1,D0 ; Assume out of range
|
||||
TST.W D6
|
||||
BNE.S bhlind_setpix_030
|
||||
MOVE.L (A4,D4.L*4),D0 ; D4=bh_ys, D0=pre_loffset[bh_ys]
|
||||
ADD.L A3,D0 ; D0=pre_loffset[bh_ys] + bh_xs(A3)
|
||||
MOVE.B (A0,D0.L),D0 ; D0=in_ptr[pre_loffset[bh_ys] + bh_xs]
|
||||
bhlind_setpix_030:
|
||||
MOVE.B D0,(A1)+
|
||||
ADD.L #1,A6 ; bh_xd++
|
||||
DBF D7,bhlind_l030
|
||||
|
||||
MOVEM.L (SP)+,D0-D7/A2-A6 ; Restore context
|
||||
RTS
|
||||
|
||||
.EVEN
|
||||
bh_xd:
|
||||
DC.L 0
|
||||
bh_yd:
|
||||
DC.L 0
|
||||
bh_rd2:
|
||||
DC.L 0
|
||||
bh_xs:
|
||||
DC.L 0
|
||||
bh_ys:
|
||||
DC.L 0
|
||||
bh_ref:
|
||||
DC.L 0
|
||||
bh_xc:
|
||||
DC.L 0
|
||||
bh_yc:
|
||||
DC.L 0
|
||||
bh_out_w:
|
||||
DC.W 0
|
||||
bh_out_h:
|
||||
DC.W 0
|
||||
bh_in_w:
|
||||
DC.W 0
|
||||
bh_in_h:
|
||||
DC.W 0
|
||||
bh_out_x:
|
||||
DC.W 0
|
||||
bh_out_y:
|
||||
DC.W 0
|
||||
last_xd:
|
||||
DC.W 0
|
||||
|
||||
; 68030/FPU routine for True Color 32bit
|
||||
; BHL32_F68030(short use_sym, void* in, void* out)
|
||||
; D0, A0 A1
|
||||
;BHL32_F68030:
|
||||
; MOVEM.L D0-D7/A2-A6,-(SP) ; Save context
|
||||
; FMOVE.X FP0,-(SP)
|
||||
;
|
||||
; INIT_BHL
|
||||
;bhl32_lf030:
|
||||
; BH_COMPUTE_FPU bhl32_tpir_f030 ; -->D6=0:pixel in range
|
||||
;bhl32_tpir_f030:
|
||||
; MOVEQ.L #-1,D0 ; Assume out of range
|
||||
; TST.W D6
|
||||
; BNE.S bhl32_setpix_f030
|
||||
; MOVE.L (A4,D4.L*4),D0 ; D4=bh_ys, D0=pre_loffset[bh_ys]
|
||||
; ADD.L A3,D0 ; D0=pre_loffset[bh_ys] + bh_xs(A3)
|
||||
; MOVE.L (A0,D0.L*4),D0 ; D0=in_ptr[pre_loffset[bh_ys] + bh_xs]
|
||||
;bhl32_setpix_f030:
|
||||
; MOVE.L D0,(A1)+
|
||||
; ADD.L #1,A6 ; bh_xd++
|
||||
; DBF D7,bhl32_lf030
|
||||
;
|
||||
; FMOVE.X (SP)+,FP0
|
||||
; MOVEM.L (SP)+,D0-D7/A2-A6 ; Restore context
|
||||
; RTS
|
||||
|
||||
BHL32_F68030:
|
||||
MOVEM.L D0-D7/A2-A6,-(SP) ; Save context
|
||||
FMOVE.X FP0,-(SP)
|
||||
|
||||
TST.W D0
|
||||
BNE BHL32_F68030_sym
|
||||
|
||||
MOVEQ.L #0,D7
|
||||
MOVE.W bh_out_x(PC),D7
|
||||
LSL.L #2,D7
|
||||
ADD.L D7,A1 ; A1-->&out[bh_out_x]
|
||||
INIT_BHL
|
||||
bhl32_lf030:
|
||||
BH_COMPUTE_FPU bhl32_tpir_f030 ; -->D6=0:pixel in range
|
||||
bhl32_tpir_f030:
|
||||
MOVEQ.L #-1,D0 ; Assume out of range
|
||||
TST.W D6
|
||||
BNE.S bhl32_setpix_f030
|
||||
MOVE.L (A4,D4.L*4),D0 ; D4=bh_ys, D0=pre_loffset[bh_ys]
|
||||
ADD.L A3,D0 ; D0=pre_loffset[bh_ys] + bh_xs(A3)
|
||||
MOVE.L (A0,D0.L*4),D0 ; D0=in_ptr[pre_loffset[bh_ys] + bh_xs]
|
||||
bhl32_setpix_f030:
|
||||
MOVE.L D0,(A1)+
|
||||
ADD.L #1,A6 ; bh_xd++
|
||||
DBF D7,bhl32_lf030
|
||||
|
||||
FMOVE.X (SP)+,FP0
|
||||
MOVEM.L (SP)+,D0-D7/A2-A6 ; Restore context
|
||||
RTS
|
||||
|
||||
BHL32_F68030_sym:
|
||||
INIT_BHL_SYM
|
||||
bhl32_lf030_sym:
|
||||
BH_COMPUTE_FPU bhl32_tpir_f030_sym ; -->D6=0:pixel in range
|
||||
bhl32_tpir_f030_sym:
|
||||
MOVEQ.L #-1,D0 ; Assume out of range
|
||||
TST.W D6
|
||||
BNE.S bhl32_setpix_f030_sym
|
||||
GET_TCPIXEL32 A0,A3,D4,D0 ; A0-->in_ptr, A3=bh_xs+bh_xc, D4=bh_ys+bh_yc
|
||||
; D0=GET_TCPIXEL(in_ptr, bh_xs+bh_xc, bh_ys+bh_yc)
|
||||
bhl32_setpix_f030_sym:
|
||||
MOVE.L A6,-(SP) ; Save bh_xd
|
||||
MOVE.L bh_xc(PC),D2 ; D2=bh_xc
|
||||
MOVE.L bh_yc(PC),D3 ; D3=bh_yc
|
||||
ADD.L D2,A6 ; A6=bh_xd+bh_xc
|
||||
MOVE.L bh_yd(PC),D7
|
||||
ADD.L D3,D7 ; D7=bh_yd+bh_yc
|
||||
SET_TCPIXEL32 A1,A6,D7,D0,D5 ; SET_TCPIXEL(out_ptr, bh_xd+bh_xc, bh_yd+bh_yc, GET_TCPIXEL(in_ptr, bh_xs+bh_xc, bh_ys+bh_yc))
|
||||
|
||||
MOVEQ.L #2,D1 ; 3 loops, -1 for DBF
|
||||
deduc32_f030:
|
||||
SUB.L D2,A3 ; We need now bh_xs(A3) and bh_ys(D4) relative to
|
||||
SUB.L D3,D4 ; Black Hole center to use R90
|
||||
SUB.L D2,A6 ; We need now bh_xd(A6) and bh_yd(D7) relative to
|
||||
SUB.L D3,D7 ; Black Hole center to use R90
|
||||
|
||||
R90 A6,D7,D0 ; Rotate (xd,yd) by PI/4
|
||||
R90 A3,D4,D0 ; Rotate (xs,ys) by PI/4
|
||||
|
||||
ADD.L D2,A3 ; Now we need coords in image raster
|
||||
ADD.L D3,D4
|
||||
ADD.L D2,A6
|
||||
ADD.L D3,D7
|
||||
|
||||
PIXINIMG A6,D7,bh_in_w(PC),bh_in_h(PC),dnotinimg32_f030 ; Check if pixel in dest is within bounds
|
||||
MOVEQ.L #-1,D0 ; Assume out of range
|
||||
PIXINIMG A3,D4,bh_in_w(PC),bh_in_h(PC),plotdest32_f030 ; Check if pixel in src is within bounds
|
||||
GET_TCPIXEL32 A0,A3,D4,D0 ; A0-->in_ptr, A3=bh_xs+bh_xc, D4=bh_ys+bh_yc
|
||||
; D0=GET_TCPIXEL(in_ptr, bh_xs+bh_xc, bh_ys+bh_yc)
|
||||
plotdest32_f030:
|
||||
SET_TCPIXEL32 A1,A6,D7,D0,D5 ; SET_TCPIXEL(out_ptr, bh_xd+bh_xc, bh_yd+bh_yc, GET_TCPIXEL(in_ptr, bh_xs+bh_xc, bh_ys+bh_yc))
|
||||
dnotinimg32_f030:
|
||||
DBF D1,deduc32_f030
|
||||
|
||||
MOVE.L (SP)+,A6 ; Restore bh_xd
|
||||
ADD.L #1,A6 ; bh_xd++
|
||||
CMP.W last_xd(PC),A6
|
||||
BLE bhl32_lf030_sym
|
||||
|
||||
FMOVE.X (SP)+,FP0
|
||||
MOVEM.L (SP)+,D0-D7/A2-A6 ; Restore context
|
||||
RTS
|
||||
|
||||
BHL16_F68030:
|
||||
MOVEM.L D0-D7/A2-A6,-(SP) ; Save context
|
||||
FMOVE.X FP0,-(SP)
|
||||
|
||||
TST.W D0
|
||||
BNE BHL16_f68030_sym
|
||||
|
||||
MOVEQ.L #0,D7
|
||||
MOVE.W bh_out_x(PC),D7
|
||||
ADD.L D7,D7
|
||||
ADD.L D7,A1 ; A1-->&out[bh_out_x]
|
||||
INIT_BHL
|
||||
bhl16_lf030:
|
||||
BH_COMPUTE_FPU bhl16_tpir_f030 ; -->D6=0:pixel in range
|
||||
bhl16_tpir_f030:
|
||||
MOVEQ.L #-1,D0 ; Assume out of range
|
||||
TST.W D6
|
||||
BNE.S bhl16_setpix_f030
|
||||
MOVE.L (A4,D4.L*4),D0 ; D4=bh_ys, D0=pre_loffset[bh_ys]
|
||||
ADD.L A3,D0 ; D0=pre_loffset[bh_ys] + bh_xs(A3)
|
||||
MOVE.W (A0,D0.L*2),D0 ; D0=in_ptr[pre_loffset[bh_ys] + bh_xs]
|
||||
bhl16_setpix_f030:
|
||||
MOVE.W D0,(A1)+
|
||||
ADD.L #1,A6 ; bh_xd++
|
||||
DBF D7,bhl16_lf030
|
||||
|
||||
FMOVE.X (SP)+,FP0
|
||||
MOVEM.L (SP)+,D0-D7/A2-A6 ; Restore context
|
||||
RTS
|
||||
|
||||
BHL16_f68030_sym:
|
||||
INIT_BHL_SYM
|
||||
bhl16_lf030_sym:
|
||||
BH_COMPUTE_FPU bhl16_tpir_f030_sym ; -->D6=0:pixel in range
|
||||
bhl16_tpir_f030_sym:
|
||||
MOVEQ.L #-1,D0 ; Assume out of range
|
||||
TST.W D6
|
||||
BNE.S bhl16_setpix_f030_sym
|
||||
GET_TCPIXEL16 A0,A3,D4,D0 ; A0-->in_ptr, A3=bh_xs+bh_xc, D4=bh_ys+bh_yc
|
||||
; D0=GET_TCPIXEL(in_ptr, bh_xs+bh_xc, bh_ys+bh_yc)
|
||||
bhl16_setpix_f030_sym:
|
||||
MOVE.L A6,-(SP) ; Save bh_xd
|
||||
MOVE.L bh_xc(PC),D2 ; D2=bh_xc
|
||||
MOVE.L bh_yc(PC),D3 ; D3=bh_yc
|
||||
ADD.L D2,A6 ; A6=bh_xd+bh_xc
|
||||
MOVE.L bh_yd(PC),D7
|
||||
ADD.L D3,D7 ; D7=bh_yd+bh_yc
|
||||
SET_TCPIXEL16 A1,A6,D7,D0,D5 ; SET_TCPIXEL(out_ptr, bh_xd+bh_xc, bh_yd+bh_yc, GET_TCPIXEL(in_ptr, bh_xs+bh_xc, bh_ys+bh_yc))
|
||||
|
||||
MOVEQ.L #2,D1 ; 3 loops, -1 for DBF
|
||||
deduc16_f030:
|
||||
SUB.L D2,A3 ; We need now bh_xs(A3) and bh_ys(D4) relative to
|
||||
SUB.L D3,D4 ; Black Hole center to use R90
|
||||
SUB.L D2,A6 ; We need now bh_xd(A6) and bh_yd(D7) relative to
|
||||
SUB.L D3,D7 ; Black Hole center to use R90
|
||||
|
||||
R90 A6,D7,D0 ; Rotate (xd,yd) by PI/4
|
||||
R90 A3,D4,D0 ; Rotate (xs,ys) by PI/4
|
||||
|
||||
ADD.L D2,A3 ; Now we need coords in image raster
|
||||
ADD.L D3,D4
|
||||
ADD.L D2,A6
|
||||
ADD.L D3,D7
|
||||
|
||||
PIXINIMG A6,D7,bh_in_w(PC),bh_in_h(PC),dnotinimg16_f030 ; Check if pixel in dest is within bounds
|
||||
MOVEQ.L #-1,D0 ; Assume out of range
|
||||
PIXINIMG A3,D4,bh_in_w(PC),bh_in_h(PC),plotdest16_f030 ; Check if pixel in src is within bounds
|
||||
GET_TCPIXEL16 A0,A3,D4,D0 ; A0-->in_ptr, A3=bh_xs+bh_xc, D4=bh_ys+bh_yc
|
||||
; D0=GET_TCPIXEL(in_ptr, bh_xs+bh_xc, bh_ys+bh_yc)
|
||||
plotdest16_f030:
|
||||
SET_TCPIXEL16 A1,A6,D7,D0,D5 ; SET_TCPIXEL(out_ptr, bh_xd+bh_xc, bh_yd+bh_yc, GET_TCPIXEL(in_ptr, bh_xs+bh_xc, bh_ys+bh_yc))
|
||||
dnotinimg16_f030:
|
||||
DBF D1,deduc16_f030
|
||||
|
||||
MOVE.L (SP)+,A6 ; Restore bh_xd
|
||||
ADD.L #1,A6 ; bh_xd++
|
||||
CMP.W last_xd(PC),A6
|
||||
BLE bhl16_lf030_sym
|
||||
|
||||
FMOVE.X (SP)+,FP0
|
||||
MOVEM.L (SP)+,D0-D7/A2-A6 ; Restore context
|
||||
RTS
|
||||
|
||||
; 68030/FPU routine for bitplances images, converted to indexes
|
||||
; BHLInd_F68030(short use_sym, void* in, void* out)
|
||||
; D0, A0 A1
|
||||
BHLInd_F68030:
|
||||
MOVEM.L D0-D7/A2-A6,-(SP) ; Save context
|
||||
FMOVE.X FP0,-(SP)
|
||||
|
||||
INIT_BHL
|
||||
bhlInd_lf030:
|
||||
BH_COMPUTE_FPU bhlInd_tpir_f030 ; -->D6=0:pixel in range
|
||||
bhlInd_tpir_f030:
|
||||
MOVEQ.L #-1,D0 ; Assume out of range
|
||||
TST.W D6
|
||||
BNE.S bhlInd_setpix_f030
|
||||
MOVE.L (A4,D4.L*4),D0 ; D4=bh_ys, D0=pre_loffset[bh_ys]
|
||||
ADD.L A3,D0 ; D0=pre_loffset[bh_ys] + bh_xs
|
||||
MOVE.B (A0,D0.L),D0 ; D0=in_ptr[pre_loffset[bh_ys] + bh_xs]
|
||||
bhlInd_setpix_f030:
|
||||
MOVE.B D0,(A1)+
|
||||
ADD.L #1,A6 ; bh_xd++
|
||||
DBF D7,bhlInd_lf030
|
||||
|
||||
FMOVE.X (SP)+,FP0
|
||||
MOVEM.L (SP)+,D0-D7/A2-A6 ; Restore context
|
||||
RTS
|
||||
|
||||
|
||||
; Pre-calculation of cosinus/sinus table using FPU
|
||||
; void lcosin_fpu(long i, long* pcs)
|
||||
; D0 A0
|
||||
; double angle = i*ANGLE_ADD ;
|
||||
; pcs[0] = 65536.0 * cos( angle ) ;
|
||||
; pcs[1] = 65536.0 * sin( angle ) ;
|
||||
lcosin_fpu:
|
||||
FMOVEM.X FP0-FP2,-(SP)
|
||||
|
||||
FMOVE D0,FP0
|
||||
; 3.8349519697141030742952189737299e-4=M_PI/2.0/(double)QUARTER
|
||||
; For some reason, I did not manage to use EQU with floating point constants
|
||||
FMUL.X #3.8349519697141030742952189737299e-4,FP0
|
||||
FSINCOS.X FP0,FP1:FP2
|
||||
FMUL.X #65536.0,FP1
|
||||
FMUL.X #65536.0,FP2
|
||||
FMOVE.L FP1,(A0)+
|
||||
FMOVE.L FP2,(A0)
|
||||
|
||||
FMOVEM.X (SP)+,FP0-FP2
|
||||
RTS
|
||||
86
tools/vision/ldv/src/bhole/perf_r51.txt
Normal file
86
tools/vision/ldv/src/bhole/perf_r51.txt
Normal file
@@ -0,0 +1,86 @@
|
||||
68000, TC32, 2016x1508
|
||||
MagicC, SYM:
|
||||
25/02/18 18:31:38 [INFO] MayAddRect (0,0,254,0)
|
||||
25/02/18 18:31:38 [INFO] MayAddRect (254,0,1508,0)
|
||||
25/02/18 18:31:38 [INFO] MayAddRect (1762,0,254,0)
|
||||
25/02/18 18:31:38 [INFO] MayAddRect (0,0,254,1508)
|
||||
25/02/18 18:31:38 [INFO] Adding R4(0,0,254,1508)
|
||||
25/02/18 18:31:38 [INFO] MayAddRect (1762,0,254,1508)
|
||||
25/02/18 18:31:38 [INFO] Adding R5(1762,0,254,1508)
|
||||
25/02/18 18:31:38 [INFO] MayAddRect (0,1508,254,0)
|
||||
25/02/18 18:31:38 [INFO] MayAddRect (254,1508,1508,0)
|
||||
25/02/18 18:31:38 [INFO] MayAddRect (1762,1508,254,0)
|
||||
25/02/18 18:31:38 [INFO] 100 being the time without using symmetry, using symmetry would be 43
|
||||
25/02/18 18:31:38 [INFO] Image source : (0,0,+2016,+1508); 3040128 pixels
|
||||
25/02/18 18:31:38 [INFO] Symmetry zone : (254,0,+1508,+1508), index:0
|
||||
25/02/18 18:31:40 [INFO] Run zone 0: (254,0,+1508,+1508), use_sym=1, 2274064 pixels, done in 850ms, 2675 Kpixels/s
|
||||
25/02/18 18:31:40 [INFO] Run zone 1: (0,0,+254,+1508), use_sym=0, 383032 pixels, done in 295ms, 1298 Kpixels/s
|
||||
25/02/18 18:31:40 [INFO] Run zone 2: (1762,0,+254,+1508), use_sym=0, 383032 pixels, done in 295ms, 1298 Kpixels/s
|
||||
25/02/18 18:31:40 [INFO] 3040128 pixels computed or deduced
|
||||
25/02/18 18:31:40 [PERF] LDV Run took 1445ms
|
||||
|
||||
MagicC, NO SYM:
|
||||
25/02/18 18:36:52 [INFO] 100 being the time without using symmetry, using symmetry would be 43
|
||||
25/02/18 18:36:52 [INFO] Image source : (0,0,+2016,+1508); 3040128 pixels
|
||||
25/02/18 18:36:52 [INFO] Symmetry zone : (0,0,+2016,+1508), index:-1
|
||||
25/02/18 18:36:54 [INFO] Run zone 0: (0,0,+2016,+1508), use_sym=0, 3040128 pixels, done in 2270ms, 1339 Kpixels/s
|
||||
25/02/18 18:36:54 [INFO] 3040128 pixels computed or deduced
|
||||
25/02/18 18:36:54 [PERF] LDV Run took 2275ms
|
||||
|
||||
Aranym, NO SYM:
|
||||
25/02/18 18:38:54 [INFO] 100 being the time without using symmetry, using symmetry would be 43
|
||||
25/02/18 18:38:54 [INFO] Image source : (0,0,+2016,+1508); 3040128 pixels
|
||||
25/02/18 18:38:54 [INFO] Symmetry zone : (0,0,+2016,+1508), index:-1
|
||||
25/02/18 18:38:54 [INFO] Run zone 0: (0,0,+2016,+1508), use_sym=0, 3040128 pixels, done in 1710ms, 1777 Kpixels/s
|
||||
25/02/18 18:38:54 [INFO] 3040128 pixels computed or deduced
|
||||
25/02/18 18:38:54 [PERF] LDV Run took 1710ms
|
||||
|
||||
Aranym, SYM:
|
||||
25/02/18 18:41:12 [INFO] MayAddRect (0,0,254,0)
|
||||
25/02/18 18:41:12 [INFO] MayAddRect (254,0,1508,0)
|
||||
25/02/18 18:41:12 [INFO] MayAddRect (1762,0,254,0)
|
||||
25/02/18 18:41:12 [INFO] MayAddRect (0,0,254,1508)
|
||||
25/02/18 18:41:12 [INFO] Adding R4(0,0,254,1508)
|
||||
25/02/18 18:41:12 [INFO] MayAddRect (1762,0,254,1508)
|
||||
25/02/18 18:41:12 [INFO] Adding R5(1762,0,254,1508)
|
||||
25/02/18 18:41:12 [INFO] MayAddRect (0,1508,254,0)
|
||||
25/02/18 18:41:12 [INFO] MayAddRect (254,1508,1508,0)
|
||||
25/02/18 18:41:12 [INFO] MayAddRect (1762,1508,254,0)
|
||||
25/02/18 18:41:12 [INFO] 100 being the time without using symmetry, using symmetry would be 43
|
||||
25/02/18 18:41:12 [INFO] Image source : (0,0,+2016,+1508); 3040128 pixels
|
||||
25/02/18 18:41:12 [INFO] Symmetry zone : (254,0,+1508,+1508), index:0
|
||||
25/02/18 18:41:14 [INFO] Run zone 0: (254,0,+1508,+1508), use_sym=1, 2274064 pixels, done in 500ms, 4548 Kpixels/s
|
||||
25/02/18 18:41:14 [INFO] Run zone 1: (0,0,+254,+1508), use_sym=0, 383032 pixels, done in 900ms, 425 Kpixels/s
|
||||
25/02/18 18:41:14 [INFO] Run zone 2: (1762,0,+254,+1508), use_sym=0, 383032 pixels, done in 890ms, 430 Kpixels/s
|
||||
25/02/18 18:41:14 [INFO] 3040128 pixels computed or deduced
|
||||
25/02/18 18:41:14 [PERF] LDV Run took 2300ms
|
||||
|
||||
HATARI, Falcon 32Mhz, TC16, SYM:
|
||||
25/02/18 19:07:02 [DEBUG] Running LDV with w=1008, h=754, P0=10, P1=50, P2=50
|
||||
25/02/18 19:07:04 [INFO] MayAddRect (0,0,127,0)
|
||||
25/02/18 19:07:04 [INFO] MayAddRect (127,0,754,0)
|
||||
25/02/18 19:07:04 [INFO] MayAddRect (881,0,127,0)
|
||||
25/02/18 19:07:04 [INFO] MayAddRect (0,0,127,754)
|
||||
25/02/18 19:07:04 [INFO] Adding R4(0,0,127,754)
|
||||
25/02/18 19:07:04 [INFO] MayAddRect (881,0,127,754)
|
||||
25/02/18 19:07:04 [INFO] Adding R5(881,0,127,754)
|
||||
25/02/18 19:07:04 [INFO] MayAddRect (0,754,127,0)
|
||||
25/02/18 19:07:04 [INFO] MayAddRect (127,754,754,0)
|
||||
25/02/18 19:07:04 [INFO] MayAddRect (881,754,127,0)
|
||||
25/02/18 19:07:04 [INFO] 100 being the time without using symmetry, using symmetry would be 43
|
||||
25/02/18 19:07:04 [INFO] Image source : (0,0,+1008,+754); 760032 pixels
|
||||
25/02/18 19:07:04 [INFO] Symmetry zone : (127,0,+754,+754), index:0
|
||||
25/02/18 19:07:20 [INFO] Run zone 0: (127,0,+754,+754), use_sym=1, 568516 pixels, done in 17260ms, 32 Kpixels/s
|
||||
25/02/18 19:07:26 [INFO] Run zone 1: (0,0,+127,+754), use_sym=0, 95758 pixels, done in 6350ms, 15 Kpixels/s
|
||||
25/02/18 19:07:34 [INFO] Run zone 2: (881,0,+127,+754), use_sym=0, 95758 pixels, done in 6400ms, 14 Kpixels/s
|
||||
25/02/18 19:07:34 [INFO] 760032 pixels computed or deduced
|
||||
25/02/18 19:07:34 [PERF] LDV Run took 30030ms
|
||||
|
||||
HATARI, Falcon 32Mhz, TC16, NO SYM:
|
||||
25/02/18 19:11:00 [DEBUG] Running LDV with w=1008, h=754, P0=10, P1=50, P2=50
|
||||
25/02/18 19:11:00 [INFO] 100 being the time without using symmetry, using symmetry would be 43
|
||||
25/02/18 19:11:00 [INFO] Image source : (0,0,+1008,+754); 760032 pixels
|
||||
25/02/18 19:11:00 [INFO] Symmetry zone : (0,0,+1008,+754), index:-1
|
||||
25/02/18 19:11:46 [INFO] Run zone 0: (0,0,+1008,+754), use_sym=0, 760032 pixels, done in 46625ms, 16 Kpixels/s
|
||||
25/02/18 19:11:46 [INFO] 760032 pixels computed or deduced
|
||||
25/02/18 19:11:46 [PERF] LDV Run took 46901ms
|
||||
278
tools/vision/ldv/src/bw/bw.c
Normal file
278
tools/vision/ldv/src/bw/bw.c
Normal file
@@ -0,0 +1,278 @@
|
||||
/*
|
||||
*
|
||||
*
|
||||
* Version PureC / Gcc
|
||||
*/
|
||||
|
||||
#define PCGEMLIB 1 /* mettre 1 si les utilisateurs de Pure C
|
||||
* utilise les librairies GEM Pure C */
|
||||
|
||||
/* Fichiers headers */
|
||||
|
||||
#include <portab.h>
|
||||
#if PCGEMLIB
|
||||
#include <aes.h>
|
||||
#include <vdi.h>
|
||||
#else
|
||||
#include <aesbind.h>
|
||||
#include <vdibind.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "..\..\ldg.h"
|
||||
#include "..\..\vapi.h"
|
||||
#include "..\..\ldv.h"
|
||||
#include "..\..\mt_aes.h"
|
||||
|
||||
/* Prototypages */
|
||||
LDV_INFOS * cdecl GetLDVCapabilities(VAPI *vapi) ;
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
LDV_STATUS cdecl Preview(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
|
||||
void OnClose(void) ;
|
||||
|
||||
/* Variables globales */
|
||||
PROC Proc[] = {
|
||||
"GetLDVCapabilities", "Capacit<EFBFBD>s du LDV", (void *)GetLDVCapabilities,
|
||||
"PreRun", "Init du Run", (void *)PreRun,
|
||||
"Run", "Fonction du LDV", (void *)Run,
|
||||
"Preview", "Pre-Visu", (void *)Preview,
|
||||
} ;
|
||||
|
||||
char Info[] = "LDV";
|
||||
|
||||
LDGLIB Ldg[] = {
|
||||
0x0104, /* version de la lib, recommand<6E> */
|
||||
4, /* nombre de fonction dans la lib */
|
||||
Proc, /* Pointeurs vers nos fonctions */
|
||||
Info, /* Information sur la lib */
|
||||
0x0, /* Flags de la lib, obligatoire */
|
||||
OnClose, /* Fermeture, liberation de VDIHandle */
|
||||
};
|
||||
|
||||
#define BP_CAPS (LDVF_SPECFORMAT | LDVF_OPINPLACE | LDVF_SUPPORTPREVIEW | LDVF_AFFECTPALETTE)
|
||||
#define TC_CAPS (LDVF_SPECFORMAT | LDVF_OPINPLACE | LDVF_SUPPORTPREVIEW | LDVF_SUPPORTPROG | LDVF_SUPPORTCANCEL)
|
||||
|
||||
LDV_INFOS LdvInfos = {
|
||||
(short) sizeof(LDV_INFOS), /* Taille de cette structure */
|
||||
TLDV_MODIFYIMG, /* Type du LDV */
|
||||
"Jean Lusetti/Olivier Landemarre", /* Auteurs */
|
||||
{
|
||||
{ 1, 1, BP_CAPS }, /* Capacites pour 1 plan */
|
||||
{ 2, 2, BP_CAPS }, /* Capacites pour 2 plans */
|
||||
{ 4, 4, BP_CAPS }, /* Capacites pour 4 plans */
|
||||
{ 8, 8, BP_CAPS }, /* Capacites pour 8 plans */
|
||||
{ 16, 16, TC_CAPS }, /* Capacites pour 16 plans */
|
||||
{ 24, 24, TC_CAPS }, /* Capacites pour 24 plans */
|
||||
{ 32, 32, TC_CAPS }, /* Capacites pour 32 plans */
|
||||
{ 0, 0, 0UL } /* Fin de la liste des capacites */
|
||||
},
|
||||
} ;
|
||||
|
||||
VAPI *Vapi = NULL ;
|
||||
int VDIHandle = -1 ;
|
||||
|
||||
/* Petites macros bien utiles ... */
|
||||
#define RVB16( r, v, b ) ( (r << 11) + (v << 5) + (b) )
|
||||
#define RVB32( r, v, b ) ( ((long)r << 24) + ((long)v << 16) + ((long)b << 8) )
|
||||
|
||||
|
||||
void OnClose(void)
|
||||
{
|
||||
if ( VDIHandle != -1 ) v_clsvwk( VDIHandle ) ;
|
||||
VDIHandle = -1 ;
|
||||
}
|
||||
|
||||
/* Helper function to call best progress routine depending on VAPI progress function availability */
|
||||
/* Return value: */
|
||||
/* 1: Cencel requested by user */
|
||||
/* 0: Progress update done */
|
||||
/* -1: Progress update not made to screen () */
|
||||
static short Prog(long current, long max)
|
||||
{
|
||||
short status = 0 ;
|
||||
|
||||
if ( Vapi->PrSetProgRange ) status = (short) Vapi->PrSetProgRange( current, max ) ;
|
||||
else if ( max && ( ( current & 0x0F ) == 0 ) )
|
||||
{
|
||||
short pc ;
|
||||
|
||||
/* Call progress routine only once on 16 */
|
||||
pc = (short) ( ( 100L * ( current - max ) ) / max ) ;
|
||||
if ( Vapi->PrSetProgEx ) status = Vapi->PrSetProgEx( pc ) ;
|
||||
else Vapi->PrSetProg( pc ) ;
|
||||
}
|
||||
|
||||
return status ;
|
||||
}
|
||||
#define PROG_CANCEL(status) (status == 1)
|
||||
|
||||
/*
|
||||
* Fonctions de la librairie
|
||||
*/
|
||||
int R4[256],G4[256],B4[256]; /*pr<70>calcul de luminescence 256 niveaux */
|
||||
|
||||
LDV_INFOS * cdecl GetLDVCapabilities(VAPI *vapi)
|
||||
{ float valR=0,valG=0,valB=0; int i;
|
||||
Vapi = vapi ;
|
||||
for(i=0;i<256;i++)
|
||||
{
|
||||
R4[i]=(int)valR; /* methode rapide */
|
||||
G4[i]=(int)valG;
|
||||
B4[i]=(int)valB;
|
||||
valR+=0.302;
|
||||
valG+=0.589;
|
||||
valB+=0.114;
|
||||
|
||||
}
|
||||
return( &LdvInfos ) ;
|
||||
}
|
||||
|
||||
int vdihandle(void)
|
||||
{
|
||||
int work_in[11], work_out[57], i ;
|
||||
|
||||
for ( i = 0; i < 10; work_in[i++] = 1 ) ;
|
||||
work_in[10] = 2 ;
|
||||
v_opnvwk( work_in, &i, work_out ) ;
|
||||
|
||||
return( i ) ;
|
||||
}
|
||||
|
||||
#pragma warn -par
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
return( ELDV_NOERROR ) ;
|
||||
}
|
||||
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
LDV_PALETTE *vdi_palette = &in->Palette ;
|
||||
VDI_ELEMENTPAL *vdi_epal ;
|
||||
short vdi_index ;
|
||||
short bw_value ;
|
||||
short status = 0 ;
|
||||
|
||||
if ( in->Raster.fd_nplanes <= 8 )
|
||||
{
|
||||
if ( vdi_palette == NULL ) return( ELDV_GENERALFAILURE ) ;
|
||||
vdi_epal = vdi_palette->Pal ;
|
||||
if ( vdi_epal == NULL ) return( ELDV_GENERALFAILURE ) ;
|
||||
|
||||
for ( vdi_index = 0; vdi_index < vdi_palette->NbColors; vdi_index++, vdi_epal++ )
|
||||
{
|
||||
bw_value = ( vdi_epal->Red + vdi_epal->Green + vdi_epal->Blue ) / 3 ;
|
||||
vdi_epal->Red = bw_value ;
|
||||
vdi_epal->Green = bw_value ;
|
||||
vdi_epal->Blue = bw_value ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MFDB *img = &in->Raster ;
|
||||
long nb_pts_in_line, ymax ;
|
||||
short x, y ;
|
||||
|
||||
if ( Vapi == NULL ) return ELDV_GENERALFAILURE ;
|
||||
|
||||
ymax = params->y2 - params->y1 ;
|
||||
/* Convertir l'image au format True Color "standard" ATARI */
|
||||
/* Format specifique --> format "ATARI True Color" */
|
||||
Vapi->RaTCInvConvert( img ) ;
|
||||
|
||||
nb_pts_in_line = img->fd_w ;
|
||||
nb_pts_in_line = ALIGN16( nb_pts_in_line ) ; /* Toujours aligne sur 16 pixels ! */
|
||||
|
||||
if ( img->fd_nplanes == 16 )
|
||||
{
|
||||
unsigned short *ptu, red, green, blue, ugris, val, ubr ;
|
||||
|
||||
for ( y = params->y1; !PROG_CANCEL(status) && (y <= params->y2); y++ )
|
||||
{
|
||||
ptu = (unsigned short *) img->fd_addr ;
|
||||
ptu += nb_pts_in_line * y ;
|
||||
ptu += params->x1 ;
|
||||
for ( x = params->x1; x <= params->x2; x++ )
|
||||
{
|
||||
val = *ptu ;
|
||||
red = ( val & 0x01F ) << 1 ; /* Sur 6 bits */
|
||||
green = ( val & 0x07E0 ) >> 6 ; /* Sur 6 bits */
|
||||
blue = ( val & 0xF800 ) >> 10 ; /* Sur 6 bits */
|
||||
ugris = ( R4[red] + G4[green] + B4[blue] ) ;
|
||||
ubr = ( ugris >> 1 ) ;
|
||||
*ptu++ = RVB16( ubr, ugris, ubr ) ;
|
||||
}
|
||||
status = Prog( y - params->y1, ymax ) ;
|
||||
}
|
||||
}
|
||||
else if ( img->fd_nplanes == 24 ) /* NON teste ! */
|
||||
{
|
||||
unsigned char *ptu ;
|
||||
unsigned short red, green, blue, ugris ;
|
||||
|
||||
for ( y = params->y1; !PROG_CANCEL(status) && (y <= params->y2); y++ )
|
||||
{
|
||||
ptu = (unsigned char *) img->fd_addr ;
|
||||
ptu += 3 * nb_pts_in_line * y ;
|
||||
ptu += 3 * params->x1 ;
|
||||
for ( x = params->x1; x <= params->x2; x++ )
|
||||
{
|
||||
red = (unsigned short) (*ptu++) ;
|
||||
green = (unsigned short) (*ptu++) ;
|
||||
blue = (unsigned short) (*ptu++) ;
|
||||
ugris = ( R4[red] + G4[green] + B4[blue] ) ;
|
||||
*ptu-- = ugris ;
|
||||
*ptu-- = ugris ;
|
||||
*ptu-- = ugris ;
|
||||
ptu += 3 ;
|
||||
}
|
||||
status = Prog( y - params->y1, ymax ) ;
|
||||
}
|
||||
}
|
||||
else if ( img->fd_nplanes == 32 )
|
||||
{
|
||||
unsigned long *ptu, val ;
|
||||
unsigned short red, green, blue, ugris ;
|
||||
|
||||
for ( y = params->y1; !PROG_CANCEL(status) && (y <= params->y2); y++ )
|
||||
{
|
||||
ptu = (unsigned long *)img->fd_addr ;
|
||||
ptu += nb_pts_in_line * y ;
|
||||
ptu += params->x1 ;
|
||||
for ( x = params->x1; x <= params->x2; x++ )
|
||||
{
|
||||
val = *ptu ;
|
||||
val >>= 8 ;
|
||||
blue = (unsigned short) (val & 0xFF) ;
|
||||
val >>= 8 ;
|
||||
green = (unsigned short) (val & 0xFF) ;
|
||||
val >>= 8 ;
|
||||
red = (unsigned short) (val & 0xFF) ;
|
||||
ugris = ( R4[red] + G4[green] + B4[blue] ) ;
|
||||
*ptu++ = RVB32( ugris, ugris, ugris ) ;
|
||||
}
|
||||
status = Prog( y - params->y1, ymax ) ;
|
||||
}
|
||||
}
|
||||
|
||||
/* Format "ATARI True Color" --> format specifique */
|
||||
Vapi->RaTCConvert( img ) ;
|
||||
}
|
||||
|
||||
return( PROG_CANCEL(status) ? ELDV_CANCELLED : ELDV_NOERROR ) ;
|
||||
}
|
||||
|
||||
LDV_STATUS cdecl Preview(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
return( Run( in, params, out ) ) ;
|
||||
}
|
||||
#pragma warn +par
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ldg_init( Ldg ) ;
|
||||
return( 0 ) ;
|
||||
}
|
||||
BIN
tools/vision/ldv/src/bw/bw.ldv
Normal file
BIN
tools/vision/ldv/src/bw/bw.ldv
Normal file
Binary file not shown.
13
tools/vision/ldv/src/bw/bw.prj
Normal file
13
tools/vision/ldv/src/bw/bw.prj
Normal file
@@ -0,0 +1,13 @@
|
||||
bw.ldv
|
||||
.C [ ]
|
||||
.S [ ]
|
||||
.L [ ]
|
||||
=
|
||||
pcstart.o
|
||||
bw.c
|
||||
pcgemlib.lib
|
||||
pcstdlib.lib
|
||||
pctoslib.lib
|
||||
pcfltlib.lib
|
||||
..\..\ldg.lib
|
||||
..\..\mt_aes.lib
|
||||
856
tools/vision/ldv/src/cntcol/cntcol.c
Normal file
856
tools/vision/ldv/src/cntcol/cntcol.c
Normal file
@@ -0,0 +1,856 @@
|
||||
#define PCGEMLIB 1 /* Set to 1 if PureC is used */
|
||||
|
||||
#if PCGEMLIB
|
||||
#include <aes.h>
|
||||
#include <vdi.h>
|
||||
#else
|
||||
#include <aesbind.h>
|
||||
#include <vdibind.h>
|
||||
#endif
|
||||
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "..\..\ldg.h"
|
||||
#include "..\..\vapi.h"
|
||||
#include "..\..\ldv.h"
|
||||
|
||||
/* Prototypes */
|
||||
LDV_INFOS* cdecl GetLDVCapabilities(VAPI* vapi) ;
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE* in, LDV_PARAMS* params, LDV_IMAGE* out) ;
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE* in, LDV_PARAMS* params, LDV_IMAGE* out) ;
|
||||
|
||||
/* Global variables */
|
||||
PROC Proc[] = {
|
||||
"GetLDVCapabilities", "LDV capabilities", (void*)GetLDVCapabilities,
|
||||
"PreRun", "Run initialization", (void*)PreRun,
|
||||
"Run", "LDV operation", (void*)Run,
|
||||
} ;
|
||||
|
||||
char Info[] = "LDV" ;
|
||||
|
||||
LDGLIB Ldg[] = {
|
||||
0x0107, /* Lib version */
|
||||
3, /* Number of functions in lib */
|
||||
Proc, /* Pointers to our functions */
|
||||
Info, /* Lib information */
|
||||
0x0, /* Lib flags */
|
||||
NULL, /* On exit, free VDI handle (unused) */
|
||||
} ;
|
||||
|
||||
#define CAPS (LDVF_ATARIFORMAT | LDVF_SUPPORTPROG | LDVF_OPINPLACE | LDVF_SUPPORTCANCEL | LDVF_NOSELECTION | LDVF_NOCHANGE)
|
||||
|
||||
LDV_INFOS LdvInfos = {
|
||||
(short) sizeof(LDV_INFOS), /* size of this structure */
|
||||
TLDV_MODIFYIMG, /* LDV Type */
|
||||
"Jean Lusetti/Seedy", /* Authors */
|
||||
{
|
||||
{ 1, 1, CAPS }, /* 1 bitplane capabilities */
|
||||
{ 2, 2, CAPS }, /* 2 bitplane capabilities */
|
||||
{ 4, 4, CAPS }, /* 4 bitplane capabilities */
|
||||
{ 8, 8, CAPS }, /* 8 bitplane capabilities */
|
||||
{ 16, 16, CAPS }, /* 16 bitplane capabilities */
|
||||
/* Not yet { 24, 24, CAPS }, */
|
||||
{ 32, 32, CAPS }, /* 32 bitplane capabilities */
|
||||
{ 0, 0, 0UL } /* End of this list */
|
||||
},
|
||||
} ;
|
||||
|
||||
VAPI* Vapi = NULL ;
|
||||
unsigned char VapiLog = 0 ;
|
||||
unsigned char UseVAlloc ; /* Use VISION's allocation routines if possible */
|
||||
unsigned char NbBitsIn[256] ; /* Number of bits set to 1 for every integer in [0;255] */
|
||||
|
||||
typedef struct _CNTCOL_DATA
|
||||
{
|
||||
/* Input data */
|
||||
LDV_IMAGE* in ;
|
||||
LDV_PARAMS* params ;
|
||||
FILE* report_file ;
|
||||
short method ; /* 0: auto, 1: bit array of colors, 2: sorted colors */
|
||||
}
|
||||
CNTCOL_DATA, *PCNTCOL_DATA ;
|
||||
|
||||
typedef struct _CC1_CONTEXT
|
||||
{
|
||||
void* line_colors ;
|
||||
unsigned long so_line_colors ;
|
||||
unsigned char* unique_colors_bits ;
|
||||
unsigned long so_unique_colors_bits ;
|
||||
short nplanes ;
|
||||
unsigned char* indexes ; /* Allocated only if nplanes <= 8 */
|
||||
unsigned long so_indexes ;
|
||||
unsigned long used_bytes ;
|
||||
}
|
||||
CC1_CONTEXT, *PCC1_CONTEXT ;
|
||||
|
||||
typedef struct _CC2_CONTEXT
|
||||
{
|
||||
unsigned char* line_sorted ;
|
||||
unsigned char* img_sorted ;
|
||||
unsigned long nb_img_colors ;
|
||||
unsigned long nb_img_colors_max ;
|
||||
short nplanes ;
|
||||
unsigned char* indexes ; /* Allocated only if nplanes <= 8 */
|
||||
unsigned long so_indexes ;
|
||||
unsigned long used_bytes ;
|
||||
}
|
||||
CC2_CONTEXT, *PCC2_CONTEXT ;
|
||||
|
||||
typedef struct _CC3_CONTEXT
|
||||
{
|
||||
unsigned char* line_sorted ;
|
||||
unsigned long so_line_colors ;
|
||||
unsigned char* unique_colors_bits ;
|
||||
unsigned long so_unique_colors_bits ;
|
||||
short nplanes ;
|
||||
unsigned char* indexes ; /* Allocated only if nplanes <= 8 */
|
||||
unsigned long so_indexes ;
|
||||
unsigned long used_bytes ;
|
||||
}
|
||||
CC3_CONTEXT, *PCC3_CONTEXT ;
|
||||
|
||||
typedef union _CC_CONTEXT
|
||||
{
|
||||
/* Specific data for each method */
|
||||
CC1_CONTEXT c1 ; /* color table for a line and bitcolor array globally */
|
||||
CC2_CONTEXT c2 ; /* sort/reduce each line and globally */
|
||||
CC3_CONTEXT c3 ; /* sort/reduce each line and bitcolor array globally */
|
||||
}
|
||||
CC_CONTEXT, *PCC_CONTEXT ;
|
||||
|
||||
typedef struct _CC_INTERFACE
|
||||
{
|
||||
LDV_STATUS (*Init)(CC_CONTEXT* vc, CNTCOL_DATA* data) ;
|
||||
unsigned long (*CountColors)(CC_CONTEXT* vc, void* addr, unsigned long so_line) ;
|
||||
unsigned long (*CountColorsEnd)(CC_CONTEXT* vc) ;
|
||||
unsigned long (*Exit)(CC_CONTEXT* vc) ;
|
||||
}
|
||||
CC_INTERFACE, *PCC_INTERFACE ;
|
||||
|
||||
|
||||
/* Helper function to call best progress routine depending on VAPI progress function availability */
|
||||
/* Return value: */
|
||||
/* 1: Cencel requested by user */
|
||||
/* 0: Progress update done */
|
||||
/* -1: Progress update not made to screen () */
|
||||
static short Prog(long current, long max)
|
||||
{
|
||||
short status = 0 ;
|
||||
|
||||
if ( Vapi->PrSetProgRange ) status = (short) Vapi->PrSetProgRange( current, max ) ;
|
||||
else if ( max && ( ( current & 0x0F ) == 0 ) )
|
||||
{
|
||||
short pc ;
|
||||
|
||||
/* Call progress routine only once on 16 */
|
||||
pc = (short) ( ( 100L * ( current - max ) ) / max ) ;
|
||||
if ( Vapi->PrSetProgEx ) status = Vapi->PrSetProgEx( pc ) ;
|
||||
else Vapi->PrSetProg( pc ) ;
|
||||
}
|
||||
|
||||
return status ;
|
||||
}
|
||||
|
||||
/* Wrappers to abstract dynamic allocation routines */
|
||||
static void* localCalloc(unsigned long size)
|
||||
{
|
||||
void* p ;
|
||||
|
||||
if ( UseVAlloc ) p = Vapi->MeXcalloc( 1, size ) ;
|
||||
else p = calloc( 1, size ) ;
|
||||
|
||||
return p ;
|
||||
}
|
||||
|
||||
static void* localAlloc(unsigned long size)
|
||||
{
|
||||
void* p ;
|
||||
|
||||
if ( UseVAlloc ) p = Vapi->MeXalloc( size ) ;
|
||||
else p = malloc( size ) ;
|
||||
|
||||
return p ;
|
||||
}
|
||||
|
||||
static void localFree(void* p)
|
||||
{
|
||||
if ( p )
|
||||
{
|
||||
if ( UseVAlloc ) Vapi->MeXfree( p ) ;
|
||||
else free( p ) ;
|
||||
}
|
||||
}
|
||||
|
||||
LDV_INFOS* cdecl GetLDVCapabilities(VAPI* vapi)
|
||||
{
|
||||
Vapi = vapi ;
|
||||
VapiLog = Vapi && Vapi->LoDoLog ;
|
||||
|
||||
return( &LdvInfos ) ;
|
||||
}
|
||||
|
||||
#pragma warn -par
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE* in, LDV_PARAMS* params, LDV_IMAGE* out)
|
||||
{
|
||||
return ELDV_NOERROR ;
|
||||
}
|
||||
#pragma warn +par
|
||||
|
||||
static FILE* CreateReportFile(CNTCOL_DATA* data)
|
||||
{
|
||||
FILE* stream ;
|
||||
char* filename ;
|
||||
|
||||
if ( data->params->Param[1].str ) filename = data->params->Param[1].str ;
|
||||
else filename = "cntcol.txt" ;
|
||||
stream = fopen( filename, "wb" ) ;
|
||||
if ( VapiLog )
|
||||
{
|
||||
if ( stream ) Vapi->LoDoLog(LL_INFO, "cntcol.ldv will generate report file %s", filename) ;
|
||||
else Vapi->LoDoLog(LL_ERROR, "cntcol.ldv failed to create report file %s", filename) ;
|
||||
}
|
||||
|
||||
if ( stream )
|
||||
{
|
||||
fprintf( stream, "cntcol LDV running on image %dx%d, %d bitplanes:\r\n", data->in->Raster.fd_w, data->in->Raster.fd_h, data->in->Raster.fd_nplanes ) ;
|
||||
fprintf( stream, "-------|--------------------\r\n" ) ;
|
||||
fprintf( stream, "| Line | # unique colors |\r\n" ) ;
|
||||
}
|
||||
|
||||
return stream ;
|
||||
}
|
||||
|
||||
static unsigned long CountBits(unsigned char* pt, unsigned long nb_bytes)
|
||||
{
|
||||
unsigned char* p = pt ;
|
||||
unsigned long nb_bits = 0 ;
|
||||
|
||||
while ( p < pt+nb_bytes )
|
||||
{
|
||||
nb_bits += NbBitsIn[*p] ;
|
||||
p++ ;
|
||||
}
|
||||
|
||||
return nb_bits ;
|
||||
}
|
||||
|
||||
static LDV_STATUS check_prog(short y, short ymax, unsigned long nb_unique_colors_on_line)
|
||||
{
|
||||
short status ;
|
||||
|
||||
status = Prog( y, ymax ) ;
|
||||
if ( status == 0 ) /* GUI updated */
|
||||
{
|
||||
if ( Vapi->PrSetText )
|
||||
{
|
||||
char buf[128] ;
|
||||
|
||||
sprintf( buf, "%lu unique colors on line %d", nb_unique_colors_on_line, y ) ;
|
||||
Vapi->PrSetText( 1, buf ) ;
|
||||
}
|
||||
}
|
||||
|
||||
return LDVPROG_CANCEL( status ) ? ELDV_CANCELLED:ELDV_NOERROR ;
|
||||
}
|
||||
|
||||
static short add_pixel_if_not_present16(unsigned short pixel, unsigned short* line_colors, unsigned long nb_colors)
|
||||
{
|
||||
unsigned long i ;
|
||||
|
||||
for ( i = 0; i < nb_colors; i++ )
|
||||
if ( line_colors[i] == pixel ) break ;
|
||||
|
||||
if ( i == nb_colors ) { line_colors[nb_colors++] = pixel ; return 1 ; }
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
static short add_pixel_if_not_present32(unsigned long pixel, unsigned long* line_colors, unsigned long nb_colors)
|
||||
{
|
||||
unsigned long i ;
|
||||
|
||||
for ( i = 0; i < nb_colors; i++ )
|
||||
if ( line_colors[i] == pixel ) break ;
|
||||
|
||||
if ( i == nb_colors ) { line_colors[nb_colors++] = pixel ; return 1 ; }
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
static unsigned long CC1(CC_CONTEXT* vc, void* addr, unsigned long so_line)
|
||||
{
|
||||
CC1_CONTEXT* c = (CC1_CONTEXT*) &vc->c1 ;
|
||||
unsigned char* line = (unsigned char*) addr ;
|
||||
unsigned long offset, nb_colors = 0 ;
|
||||
unsigned short bit ;
|
||||
|
||||
if ( c->nplanes <= 8 ) /* Bit planes */
|
||||
{
|
||||
unsigned char unique_colors_bits_line[256/8] ; /* 256 bits --> 256/8 bytes */
|
||||
unsigned short x ;
|
||||
|
||||
memset( unique_colors_bits_line, 0, sizeof(unique_colors_bits_line) ) ;
|
||||
Vapi->RaRaster2Ind( addr, c->so_indexes, c->nplanes, c->indexes ) ;
|
||||
for ( x = 0; x < c->so_indexes; x++ )
|
||||
{
|
||||
bit = c->indexes[x] & 0x07 ;
|
||||
offset = c->indexes[x] >> 3 ;
|
||||
c->unique_colors_bits[offset] |= (1 << bit) ;
|
||||
unique_colors_bits_line[offset] |= (1 << bit) ;
|
||||
}
|
||||
nb_colors = CountBits( unique_colors_bits_line, sizeof(unique_colors_bits_line) ) ;
|
||||
}
|
||||
else if ( c->nplanes == 16 ) /* TC16 */
|
||||
{
|
||||
unsigned short* p ;
|
||||
unsigned short pixel ;
|
||||
|
||||
for ( p = (unsigned short*)line; p < (unsigned short*) (line+so_line); p++ )
|
||||
{
|
||||
pixel = *p ;
|
||||
nb_colors += add_pixel_if_not_present16( pixel, c->line_colors, nb_colors ) ;
|
||||
bit = pixel & 0x07 ;
|
||||
offset = pixel >> 3 ;
|
||||
c->unique_colors_bits[offset] |= (1 << bit) ;
|
||||
}
|
||||
}
|
||||
else if ( c->nplanes == 32 ) /* TC32 */
|
||||
{
|
||||
unsigned char* p ;
|
||||
unsigned long pixel ;
|
||||
|
||||
for ( p = line; p < line+so_line; p += 4 )
|
||||
{
|
||||
pixel = p[0] ;
|
||||
pixel |= ( (unsigned long)p[1] << 8 ) ;
|
||||
pixel |= ( (unsigned long)p[2] << 16 ) ;
|
||||
nb_colors += add_pixel_if_not_present32( pixel, c->line_colors, nb_colors ) ;
|
||||
bit = (unsigned short)pixel & 0x07 ;
|
||||
offset = pixel >> 3 ;
|
||||
c->unique_colors_bits[offset] |= (1 << bit) ;
|
||||
}
|
||||
}
|
||||
|
||||
return nb_colors ;
|
||||
}
|
||||
|
||||
static unsigned long CC1Exit(CC_CONTEXT* vc)
|
||||
{
|
||||
CC1_CONTEXT* c = &vc->c1 ;
|
||||
|
||||
localFree( c->unique_colors_bits ) ;
|
||||
localFree( c->line_colors ) ;
|
||||
localFree( c->indexes ) ;
|
||||
|
||||
return c->used_bytes ;
|
||||
}
|
||||
|
||||
static unsigned long Getso_unique_colors_bits(MFDB* img)
|
||||
{
|
||||
unsigned long so_unique_colors_bits ;
|
||||
|
||||
if ( img->fd_nplanes > 8 )
|
||||
{
|
||||
if ( img->fd_nplanes == 16 ) so_unique_colors_bits = 1UL << 16 ;
|
||||
else so_unique_colors_bits = 1UL << 24 ; /* TC24 or TC32 */
|
||||
}
|
||||
else so_unique_colors_bits = 256 ;
|
||||
|
||||
so_unique_colors_bits >>= 3 ; /* #bits --> #bytes */
|
||||
if ( so_unique_colors_bits == 0 ) so_unique_colors_bits = 1 ;
|
||||
|
||||
return so_unique_colors_bits ;
|
||||
}
|
||||
|
||||
static LDV_STATUS CC1Init(CC_CONTEXT* vc, CNTCOL_DATA* data)
|
||||
{
|
||||
MFDB* img = &data->in->Raster ;
|
||||
CC1_CONTEXT* c = &vc->c1 ;
|
||||
|
||||
memset( c, 0, sizeof(*c) ) ;
|
||||
c->nplanes = img->fd_nplanes ;
|
||||
if ( img->fd_nplanes > 8 )
|
||||
{
|
||||
/* True Color */
|
||||
/* Size of bit array for each unique color depending on the number of planes */
|
||||
c->so_line_colors = Vapi->RaGetImgSize( img->fd_w, 1, img->fd_nplanes ) ;
|
||||
c->line_colors = localAlloc( c->so_line_colors ) ;
|
||||
if ( c->line_colors == NULL ) return ELDV_NOTENOUGHMEMORY ;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Bit planes */
|
||||
c->so_indexes = 16*img->fd_wdwidth ; /* Max for 8 planes */
|
||||
c->indexes = (unsigned char*) localAlloc( c->so_indexes ) ;
|
||||
c->so_line_colors = 0 ;
|
||||
if ( c->indexes == NULL ) return ELDV_NOTENOUGHMEMORY ;
|
||||
}
|
||||
|
||||
c->so_unique_colors_bits = Getso_unique_colors_bits( img ) ;
|
||||
c->unique_colors_bits = localCalloc( c->so_unique_colors_bits ) ;
|
||||
if ( c->unique_colors_bits == NULL ) { CC1Exit( vc ) ; return ELDV_NOTENOUGHMEMORY ; }
|
||||
|
||||
c->used_bytes = c->so_unique_colors_bits + c->so_line_colors + c->so_indexes ;
|
||||
|
||||
return ELDV_NOERROR ;
|
||||
}
|
||||
|
||||
static unsigned long CC1End(CC_CONTEXT* vc)
|
||||
{
|
||||
CC1_CONTEXT* c = &vc->c1 ;
|
||||
|
||||
return CountBits( c->unique_colors_bits, c->so_unique_colors_bits ) ;
|
||||
}
|
||||
|
||||
static int cmp8(const void* a, const void* b)
|
||||
{
|
||||
unsigned char* e1 = (unsigned char*) a ;
|
||||
unsigned char* e2 = (unsigned char*) b ;
|
||||
|
||||
return (int)( *e1 - *e2 ) ;
|
||||
}
|
||||
|
||||
static int cmp16(const void* a, const void* b)
|
||||
{
|
||||
unsigned short* e1 = (unsigned short*) a ;
|
||||
unsigned short* e2 = (unsigned short*) b ;
|
||||
|
||||
return ( *e1 - *e2 ) ;
|
||||
}
|
||||
|
||||
static int cmp32(const void* a, const void* b)
|
||||
{
|
||||
unsigned long* e1 = (unsigned long*) a ;
|
||||
unsigned long* e2 = (unsigned long*) b ;
|
||||
|
||||
if ( *e1 < *e2 ) return -1 ;
|
||||
if ( *e1 == *e2 ) return 0 ;
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
static unsigned long reduce8(unsigned char* array, unsigned long nb_items)
|
||||
{
|
||||
unsigned long nb_unique = 0 ;
|
||||
unsigned char* pread ;
|
||||
unsigned char* pwrite ;
|
||||
unsigned char val ;
|
||||
|
||||
pread = pwrite = array ;
|
||||
while ( pread < array + nb_items )
|
||||
{
|
||||
val = *pread++ ;
|
||||
while ( (pread < array + nb_items) && (*pread == val) ) pread++ ;
|
||||
nb_unique++ ;
|
||||
*pwrite++ = val ;
|
||||
}
|
||||
|
||||
return nb_unique ;
|
||||
}
|
||||
|
||||
static unsigned long reduce16(unsigned short* array, unsigned long nb_items)
|
||||
{
|
||||
unsigned long nb_unique = 0 ;
|
||||
unsigned short* pread ;
|
||||
unsigned short* pwrite ;
|
||||
unsigned short val ;
|
||||
|
||||
pread = pwrite = array ;
|
||||
while ( pread < array + nb_items )
|
||||
{
|
||||
val = *pread++ ;
|
||||
while ( (pread < array + nb_items) && (*pread == val) ) pread++ ;
|
||||
nb_unique++ ;
|
||||
*pwrite++ = val ;
|
||||
}
|
||||
|
||||
return nb_unique ;
|
||||
}
|
||||
|
||||
static unsigned long reduce32(unsigned long* array, unsigned long nb_items)
|
||||
{
|
||||
unsigned long nb_unique = 0 ;
|
||||
unsigned long* pread ;
|
||||
unsigned long* pwrite ;
|
||||
unsigned long val ;
|
||||
|
||||
pread = pwrite = array ;
|
||||
while ( pread < array + nb_items )
|
||||
{
|
||||
val = *pread++ ;
|
||||
while ( (pread < array + nb_items) && (*pread == val) ) pread++ ;
|
||||
nb_unique++ ;
|
||||
*pwrite++ = val ;
|
||||
}
|
||||
|
||||
return nb_unique ;
|
||||
}
|
||||
|
||||
static unsigned long CC2(CC_CONTEXT* vc, void* addr, unsigned long so_line)
|
||||
{
|
||||
CC2_CONTEXT* c = (CC2_CONTEXT*) &vc->c2 ;
|
||||
unsigned long nb_colors = 0 ;
|
||||
|
||||
if ( c->nplanes <= 8 ) /* Bit planes */
|
||||
{
|
||||
Vapi->RaRaster2Ind( addr, c->so_indexes, c->nplanes, c->indexes ) ;
|
||||
qsort( c->indexes, c->so_indexes, sizeof(unsigned char), cmp8 ) ;
|
||||
nb_colors = reduce8( c->indexes, c->so_indexes ) ;
|
||||
/* Add new line of unique colors to current image unique colors */
|
||||
memmove( c->img_sorted + c->nb_img_colors, c->indexes, nb_colors*sizeof(unsigned char) ) ;
|
||||
c->nb_img_colors += nb_colors ;
|
||||
}
|
||||
else if ( c->nplanes == 16 ) /* TC16 */
|
||||
{
|
||||
memmove( c->line_sorted, addr, so_line ) ;
|
||||
qsort( c->line_sorted, so_line >> 1, sizeof(unsigned short), cmp16 ) ;
|
||||
nb_colors = reduce16( (unsigned short*) c->line_sorted, so_line >> 1 ) ;
|
||||
/* Add new line of unique colors to current image unique colors */
|
||||
memmove( c->img_sorted + 2*c->nb_img_colors, c->line_sorted, nb_colors*sizeof(unsigned short) ) ;
|
||||
c->nb_img_colors += nb_colors ;
|
||||
}
|
||||
else if ( c->nplanes == 32 ) /* TC32 */
|
||||
{
|
||||
memmove( c->line_sorted, addr, so_line ) ;
|
||||
qsort( c->line_sorted, so_line >> 2, sizeof(unsigned long), cmp32 ) ;
|
||||
nb_colors = reduce32( (unsigned long*) c->line_sorted, so_line >> 2 ) ;
|
||||
/* Add new line of unique colors to current image unique colors */
|
||||
memmove( c->img_sorted + 4*c->nb_img_colors, c->line_sorted, nb_colors*sizeof(unsigned long) ) ;
|
||||
c->nb_img_colors += nb_colors ;
|
||||
}
|
||||
|
||||
return nb_colors ;
|
||||
}
|
||||
|
||||
static unsigned long CC2Exit(CC_CONTEXT* vc)
|
||||
{
|
||||
CC2_CONTEXT* c = &vc->c2 ;
|
||||
|
||||
localFree( c->indexes ) ;
|
||||
localFree( c->img_sorted ) ;
|
||||
localFree( c->line_sorted ) ;
|
||||
|
||||
return c->used_bytes ;
|
||||
}
|
||||
|
||||
static LDV_STATUS CC2Init(CC_CONTEXT* vc, CNTCOL_DATA* data)
|
||||
{
|
||||
MFDB* img = &data->in->Raster ;
|
||||
CC2_CONTEXT* c = &vc->c2 ;
|
||||
short pixel_in_bytes ;
|
||||
|
||||
memset( c, 0, sizeof(*c) ) ;
|
||||
c->nplanes = img->fd_nplanes ;
|
||||
|
||||
/* Use VISION's checked allocation routine for safety as VISION performs bounduary checks */
|
||||
/* Allocate memory to duplicate a line and sort it out */
|
||||
if ( img->fd_nplanes > 8 )
|
||||
{
|
||||
c->line_sorted = (unsigned char*) localAlloc( Vapi->RaGetImgSize( img->fd_w, 1, img->fd_nplanes ) ) ;
|
||||
if ( c->line_sorted == NULL ) return ELDV_NOTENOUGHMEMORY ;
|
||||
if ( img->fd_nplanes == 16 ) pixel_in_bytes = 2 ;
|
||||
else pixel_in_bytes = 4 ;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Bit planes: we need an index array */
|
||||
c->so_indexes = 16*img->fd_wdwidth ; /* Max for 8 planes */
|
||||
c->indexes = (unsigned char*) localAlloc( c->so_indexes ) ;
|
||||
if ( c->indexes == NULL ) { CC2Exit( vc ) ; return ELDV_NOTENOUGHMEMORY ; }
|
||||
pixel_in_bytes = 1 ;
|
||||
}
|
||||
|
||||
/* Allocate memory to store all colors used for all the image */
|
||||
/* There can't be more colors than pixels in the image, so let's go with that */
|
||||
c->nb_img_colors_max = (unsigned long)img->fd_w * (unsigned long)img->fd_h ;
|
||||
c->img_sorted = (unsigned char*) localAlloc( c->nb_img_colors_max*pixel_in_bytes ) ;
|
||||
if ( c->img_sorted == NULL ) { CC2Exit( vc ) ; return ELDV_NOTENOUGHMEMORY ; }
|
||||
c->used_bytes = c->so_indexes + c->nb_img_colors_max*pixel_in_bytes ;
|
||||
|
||||
return ELDV_NOERROR ;
|
||||
}
|
||||
|
||||
static unsigned long CC2End(CC_CONTEXT* vc)
|
||||
{
|
||||
CC2_CONTEXT* c = &vc->c2 ;
|
||||
|
||||
if ( c->nplanes <= 8 ) /* Bit planes */
|
||||
{
|
||||
/* Sort the new array */
|
||||
qsort( c->img_sorted, c->nb_img_colors, sizeof(unsigned char), cmp8 ) ;
|
||||
/* And reduce it */
|
||||
c->nb_img_colors = reduce8( c->img_sorted, c->nb_img_colors ) ;
|
||||
}
|
||||
else if ( c->nplanes == 16 ) /* TC16 */
|
||||
{
|
||||
/* Sort the new array */
|
||||
qsort( c->img_sorted, c->nb_img_colors, sizeof(unsigned short), cmp16 ) ;
|
||||
/* And reduce it */
|
||||
c->nb_img_colors = reduce16( (unsigned short*) c->img_sorted, c->nb_img_colors ) ;
|
||||
}
|
||||
else if ( c->nplanes == 32 ) /* TC32 */
|
||||
{
|
||||
/* Sort the new array */
|
||||
qsort( c->img_sorted, c->nb_img_colors, sizeof(unsigned long), cmp32 ) ;
|
||||
/* And reduce it */
|
||||
c->nb_img_colors = reduce32( (unsigned long*) c->img_sorted, c->nb_img_colors ) ;
|
||||
}
|
||||
|
||||
return c->nb_img_colors ;
|
||||
}
|
||||
|
||||
static unsigned long CC3Exit(CC_CONTEXT* vc)
|
||||
{
|
||||
CC3_CONTEXT* c = &vc->c3 ;
|
||||
|
||||
localFree( c->unique_colors_bits ) ;
|
||||
localFree( c->line_sorted ) ;
|
||||
localFree( c->indexes ) ;
|
||||
|
||||
return c->used_bytes ;
|
||||
}
|
||||
|
||||
static LDV_STATUS CC3Init(CC_CONTEXT* vc, CNTCOL_DATA* data)
|
||||
{
|
||||
MFDB* img = &data->in->Raster ;
|
||||
CC3_CONTEXT* c = &vc->c3 ;
|
||||
|
||||
memset( c, 0, sizeof(*c) ) ;
|
||||
c->nplanes = img->fd_nplanes ;
|
||||
if ( img->fd_nplanes > 8 )
|
||||
{
|
||||
/* True Color */
|
||||
/* Size of bit array for each unique color depending on the number of planes */
|
||||
c->so_line_colors = Vapi->RaGetImgSize( img->fd_w, 1, img->fd_nplanes ) ;
|
||||
/* Allocate memory for a line to get sorted */
|
||||
c->line_sorted = localAlloc( c->so_line_colors ) ;
|
||||
if ( c->line_sorted == NULL ) return ELDV_NOTENOUGHMEMORY ;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Bit planes */
|
||||
c->so_indexes = 16*img->fd_wdwidth ; /* Max for 8 planes */
|
||||
c->indexes = (unsigned char*) localAlloc( c->so_indexes ) ;
|
||||
if ( c->indexes == NULL ) return ELDV_NOTENOUGHMEMORY ;
|
||||
}
|
||||
|
||||
c->so_unique_colors_bits = Getso_unique_colors_bits( img ) ;
|
||||
c->unique_colors_bits = localCalloc( c->so_unique_colors_bits ) ;
|
||||
if ( c->unique_colors_bits == NULL ) { CC3Exit( vc ) ; return ELDV_NOTENOUGHMEMORY ; }
|
||||
|
||||
c->used_bytes = c->so_line_colors + c->so_indexes + c->so_unique_colors_bits ;
|
||||
|
||||
return ELDV_NOERROR ;
|
||||
}
|
||||
|
||||
static unsigned long CC3End(CC_CONTEXT* vc)
|
||||
{
|
||||
CC3_CONTEXT* c = &vc->c3 ;
|
||||
|
||||
return CountBits( c->unique_colors_bits, c->so_unique_colors_bits ) ;
|
||||
}
|
||||
|
||||
static unsigned long CC3(CC_CONTEXT* vc, void* addr, unsigned long so_line)
|
||||
{
|
||||
CC3_CONTEXT* c = (CC3_CONTEXT*) &vc->c3 ;
|
||||
unsigned char* line = (unsigned char*) addr ;
|
||||
unsigned long offset, nb_colors = 0 ;
|
||||
unsigned short bit ;
|
||||
|
||||
if ( c->nplanes <= 8 ) /* Bit planes */
|
||||
{
|
||||
unsigned short x ;
|
||||
|
||||
/* Sort/reduce this line */
|
||||
Vapi->RaRaster2Ind( addr, c->so_indexes, c->nplanes, c->indexes ) ;
|
||||
qsort( c->indexes, c->so_indexes, sizeof(unsigned char), cmp8 ) ;
|
||||
nb_colors = reduce8( c->indexes, c->so_indexes ) ;
|
||||
|
||||
/* Update global bitarray */
|
||||
for ( x = 0; x < c->so_indexes; x++ )
|
||||
{
|
||||
bit = c->indexes[x] & 0x07 ;
|
||||
offset = c->indexes[x] >> 3 ;
|
||||
c->unique_colors_bits[offset] |= (1 << bit) ;
|
||||
}
|
||||
}
|
||||
else if ( c->nplanes == 16 ) /* TC16 */
|
||||
{
|
||||
unsigned short* p ;
|
||||
unsigned short pixel ;
|
||||
|
||||
/* Sort/reduce this line */
|
||||
memmove( c->line_sorted, addr, so_line ) ;
|
||||
qsort( c->line_sorted, so_line >> 1, sizeof(unsigned short), cmp16 ) ;
|
||||
nb_colors = reduce16( (unsigned short*) c->line_sorted, so_line >> 1 ) ;
|
||||
|
||||
/* Update global bitarray */
|
||||
for ( p = (unsigned short*)line; p < (unsigned short*) (line+so_line); p++ )
|
||||
{
|
||||
pixel = *p ;
|
||||
bit = pixel & 0x07 ;
|
||||
offset = pixel >> 3 ;
|
||||
c->unique_colors_bits[offset] |= (1 << bit) ;
|
||||
}
|
||||
}
|
||||
else if ( c->nplanes == 32 ) /* TC32 */
|
||||
{
|
||||
unsigned char* p ;
|
||||
unsigned long pixel ;
|
||||
|
||||
/* Sort/reduce this line */
|
||||
memmove( c->line_sorted, addr, so_line ) ;
|
||||
qsort( c->line_sorted, so_line >> 2, sizeof(unsigned long), cmp32 ) ;
|
||||
nb_colors = reduce32( (unsigned long*) c->line_sorted, so_line >> 2 ) ;
|
||||
|
||||
for ( p = line; p < line+so_line; p += 4 )
|
||||
{
|
||||
pixel = p[0] ;
|
||||
pixel |= ( (unsigned long)p[1] << 8 ) ;
|
||||
pixel |= ( (unsigned long)p[2] << 16 ) ;
|
||||
bit = (unsigned short)pixel & 0x07 ;
|
||||
offset = pixel >> 3 ;
|
||||
c->unique_colors_bits[offset] |= (1 << bit) ;
|
||||
}
|
||||
}
|
||||
|
||||
return nb_colors ;
|
||||
}
|
||||
|
||||
static LDV_STATUS LDVOperation(CNTCOL_DATA* data)
|
||||
{
|
||||
CC_INTERFACE cci ;
|
||||
CC_CONTEXT c ;
|
||||
LDV_STATUS status ;
|
||||
MFDB* img = &data->in->Raster ;
|
||||
unsigned char* line ;
|
||||
unsigned long so_line ;
|
||||
short method, l = 0 ;
|
||||
unsigned long nb_unique_colors_on_line, used_ram ;
|
||||
unsigned char* pt_after_img ;
|
||||
|
||||
so_line = Vapi->RaGetImgSize( img->fd_w, 1, img->fd_nplanes ) ;
|
||||
method = data->method ;
|
||||
if ( method == 0 )
|
||||
{
|
||||
/* Let me decide */
|
||||
if ( img->fd_nplanes <= 8 ) method = 1 ; /* qsort/reduce is too costy when there are not so many colors */
|
||||
else method = 3 ;
|
||||
}
|
||||
switch( method )
|
||||
{
|
||||
case 1: cci.Init = CC1Init ;
|
||||
cci.CountColors = CC1 ;
|
||||
cci.CountColorsEnd = CC1End ;
|
||||
cci.Exit = CC1Exit ;
|
||||
break ;
|
||||
|
||||
case 2: cci.Init = CC2Init ;
|
||||
cci.CountColors = CC2 ;
|
||||
cci.CountColorsEnd = CC2End ;
|
||||
cci.Exit = CC2Exit ;
|
||||
break ;
|
||||
|
||||
default: cci.Init = CC3Init ;
|
||||
cci.CountColors = CC3 ;
|
||||
cci.CountColorsEnd = CC3End ;
|
||||
cci.Exit = CC3Exit ;
|
||||
method = 3 ;
|
||||
break ;
|
||||
}
|
||||
if ( VapiLog )
|
||||
{
|
||||
Vapi->LoDoLog(LL_DEBUG, "cntcol.ldv: Image is %dx%dx%d, wd_width=%d", img->fd_w, img->fd_h, img->fd_nplanes, img->fd_wdwidth ) ;
|
||||
Vapi->LoDoLog(LL_DEBUG, "cntcol.ldv: using %s's memory allocation routines", UseVAlloc ? "VISION":"compiler" ) ;
|
||||
Vapi->LoDoLog(LL_DEBUG, "cntcol.ldv: using method %d for counting colors", method ) ;
|
||||
}
|
||||
status = cci.Init( &c, data ) ;
|
||||
if ( !LDV_SUCCESS( status ) ) return status ;
|
||||
if ( VapiLog ) Vapi->LoDoLog(LL_DEBUG, "cntcol.ldv: init done" ) ;
|
||||
|
||||
line = img->fd_addr ;
|
||||
pt_after_img = line + (unsigned long)img->fd_h*so_line ;
|
||||
while ( LDV_SUCCESS( status ) && (line < pt_after_img) )
|
||||
{
|
||||
nb_unique_colors_on_line = cci.CountColors( &c, line, so_line ) ;
|
||||
if ( nb_unique_colors_on_line > 0 )
|
||||
{
|
||||
fprintf( data->report_file, "|%6d|%17lu|\r\n", l, nb_unique_colors_on_line ) ;
|
||||
line += so_line ;
|
||||
status = check_prog( l++, img->fd_h, nb_unique_colors_on_line ) ;
|
||||
}
|
||||
else status = ELDV_NOTENOUGHMEMORY ;
|
||||
}
|
||||
|
||||
if ( status == ELDV_CANCELLED ) fprintf( data->report_file, "---- Operation cancelled by user ----\r\n" ) ;
|
||||
else if ( status == ELDV_NOTENOUGHMEMORY ) fprintf( data->report_file, "---- Not enough memory ----\r\n" ) ;
|
||||
else
|
||||
{
|
||||
unsigned long nb_unique_colors ;
|
||||
|
||||
if ( VapiLog ) Vapi->LoDoLog(LL_DEBUG, "cntcol.ldv: finishing counting..." ) ;
|
||||
fprintf( data->report_file, "-------|------------------\r\n" ) ;
|
||||
nb_unique_colors = cci.CountColorsEnd( &c ) ;
|
||||
fprintf( data->report_file, "|Total |%17lu|\r\n", nb_unique_colors ) ;
|
||||
if ( VapiLog ) Vapi->LoDoLog(LL_INFO, "cntcol.ldv: %lu unique colors on image", nb_unique_colors ) ;
|
||||
if ( Vapi->Header.Version >= 0x0106 )
|
||||
{
|
||||
/* LDV_PARAMS provides storage for returning */
|
||||
/* A free text to be displayed in VISION */
|
||||
if ( VapiLog ) Vapi->LoDoLog(LL_INFO, "cntcol.ldv: returning #unique colors to VISION" ) ;
|
||||
sprintf( data->params->ldv_txt_out, "%lu unique colors", nb_unique_colors ) ;
|
||||
}
|
||||
}
|
||||
|
||||
fprintf( data->report_file, "-------|------------------\r\n" ) ;
|
||||
used_ram = cci.Exit( &c ) ;
|
||||
fprintf( data->report_file, "RAM used: %lu KB\r\n", used_ram/1024UL ) ;
|
||||
|
||||
return status ;
|
||||
}
|
||||
|
||||
#pragma warn -par
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE* in, LDV_PARAMS* params, LDV_IMAGE* out)
|
||||
{
|
||||
CNTCOL_DATA data ;
|
||||
LDV_STATUS status ;
|
||||
clock_t t0 ;
|
||||
|
||||
if ( (in->RasterFormat & CAPS) == 0 ) return ELDV_IMGFORMATMISMATCH ;
|
||||
|
||||
UseVAlloc = Vapi && Vapi->MeXcalloc && Vapi->MeXfree ;
|
||||
|
||||
data.in = in ;
|
||||
data.params = params ;
|
||||
data.method = data.params->Param[0].s ;
|
||||
data.report_file = CreateReportFile( &data ) ;
|
||||
if ( data.report_file == NULL ) return ELDV_GENERALFAILURE ;
|
||||
|
||||
t0 = clock() ;
|
||||
status = LDVOperation( &data ) ;
|
||||
|
||||
fprintf( data.report_file, "Computation time: %lu ms\r\n", (1000L*(clock()-t0))/CLK_TCK ) ;
|
||||
fclose( data.report_file ) ;
|
||||
|
||||
return status ;
|
||||
}
|
||||
#pragma warn +par
|
||||
|
||||
static void init_bit_counts(void)
|
||||
{
|
||||
unsigned short i, mask ;
|
||||
|
||||
for ( i = 0; i <= 255; i++ )
|
||||
for ( mask = 1; mask < 256; mask <<= 1 )
|
||||
if ( i & mask ) NbBitsIn[i]++ ;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ldg_init( Ldg ) ;
|
||||
|
||||
init_bit_counts() ;
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
BIN
tools/vision/ldv/src/cntcol/cntcol.ldv
Normal file
BIN
tools/vision/ldv/src/cntcol/cntcol.ldv
Normal file
Binary file not shown.
12
tools/vision/ldv/src/cntcol/cntcol.prj
Normal file
12
tools/vision/ldv/src/cntcol/cntcol.prj
Normal file
@@ -0,0 +1,12 @@
|
||||
CNTCOL.LDV
|
||||
.C [ ]
|
||||
.S [ ]
|
||||
.L [ ]
|
||||
=
|
||||
pcstart.o
|
||||
CNTCOL.C
|
||||
pcgemlib.lib
|
||||
pcstdlib.lib
|
||||
pctoslib.lib
|
||||
..\..\ldg.lib
|
||||
..\..\mt_aes.lib
|
||||
145
tools/vision/ldv/src/dither/dither.c
Normal file
145
tools/vision/ldv/src/dither/dither.c
Normal file
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
*
|
||||
*
|
||||
* Version PureC / Gcc
|
||||
*/
|
||||
|
||||
#define PCGEMLIB 1 /* mettre 1 si les utilisateurs de Pure C
|
||||
* utilise les librairies GEM Pure C */
|
||||
|
||||
/* Fichiers headers */
|
||||
|
||||
#include <portab.h>
|
||||
#if PCGEMLIB
|
||||
#include <aes.h>
|
||||
#include <vdi.h>
|
||||
#else
|
||||
#include <aesbind.h>
|
||||
#include <vdibind.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "..\..\ldg.h"
|
||||
#include "..\..\vapi.h"
|
||||
#include "..\..\ldv.h"
|
||||
#include "..\..\mt_aes.h"
|
||||
|
||||
/* Prototypages */
|
||||
LDV_INFOS* cdecl GetLDVCapabilities(VAPI *vapi) ;
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
LDV_STATUS cdecl Preview(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
|
||||
void OnClose(void) ;
|
||||
|
||||
/* Variables globales */
|
||||
PROC Proc[] = {
|
||||
"GetLDVCapabilities", "LDV capabilties", (void *)GetLDVCapabilities,
|
||||
"PreRun", "Before Run", (void *)PreRun,
|
||||
"Run", "LDV routine", (void *)Run,
|
||||
"Preview", "Preview", (void *)Preview,
|
||||
} ;
|
||||
|
||||
char Info[] = "LDV";
|
||||
|
||||
LDGLIB Ldg[] = {
|
||||
0x0100, /* version de la lib, recommand<6E> */
|
||||
4, /* nombre de fonction dans la lib */
|
||||
Proc, /* Pointeurs vers nos fonctions */
|
||||
Info, /* Information sur la lib */
|
||||
0x0, /* Flags de la lib, obligatoire */
|
||||
NULL,
|
||||
};
|
||||
|
||||
#define BP_CAPS (LDVF_ATARIFORMAT | LDVF_SUPPORTPREVIEW | LDVF_REALTIMEPARAMS | LDVF_NOSELECTION | LDVF_AFFECTPALETTE)
|
||||
#define TC_CAPS (LDVF_ATARIFORMAT | LDVF_SUPPORTPREVIEW | LDVF_REALTIMEPARAMS | LDVF_NOSELECTION | LDVF_AFFECTPALETTE)
|
||||
|
||||
LDV_INFOS LdvInfos = {
|
||||
(short) sizeof(LDV_INFOS), /* Taille de cette structure */
|
||||
TLDV_MODIFYIMG, /* Type du LDV */
|
||||
"Jean Lusetti", /* Auteurs */
|
||||
{
|
||||
{ 1, 1, BP_CAPS }, /* Capacites pour 1 plan */
|
||||
{ 4, 1, BP_CAPS }, /* Capacites pour 4 plans */
|
||||
{ 8, 1, BP_CAPS }, /* Capacites pour 8 plans */
|
||||
{ 16, 1, TC_CAPS }, /* Capacites pour 16 plans */
|
||||
{ 32, 1, TC_CAPS }, /* Capacites pour 32 plans */
|
||||
{ 0, 0, 0UL } /* Fin de la liste des capacites */
|
||||
},
|
||||
} ;
|
||||
|
||||
VAPI* Vapi = NULL ;
|
||||
|
||||
/* Petite macro de verification pour VAPI */
|
||||
#define CHECK_VAPI(vapi) if ( (vapi == NULL) || (vapi->Header.Version < 0x0109) ) return ELDV_BADVAPIVERSION ;
|
||||
|
||||
|
||||
/*
|
||||
* Fonctions de la librairie
|
||||
*/
|
||||
|
||||
LDV_INFOS* cdecl GetLDVCapabilities(VAPI* vapi)
|
||||
{
|
||||
Vapi = vapi ;
|
||||
|
||||
return( &LdvInfos ) ;
|
||||
}
|
||||
|
||||
#pragma warn -par
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE* in, LDV_PARAMS* params, LDV_IMAGE* out)
|
||||
{
|
||||
return ELDV_NOERROR ;
|
||||
}
|
||||
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE* in, LDV_PARAMS* params, LDV_IMAGE* out)
|
||||
{
|
||||
LDV_STATUS status ;
|
||||
short method, param, out_planes ;
|
||||
|
||||
CHECK_VAPI( Vapi ) ;
|
||||
|
||||
method = params->Param[0].s ;
|
||||
param = params->Param[1].s ;
|
||||
out_planes = params->Param[2].s ;
|
||||
if ( out_planes <= 0 )
|
||||
{
|
||||
SCREEN_INFO sinfo ;
|
||||
|
||||
Vapi->CoGetScreenInfo( &sinfo ) ;
|
||||
out_planes = sinfo.NPlanes ;
|
||||
}
|
||||
if ( (out_planes != 1) && (out_planes != 4) && (out_planes != 8) && (out_planes != 16) && (out_planes != 32) )
|
||||
{
|
||||
if ( out_planes > 32 ) out_planes = 32 ;
|
||||
else if ( out_planes > 14 ) out_planes = 16 ; /* TC15 or TC16 */
|
||||
else if ( out_planes > 8 ) out_planes = 8 ;
|
||||
else if ( out_planes > 4 ) out_planes = 4 ;
|
||||
else out_planes = 1 ;
|
||||
if ( Vapi->LoDoLog ) Vapi->LoDoLog( LL_INFO, "LDVDither: nplanes %d not supported, changed to %d", params->Param[2].s, out_planes ) ;
|
||||
}
|
||||
out->Raster.fd_nplanes = out_planes ;
|
||||
|
||||
status = (LDV_STATUS) Vapi->ImDither( method, param, in, out ) ;
|
||||
if ( status != 0 )
|
||||
{
|
||||
if ( Vapi->LoDoLog ) Vapi->LoDoLog( LL_WARNING, "LDVDither: ImDither returned %d", status ) ;
|
||||
status = ELDV_GENERALFAILURE ;
|
||||
}
|
||||
|
||||
return status ;
|
||||
}
|
||||
|
||||
LDV_STATUS cdecl Preview(LDV_IMAGE* in, LDV_PARAMS* params, LDV_IMAGE* out)
|
||||
{
|
||||
return( Run( in, params, out ) ) ;
|
||||
}
|
||||
#pragma warn +par
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ldg_init( Ldg ) ;
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
BIN
tools/vision/ldv/src/dither/dither.ldv
Normal file
BIN
tools/vision/ldv/src/dither/dither.ldv
Normal file
Binary file not shown.
13
tools/vision/ldv/src/dither/dither.prj
Normal file
13
tools/vision/ldv/src/dither/dither.prj
Normal file
@@ -0,0 +1,13 @@
|
||||
DITHER.LDV
|
||||
.C [ ]
|
||||
.S [ ]
|
||||
.L [ ]
|
||||
=
|
||||
pcstart.o
|
||||
DITHER.C
|
||||
pcgemlib.lib
|
||||
pcstdlib.lib
|
||||
pctoslib.lib
|
||||
pcfltlib.lib
|
||||
..\..\ldg.lib
|
||||
..\..\mt_aes.lib
|
||||
BIN
tools/vision/ldv/src/dither/testplan.xlsx
Normal file
BIN
tools/vision/ldv/src/dither/testplan.xlsx
Normal file
Binary file not shown.
222
tools/vision/ldv/src/gamma/gamma.c
Normal file
222
tools/vision/ldv/src/gamma/gamma.c
Normal file
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
*
|
||||
*
|
||||
* Version PureC / Gcc
|
||||
*/
|
||||
|
||||
#define PCGEMLIB 1 /* mettre 1 si les utilisateurs de Pure C
|
||||
* utilise les librairies GEM Pure C */
|
||||
|
||||
/* Fichiers headers */
|
||||
|
||||
#include <portab.h>
|
||||
#if PCGEMLIB
|
||||
#include <aes.h>
|
||||
#include <vdi.h>
|
||||
#else
|
||||
#include <aesbind.h>
|
||||
#include <vdibind.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "..\..\ldg.h"
|
||||
#include "..\..\vapi.h"
|
||||
#include "..\..\ldv.h"
|
||||
#include "..\..\mt_aes.h"
|
||||
|
||||
/* Prototypages */
|
||||
LDV_INFOS * cdecl GetLDVCapabilities(VAPI *vapi) ;
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
LDV_STATUS cdecl Preview(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
|
||||
/* Variables globales */
|
||||
PROC Proc[] = {
|
||||
"GetLDVCapabilities", "Capacit<EFBFBD>s du LDV", (void *)GetLDVCapabilities,
|
||||
"PreRun", "Init du Run", (void *)PreRun,
|
||||
"Run", "Fonction du LDV", (void *)Run,
|
||||
"Preview", "Pre-Visu", (void *)Preview,
|
||||
} ;
|
||||
|
||||
char Info[] = "LDV";
|
||||
|
||||
LDGLIB Ldg[] = {
|
||||
0x0101, /* version de la lib, recommand<6E> */
|
||||
4, /* nombre de fonction dans la lib */
|
||||
Proc, /* Pointeurs vers nos fonctions */
|
||||
Info, /* Information sur la lib */
|
||||
0x0, /* Flags de la lib, obligatoire */
|
||||
NULL, /* Fermeture, liberation de VDIHandle */
|
||||
};
|
||||
|
||||
#define BP_CAPS (LDVF_SPECFORMAT | LDVF_OPINPLACE | LDVF_SUPPORTPREVIEW | LDVF_AFFECTPALETTE | LDVF_REALTIMEPARAMS)
|
||||
#define TC_CAPS (LDVF_SPECFORMAT | LDVF_OPINPLACE | LDVF_SUPPORTPREVIEW | LDVF_SUPPORTPROG | LDVF_SUPPORTCANCEL | LDVF_REALTIMEPARAMS)
|
||||
|
||||
LDV_INFOS LdvInfos = {
|
||||
(short) sizeof(LDV_INFOS), /* Taille de cette structure */
|
||||
TLDV_MODIFYIMG, /* Type du LDV */
|
||||
"Jean Lusetti", /* Auteurs */
|
||||
{
|
||||
{ 1, 1, BP_CAPS }, /* Capacites pour 1 plan */
|
||||
{ 2, 2, BP_CAPS }, /* Capacites pour 2 plans */
|
||||
{ 4, 4, BP_CAPS }, /* Capacites pour 4 plans */
|
||||
{ 8, 8, BP_CAPS }, /* Capacites pour 8 plans */
|
||||
{ 16, 16, TC_CAPS }, /* Capacites pour 16 plans */
|
||||
{ 32, 32, TC_CAPS }, /* Capacites pour 32 plans */
|
||||
{ 0, 0, 0UL } /* Fin de la liste des capacites */
|
||||
},
|
||||
} ;
|
||||
|
||||
VAPI *Vapi = NULL ;
|
||||
double gamma_rgb = 100.0 ;
|
||||
double gamma_red = -1.0 ;
|
||||
double gamma_green = -1.0 ;
|
||||
double gamma_blue = -1.0 ;
|
||||
|
||||
unsigned char RedRemap[256] ; /* Tables de reaffectation des couleurs en True Color */
|
||||
unsigned char GreenRemap[256] ;
|
||||
unsigned char BlueRemap[256] ;
|
||||
|
||||
#define CHECK_VAPI(vapi) if ( (vapi == NULL ) || (vapi->Header.Version < 0x103) ) return( ELDV_BADVAPIVERSION ) ;
|
||||
|
||||
/*
|
||||
* Fonctions de la librairie
|
||||
*/
|
||||
|
||||
LDV_INFOS * cdecl GetLDVCapabilities(VAPI *vapi)
|
||||
{
|
||||
Vapi = vapi ;
|
||||
|
||||
return( &LdvInfos ) ;
|
||||
}
|
||||
|
||||
#pragma warn -par
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
return ELDV_NOERROR ;
|
||||
}
|
||||
|
||||
double GammaFunc(double val, double val_max, double gamma)
|
||||
{
|
||||
return( val_max * pow( val/val_max, gamma ) ) ;
|
||||
}
|
||||
|
||||
void ChangeColors(double gamma, unsigned char *tab, unsigned short nb_bits)
|
||||
{
|
||||
unsigned char *pnew_val = tab ;
|
||||
double max_val = (double) ((1 << nb_bits) - 1) ;
|
||||
unsigned short i ;
|
||||
|
||||
for ( i = 0; i <= max_val; i++, pnew_val++ )
|
||||
*pnew_val = (short) ( 0.5 + GammaFunc( i, max_val, gamma ) ) ;
|
||||
}
|
||||
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
LDV_PALETTE *vdi_palette = &in->Palette ;
|
||||
VDI_ELEMENTPAL *vdi_epal ;
|
||||
double rgamma, ggamma, bgamma ;
|
||||
short vdi_index ;
|
||||
short cancel = 0 ;
|
||||
|
||||
if ( (params->Param[0].s / 100.0) != gamma_rgb )
|
||||
{
|
||||
gamma_rgb = params->Param[0].s / 100.0 ;
|
||||
params->Param[1].s = params->Param[0].s ;
|
||||
params->Param[2].s = params->Param[0].s ;
|
||||
params->Param[3].s = params->Param[0].s ;
|
||||
}
|
||||
|
||||
rgamma = params->Param[1].s / 100.0 ;
|
||||
ggamma = params->Param[2].s / 100.0 ;
|
||||
bgamma = params->Param[3].s / 100.0 ;
|
||||
if ( in->Raster.fd_nplanes <= 8 )
|
||||
{
|
||||
if ( vdi_palette == NULL ) return ELDV_GENERALFAILURE ;
|
||||
vdi_epal = vdi_palette->Pal ;
|
||||
if ( vdi_epal == NULL ) return ELDV_GENERALFAILURE ;
|
||||
for ( vdi_index = 0; vdi_index < vdi_palette->NbColors; vdi_index++, vdi_epal++ )
|
||||
{
|
||||
vdi_epal->Red = (short) ( 0.5 + GammaFunc( vdi_epal->Red, 1000.0, rgamma ) ) ;
|
||||
if ( ggamma == rgamma ) vdi_epal->Green = vdi_epal->Red ;
|
||||
else vdi_epal->Green = (short) ( 0.5 + GammaFunc( vdi_epal->Green, 1000.0, ggamma ) ) ;
|
||||
if ( bgamma == rgamma ) vdi_epal->Blue = vdi_epal->Red ;
|
||||
else vdi_epal->Blue = (short) ( 0.5 + GammaFunc( vdi_epal->Blue, 1000.0, bgamma ) ) ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
REMAP_COLORS rc ;
|
||||
MFDB *img = &in->Raster ;
|
||||
long *pt_line32, nb_pts_in_line ;
|
||||
short *pt_line16, y, pc, is_15bits ;
|
||||
unsigned short nb_bits_red=8, nb_bits_green=8, nb_bits_blue=8 ; /* Sur 32 bits par defaut */
|
||||
|
||||
CHECK_VAPI(Vapi) ;
|
||||
|
||||
rc.red = RedRemap ;
|
||||
rc.green = GreenRemap ;
|
||||
rc.blue = BlueRemap ;
|
||||
rc.nb_pts = (long) (1 + params->x2 - params->x1) ;
|
||||
is_15bits = Vapi->RaIs15Bits() ;
|
||||
if ( img->fd_nplanes == 16 )
|
||||
{
|
||||
nb_bits_red = 5 ;
|
||||
nb_bits_green = is_15bits ? 5:6 ;
|
||||
nb_bits_blue = 5 ;
|
||||
}
|
||||
/* Remet a jour les precalculs de pourcentage sur les composantes si necessaire */
|
||||
if ( rgamma != gamma_red ) ChangeColors( rgamma, RedRemap, nb_bits_red ) ;
|
||||
if ( ggamma != gamma_green ) ChangeColors( ggamma, GreenRemap, nb_bits_green ) ;
|
||||
if ( bgamma != gamma_blue ) ChangeColors( bgamma, BlueRemap, nb_bits_blue ) ;
|
||||
|
||||
nb_pts_in_line = ALIGN16(img->fd_w) ;
|
||||
pt_line16 = (short *) img->fd_addr ;
|
||||
pt_line16 += (long)(params->y1) * nb_pts_in_line ;
|
||||
pt_line16 += params->x1 ;
|
||||
pt_line32 = (long *) img->fd_addr ;
|
||||
pt_line32 += (long)(params->y1) * nb_pts_in_line ;
|
||||
pt_line32 += params->x1 ;
|
||||
for ( y = params->y1; !cancel && (y <= params->y2); y++ )
|
||||
{
|
||||
if ( img->fd_nplanes == 16 )
|
||||
{
|
||||
rc.pt_img = pt_line16 ;
|
||||
pt_line16 += nb_pts_in_line ;
|
||||
if ( is_15bits ) Vapi->RaTC15RemapColors( &rc ) ;
|
||||
else Vapi->RaTC16RemapColors( &rc ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
rc.pt_img = pt_line32 ;
|
||||
pt_line32 += nb_pts_in_line ;
|
||||
Vapi->RaTC32RemapColors( &rc ) ;
|
||||
}
|
||||
if ( ( y & 0x0F ) == 0x0F )
|
||||
{
|
||||
pc = (short) ( ( 100L * (long)(y - params->y1) ) / (long)(params->y2 - params->y1) ) ;
|
||||
cancel = Vapi->PrSetProgEx( pc ) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
gamma_red = rgamma ;
|
||||
gamma_green = ggamma ;
|
||||
gamma_blue = bgamma ;
|
||||
|
||||
return( cancel ? ELDV_CANCELLED : ELDV_NOERROR ) ;
|
||||
}
|
||||
|
||||
LDV_STATUS cdecl Preview(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
return( Run( in, params, out ) ) ;
|
||||
}
|
||||
#pragma warn +par
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ldg_init( Ldg ) ;
|
||||
|
||||
return( 0 ) ;
|
||||
}
|
||||
BIN
tools/vision/ldv/src/gamma/gamma.ldv
Normal file
BIN
tools/vision/ldv/src/gamma/gamma.ldv
Normal file
Binary file not shown.
13
tools/vision/ldv/src/gamma/gamma.prj
Normal file
13
tools/vision/ldv/src/gamma/gamma.prj
Normal file
@@ -0,0 +1,13 @@
|
||||
GAMMA.LDV
|
||||
.C [ ]
|
||||
.S [ ]
|
||||
.L [ ]
|
||||
=
|
||||
pcstart.o
|
||||
GAMMA.C
|
||||
pcgemlib.lib
|
||||
pcstdlib.lib
|
||||
pctoslib.lib
|
||||
pcfltlib.lib
|
||||
..\..\ldg.lib
|
||||
..\..\mt_aes.lib
|
||||
173
tools/vision/ldv/src/genimg/genimg.c
Normal file
173
tools/vision/ldv/src/genimg/genimg.c
Normal file
@@ -0,0 +1,173 @@
|
||||
#define PCGEMLIB 1 /* Set to 1 if PureC is used */
|
||||
|
||||
#if PCGEMLIB
|
||||
#include <aes.h>
|
||||
#include <vdi.h>
|
||||
#else
|
||||
#include <aesbind.h>
|
||||
#include <vdibind.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "..\..\ldg.h"
|
||||
#include "..\..\vapi.h"
|
||||
#include "..\..\ldv.h"
|
||||
|
||||
/* Prototypes */
|
||||
LDV_INFOS* cdecl GetLDVCapabilities(VAPI* vapi) ;
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE* in, LDV_PARAMS* params, LDV_IMAGE* out) ;
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE* in, LDV_PARAMS* params, LDV_IMAGE* out) ;
|
||||
LDV_STATUS cdecl Preview(LDV_IMAGE* in, LDV_PARAMS* params, LDV_IMAGE* out) ;
|
||||
|
||||
/* Variables globales */
|
||||
PROC Proc[] = {
|
||||
"GetLDVCapabilities", "LDV capabilities", (void *)GetLDVCapabilities,
|
||||
"PreRun", "Run initialization", (void *)PreRun,
|
||||
"Run", "LDV operation", (void *)Run,
|
||||
"Preview", "Pre-Visu", (void *)Preview,
|
||||
} ;
|
||||
|
||||
char Info[] = "LDV" ;
|
||||
|
||||
LDGLIB Ldg[] = {
|
||||
0x0100, /* Lib version */
|
||||
4, /* Number of functions in lib */
|
||||
Proc, /* Pointers to our functions */
|
||||
Info, /* Lib information */
|
||||
0x0, /* Lib flags */
|
||||
NULL, /* On exit, free VDI handle (unused) */
|
||||
} ;
|
||||
|
||||
#define CAPS (LDVF_ATARIFORMAT | LDVF_SUPPORTPREVIEW | LDVF_OPINPLACE | LDVF_NOSELECTION)
|
||||
|
||||
LDV_INFOS LdvInfos = {
|
||||
(short) sizeof(LDV_INFOS), /* size of this structure */
|
||||
TLDV_MODIFYIMG, /* LDV Type */
|
||||
"Jean Lusetti", /* Authors */
|
||||
{
|
||||
{ 1, 1, CAPS }, /* 1 bitplane capabilities */
|
||||
{ 2, 2, CAPS }, /* 2 bitplane capabilities */
|
||||
{ 4, 4, CAPS }, /* 4 bitplane capabilities */
|
||||
{ 8, 8, CAPS }, /* 8 bitplane capabilities */
|
||||
{ 16, 16, CAPS }, /* 16 bitplane capabilities */
|
||||
/* Not yet { 24, 24, CAPS }, */
|
||||
{ 32, 32, CAPS }, /* 32 bitplane capabilities */
|
||||
{ 0, 0, 0UL } /* End of this list */
|
||||
},
|
||||
} ;
|
||||
|
||||
VAPI* Vapi = NULL ;
|
||||
|
||||
|
||||
LDV_INFOS* cdecl GetLDVCapabilities(VAPI* vapi)
|
||||
{
|
||||
Vapi = vapi ;
|
||||
|
||||
return( &LdvInfos ) ;
|
||||
}
|
||||
|
||||
static LDV_STATUS GenMaxColors(MFDB* img)
|
||||
{
|
||||
unsigned long nb = ((unsigned long)img->fd_wdwidth << 4) * (unsigned long) img->fd_h ;
|
||||
unsigned long n ;
|
||||
|
||||
if ( img->fd_nplanes <= 8 )
|
||||
{
|
||||
MFDB tmp ;
|
||||
unsigned char* pt_img ;
|
||||
unsigned char* pt_after_img ;
|
||||
unsigned char indexes[256] ; /* Array of indexes: 256 as max for 8 bitplanes */
|
||||
short bitplanes[128] ; /* Transformation into bitplanes Atari */
|
||||
unsigned long so_line ;
|
||||
unsigned short ncol = 1 << img->fd_nplanes ;
|
||||
|
||||
memset( &tmp, 0, sizeof(MFDB) ) ;
|
||||
tmp.fd_addr = bitplanes ; tmp.fd_nplanes = img->fd_nplanes ;
|
||||
tmp.fd_w = ncol ; tmp.fd_h = 1 ;
|
||||
for ( n = 0; n < 256; n++ ) indexes[n] = (unsigned char) n ;
|
||||
Vapi->RaInd2RasterInit( &tmp, 256 ) ;
|
||||
Vapi->RaInd2Raster( indexes, 256 ) ;
|
||||
/* Fill in img MFDB with repetition of bitplanes buffer */
|
||||
pt_img = img->fd_addr ;
|
||||
so_line = 16UL*img->fd_wdwidth ;
|
||||
so_line *= (unsigned long)img->fd_nplanes ;
|
||||
so_line >>= 3 ; /* Size of a line in bytes */
|
||||
pt_after_img = pt_img + so_line * (unsigned long)img->fd_h ;
|
||||
Vapi->LoDoLog(LL_DEBUG, "genimg.ldv: pt_after_img=%p", pt_after_img ) ;
|
||||
while ( pt_img < pt_after_img-256 )
|
||||
{
|
||||
Vapi->LoDoLog(LL_DEBUG, "genimg.ldv: pt_img=%p", pt_img ) ;
|
||||
memcpy( pt_img, bitplanes, 256 ) ;
|
||||
pt_img += 256 ;
|
||||
}
|
||||
}
|
||||
else if ( img->fd_nplanes == 16 )
|
||||
{
|
||||
unsigned short* pt = img->fd_addr ;
|
||||
unsigned short inc = (unsigned short) (nb / (1UL << 16)) ;
|
||||
unsigned short val = 0 ;
|
||||
|
||||
if ( inc < 1 ) inc = 1 ;
|
||||
|
||||
for ( n = 0; n < nb; n++ )
|
||||
{
|
||||
*pt++ = val ;
|
||||
val += inc ;
|
||||
}
|
||||
}
|
||||
else if ( img->fd_nplanes == 32 )
|
||||
{
|
||||
unsigned long* pt = img->fd_addr ;
|
||||
unsigned long inc = nb / (1UL << 24) ;
|
||||
unsigned long val = 0 ;
|
||||
|
||||
if ( inc < 1 ) inc = 1 ;
|
||||
inc <<= 8 ;
|
||||
|
||||
for ( n = 0; n < nb; n++ )
|
||||
{
|
||||
*pt++ = val ;
|
||||
val += inc ;
|
||||
}
|
||||
}
|
||||
|
||||
return ELDV_NOERROR ;
|
||||
}
|
||||
|
||||
#pragma warn -par
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE* in, LDV_PARAMS* params, LDV_IMAGE* out)
|
||||
{
|
||||
return ELDV_NOERROR ;
|
||||
}
|
||||
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE* in, LDV_PARAMS* params, LDV_IMAGE* out)
|
||||
{
|
||||
LDV_STATUS status ;
|
||||
|
||||
switch( params->Param[0].s )
|
||||
{
|
||||
case 1: /* Generate an image with as many colors as possible */
|
||||
status = GenMaxColors( &in->Raster ) ;
|
||||
break ;
|
||||
|
||||
default: status = ELDV_INVALIDPARAMETER ;
|
||||
break ;
|
||||
}
|
||||
|
||||
return status ;
|
||||
}
|
||||
#pragma warn +par
|
||||
|
||||
LDV_STATUS cdecl Preview(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
return( Run( in, params, out ) ) ;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ldg_init( Ldg ) ;
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
BIN
tools/vision/ldv/src/genimg/genimg.ldv
Normal file
BIN
tools/vision/ldv/src/genimg/genimg.ldv
Normal file
Binary file not shown.
12
tools/vision/ldv/src/genimg/genimg.prj
Normal file
12
tools/vision/ldv/src/genimg/genimg.prj
Normal file
@@ -0,0 +1,12 @@
|
||||
GENIMG.LDV
|
||||
.C [ ]
|
||||
.S [ ]
|
||||
.L [ ]
|
||||
=
|
||||
pcstart.o
|
||||
GENIMG.C
|
||||
pcgemlib.lib
|
||||
pcstdlib.lib
|
||||
pctoslib.lib
|
||||
..\..\ldg.lib
|
||||
..\..\mt_aes.lib
|
||||
156
tools/vision/ldv/src/invert/invert.c
Normal file
156
tools/vision/ldv/src/invert/invert.c
Normal file
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
*
|
||||
*
|
||||
* Version PureC / Gcc
|
||||
*/
|
||||
|
||||
#define PCGEMLIB 1 /* mettre 1 si les utilisateurs de Pure C
|
||||
* utilise les librairies GEM Pure C */
|
||||
|
||||
/* Fichiers headers */
|
||||
#include <portab.h>
|
||||
#if PCGEMLIB
|
||||
#include <aes.h>
|
||||
#include <vdi.h>
|
||||
#else
|
||||
#include <aesbind.h>
|
||||
#include <vdibind.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include "..\..\ldg.h"
|
||||
#include "..\..\vapi.h"
|
||||
#include "..\..\ldv.h"
|
||||
#include "..\..\mt_aes.h"
|
||||
|
||||
/* Prototypages */
|
||||
LDV_INFOS * cdecl GetLDVCapabilities(VAPI *vapi) ;
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
LDV_STATUS cdecl Preview(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
|
||||
void OnClose(void) ;
|
||||
|
||||
/* Variables globales */
|
||||
PROC Proc[] = {
|
||||
"GetLDVCapabilities", "Capacit<EFBFBD>s du LDV", (void *)GetLDVCapabilities,
|
||||
"PreRun", "Init du Run", (void *)PreRun,
|
||||
"Run", "Fonction du LDV", (void *)Run,
|
||||
"Preview", "Pre-Visu", (void *)Preview,
|
||||
} ;
|
||||
|
||||
char Info[] = "LDV";
|
||||
|
||||
LDGLIB Ldg[] = {
|
||||
0x0101, /* version de la lib, recommand<6E> */
|
||||
4, /* nombre de fonction dans la lib */
|
||||
Proc, /* Pointeurs vers nos fonctions */
|
||||
Info, /* Information sur la lib */
|
||||
0x0, /* Flags de la lib, obligatoire */
|
||||
OnClose, /* Fermeture, liberation de VDIHandle */
|
||||
} ;
|
||||
/* Enlever le commentaire de la ligne suivante */
|
||||
/* Pour que le LDV ne supporte plus la */
|
||||
/* Transformation sur place (but uniquement */
|
||||
/* Pedagogique ! */
|
||||
/*#define NOTOPINPLACE*/
|
||||
#ifndef NOTOPINPLACE
|
||||
#define CAPS (LDVF_SPECFORMAT | LDVF_SUPPORTPREVIEW | LDVF_OPINPLACE)
|
||||
#else
|
||||
#define CAPS (LDVF_SPECFORMAT | LDVF_SUPPORTPREVIEW)
|
||||
#endif
|
||||
|
||||
LDV_INFOS LdvInfos = {
|
||||
(short) sizeof(LDV_INFOS), /* Taille de cette structure */
|
||||
TLDV_MODIFYIMG, /* Type du LDV */
|
||||
"Jean Lusetti", /* Auteurs */
|
||||
{
|
||||
{ 1, 1, CAPS }, /* Capacites pour 1 plan */
|
||||
{ 2, 2, CAPS }, /* Capacites pour 2 plans */
|
||||
{ 4, 4, CAPS }, /* Capacites pour 4 plans */
|
||||
{ 8, 8, CAPS }, /* Capacites pour 8 plans */
|
||||
{ 16, 16, CAPS }, /* Capacites pour 16 plans */
|
||||
{ 32, 32, CAPS }, /* Capacites pour 24 plans */
|
||||
{ 24, 24, CAPS }, /* Capacites pour 32 plans */
|
||||
{ 0, 0, 0UL } /* Fin de la liste des capacites */
|
||||
},
|
||||
} ;
|
||||
|
||||
VAPI *Vapi = NULL ;
|
||||
int VDIHandle = -1 ;
|
||||
|
||||
void OnClose(void)
|
||||
{
|
||||
if ( VDIHandle != -1 ) v_clsvwk( VDIHandle ) ;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fonctions de la librairie
|
||||
*/
|
||||
|
||||
LDV_INFOS * cdecl GetLDVCapabilities(VAPI *vapi)
|
||||
{
|
||||
Vapi = vapi ;
|
||||
|
||||
return( &LdvInfos ) ;
|
||||
}
|
||||
|
||||
int vdihandle(void)
|
||||
{
|
||||
int work_in[11], work_out[57], i ;
|
||||
|
||||
for ( i = 0; i < 10; work_in[i++] = 1 ) ;
|
||||
work_in[10] = 2 ;
|
||||
v_opnvwk( work_in, &i, work_out ) ;
|
||||
|
||||
return( i ) ;
|
||||
}
|
||||
|
||||
#pragma warn -par
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
out->Raster.fd_w = in->Raster.fd_w ;
|
||||
out->Raster.fd_h = in->Raster.fd_h ;
|
||||
|
||||
return( ELDV_NOERROR ) ;
|
||||
}
|
||||
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
int xy[8] ;
|
||||
|
||||
if ( VDIHandle == -1 ) VDIHandle = vdihandle() ;
|
||||
#ifndef NOTOPINPLACE
|
||||
{
|
||||
/* Recopie le raster source vers la destination */
|
||||
xy[0] = xy[4] = 0 ;
|
||||
xy[1] = xy[5] = 0 ;
|
||||
xy[2] = xy[6] = in->Raster.fd_w - 1 ;
|
||||
xy[3] = xy[7] = in->Raster.fd_h - 1 ;
|
||||
vro_cpyfm( VDIHandle, S_ONLY, xy, &in->Raster, &out->Raster ) ;
|
||||
}
|
||||
#endif
|
||||
|
||||
xy[0] = params->x1 ;
|
||||
xy[1] = params->y1 ;
|
||||
xy[2] = params->x2 ;
|
||||
xy[3] = params->y2 ;
|
||||
memcpy( &xy[4], xy, 4*sizeof(int) ) ;
|
||||
|
||||
vro_cpyfm( VDIHandle, D_INVERT, xy, &out->Raster, &out->Raster ) ;
|
||||
|
||||
return( ELDV_NOERROR ) ;
|
||||
}
|
||||
|
||||
LDV_STATUS cdecl Preview(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
return( Run( in, params, out ) ) ;
|
||||
}
|
||||
#pragma warn +par
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ldg_init( Ldg ) ;
|
||||
return( 0 ) ;
|
||||
}
|
||||
BIN
tools/vision/ldv/src/invert/invert.ldv
Normal file
BIN
tools/vision/ldv/src/invert/invert.ldv
Normal file
Binary file not shown.
12
tools/vision/ldv/src/invert/invert.prj
Normal file
12
tools/vision/ldv/src/invert/invert.prj
Normal file
@@ -0,0 +1,12 @@
|
||||
invert.ldv
|
||||
.C [ ]
|
||||
.S [ ]
|
||||
.L [ ]
|
||||
=
|
||||
pcstart.o
|
||||
invert.c
|
||||
pcgemlib.lib
|
||||
pcstdlib.lib
|
||||
pctoslib.lib
|
||||
..\..\ldg.lib
|
||||
..\..\mt_aes.lib
|
||||
223
tools/vision/ldv/src/light/light.c
Normal file
223
tools/vision/ldv/src/light/light.c
Normal file
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
*
|
||||
*
|
||||
* Version PureC / Gcc
|
||||
*/
|
||||
|
||||
#define PCGEMLIB 1 /* mettre 1 si les utilisateurs de Pure C
|
||||
* utilise les librairies GEM Pure C */
|
||||
|
||||
/* Fichiers headers */
|
||||
|
||||
#include <portab.h>
|
||||
#if PCGEMLIB
|
||||
#include <aes.h>
|
||||
#include <vdi.h>
|
||||
#else
|
||||
#include <aesbind.h>
|
||||
#include <vdibind.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include "..\..\ldg.h"
|
||||
#include "..\..\vapi.h"
|
||||
#include "..\..\ldv.h"
|
||||
#include "..\..\mt_aes.h"
|
||||
|
||||
/* Prototypages */
|
||||
LDV_INFOS * cdecl GetLDVCapabilities(VAPI *vapi) ;
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
LDV_STATUS cdecl Preview(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
|
||||
/* Variables globales */
|
||||
PROC Proc[] = {
|
||||
"GetLDVCapabilities", "Capacit<EFBFBD>s du LDV", (void *)GetLDVCapabilities,
|
||||
"PreRun", "Init du Run", (void *)PreRun,
|
||||
"Run", "Fonction du LDV", (void *)Run,
|
||||
"Preview", "Pre-Visu", (void *)Preview,
|
||||
} ;
|
||||
|
||||
char Info[] = "LDV";
|
||||
|
||||
LDGLIB Ldg[] = {
|
||||
0x0102, /* version de la lib, recommand<6E> */
|
||||
4, /* nombre de fonction dans la lib */
|
||||
Proc, /* Pointeurs vers nos fonctions */
|
||||
Info, /* Information sur la lib */
|
||||
0x0, /* Flags de la lib, obligatoire */
|
||||
NULL, /* Fermeture, liberation de VDIHandle */
|
||||
};
|
||||
|
||||
#define BP_CAPS (LDVF_SPECFORMAT | LDVF_OPINPLACE | LDVF_SUPPORTPREVIEW | LDVF_AFFECTPALETTE | LDVF_REALTIMEPARAMS)
|
||||
#define TC_CAPS (LDVF_SPECFORMAT | LDVF_OPINPLACE | LDVF_SUPPORTPREVIEW | LDVF_SUPPORTPROG | LDVF_SUPPORTCANCEL | LDVF_REALTIMEPARAMS)
|
||||
|
||||
LDV_INFOS LdvInfos = {
|
||||
(short) sizeof(LDV_INFOS), /* Taille de cette structure */
|
||||
TLDV_MODIFYIMG, /* Type du LDV */
|
||||
"Jean Lusetti", /* Auteurs */
|
||||
{
|
||||
{ 1, 1, BP_CAPS }, /* Capacites pour 1 plan */
|
||||
{ 2, 2, BP_CAPS }, /* Capacites pour 2 plans */
|
||||
{ 4, 4, BP_CAPS }, /* Capacites pour 4 plans */
|
||||
{ 8, 8, BP_CAPS }, /* Capacites pour 8 plans */
|
||||
{ 16, 16, TC_CAPS }, /* Capacites pour 16 plans */
|
||||
{ 32, 32, TC_CAPS }, /* Capacites pour 32 plans */
|
||||
{ 0, 0, 0UL } /* Fin de la liste des capacites */
|
||||
},
|
||||
} ;
|
||||
|
||||
VAPI *Vapi = NULL ;
|
||||
short pc_rgb = 100 ;
|
||||
short pc_red = -1 ; /* Pourcentages de lumiere sur les comosantes rouge, verte et bleue */
|
||||
short pc_green = -1 ;
|
||||
short pc_blue = -1 ;
|
||||
|
||||
unsigned char RedRemap[256] ; /* Tables de reaffectation des couleurs en True Color */
|
||||
unsigned char GreenRemap[256] ;
|
||||
unsigned char BlueRemap[256] ;
|
||||
|
||||
#define CHECK_VAPI(vapi) if ( (vapi == NULL ) || (vapi->Header.Version < 0x103) ) return( ELDV_BADVAPIVERSION ) ;
|
||||
|
||||
/*
|
||||
* Fonctions de la librairie
|
||||
*/
|
||||
|
||||
LDV_INFOS * cdecl GetLDVCapabilities(VAPI *vapi)
|
||||
{
|
||||
Vapi = vapi ;
|
||||
|
||||
return( &LdvInfos ) ;
|
||||
}
|
||||
|
||||
#pragma warn -par
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
return( ELDV_NOERROR ) ;
|
||||
}
|
||||
|
||||
void ChangeColors(unsigned short percent, unsigned char *tab, unsigned short nb_bits)
|
||||
{
|
||||
unsigned char *pnew_val = tab ;
|
||||
unsigned short max_val = (1 << nb_bits) - 1 ;
|
||||
unsigned short val, i ;
|
||||
|
||||
for ( i = 0; i <= max_val; i++, pnew_val++ )
|
||||
{
|
||||
val = ( i * percent ) / 100 ;
|
||||
if ( val > max_val ) *pnew_val = max_val ;
|
||||
else *pnew_val = val ;
|
||||
}
|
||||
}
|
||||
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
LDV_PALETTE *vdi_palette = &in->Palette ;
|
||||
VDI_ELEMENTPAL *vdi_epal ;
|
||||
short vdi_index ;
|
||||
short cancel = 0 ;
|
||||
|
||||
if ( params->Param[0].s != pc_rgb )
|
||||
{
|
||||
pc_rgb = params->Param[0].s ;
|
||||
params->Param[1].s = pc_rgb ;
|
||||
params->Param[2].s = pc_rgb ;
|
||||
params->Param[3].s = pc_rgb ;
|
||||
}
|
||||
|
||||
if ( in->Raster.fd_nplanes <= 8 )
|
||||
{
|
||||
long red_pc, green_pc, blue_pc ; /* Pour la palette */
|
||||
|
||||
if ( vdi_palette == NULL ) return( ELDV_GENERALFAILURE ) ;
|
||||
vdi_epal = vdi_palette->Pal ;
|
||||
if ( vdi_epal == NULL ) return( ELDV_GENERALFAILURE ) ;
|
||||
red_pc = (long) params->Param[1].s ;
|
||||
green_pc = (long) params->Param[2].s ;
|
||||
blue_pc = (long) params->Param[3].s ;
|
||||
for ( vdi_index = 0; vdi_index < vdi_palette->NbColors; vdi_index++, vdi_epal++ )
|
||||
{
|
||||
/* Le calcul se fait sur des entiers 32 bits pour eviter d'exploser la plage -32K...32K */
|
||||
vdi_epal->Red = (short) ( ( (long)vdi_epal->Red * red_pc ) / 100L ) ;
|
||||
if ( vdi_epal->Red > 1000 ) vdi_epal->Red = 1000 ;
|
||||
vdi_epal->Green = (short) ( ( (long)vdi_epal->Green * green_pc ) / 100L ) ; ;
|
||||
if ( vdi_epal->Green > 1000 ) vdi_epal->Green = 1000 ;
|
||||
vdi_epal->Blue = (short) ( ( (long)vdi_epal->Blue * blue_pc ) / 100L ) ; ;
|
||||
if ( vdi_epal->Blue > 1000 ) vdi_epal->Blue = 1000 ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
REMAP_COLORS rc ;
|
||||
MFDB *img = &in->Raster ;
|
||||
long *pt_line32, nb_pts_in_line ;
|
||||
short *pt_line16, y, pc, is_15bits ;
|
||||
unsigned short nb_bits_red=8, nb_bits_green=8, nb_bits_blue=8 ; /* Sur 32 bits par defaut */
|
||||
|
||||
CHECK_VAPI(Vapi) ;
|
||||
|
||||
rc.red = RedRemap ;
|
||||
rc.green = GreenRemap ;
|
||||
rc.blue = BlueRemap ;
|
||||
rc.nb_pts = (long) (1 + params->x2 - params->x1) ;
|
||||
is_15bits = Vapi->RaIs15Bits() ;
|
||||
if ( img->fd_nplanes == 16 )
|
||||
{
|
||||
nb_bits_red = 5 ;
|
||||
nb_bits_green = is_15bits ? 5:6 ;
|
||||
nb_bits_blue = 5 ;
|
||||
}
|
||||
/* Remet a jour les precalculs de pourcentage sur les composantes si necessaire */
|
||||
if ( pc_red != params->Param[1].s ) ChangeColors( (unsigned short) (params->Param[1].s), RedRemap, nb_bits_red ) ;
|
||||
if ( pc_green != params->Param[2].s ) ChangeColors( (unsigned short) (params->Param[2].s), GreenRemap, nb_bits_green ) ;
|
||||
if ( pc_blue != params->Param[3].s ) ChangeColors( (unsigned short) (params->Param[3].s), BlueRemap, nb_bits_blue ) ;
|
||||
pc_red = params->Param[1].s ;
|
||||
pc_green = params->Param[2].s ;
|
||||
pc_blue = params->Param[3].s ;
|
||||
|
||||
nb_pts_in_line = ALIGN16(img->fd_w) ;
|
||||
pt_line16 = (short *) img->fd_addr ;
|
||||
pt_line16 += (long)(params->y1) * nb_pts_in_line ;
|
||||
pt_line16 += params->x1 ;
|
||||
pt_line32 = (long *) img->fd_addr ;
|
||||
pt_line32 += (long)(params->y1) * nb_pts_in_line ;
|
||||
pt_line32 += params->x1 ;
|
||||
for ( y = params->y1; !cancel && (y <= params->y2); y++ )
|
||||
{
|
||||
if ( img->fd_nplanes == 16 )
|
||||
{
|
||||
rc.pt_img = pt_line16 ;
|
||||
pt_line16 += nb_pts_in_line ;
|
||||
if ( is_15bits ) Vapi->RaTC15RemapColors( &rc ) ;
|
||||
else Vapi->RaTC16RemapColors( &rc ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
rc.pt_img = pt_line32 ;
|
||||
pt_line32 += nb_pts_in_line ;
|
||||
Vapi->RaTC32RemapColors( &rc ) ;
|
||||
}
|
||||
if ( ( y & 0x0F ) == 0x0F )
|
||||
{
|
||||
pc = (short) ( ( 100L * (long)(y - params->y1) ) / (long)(params->y2 - params->y1) ) ;
|
||||
cancel = Vapi->PrSetProgEx( pc ) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return( cancel ? ELDV_CANCELLED : ELDV_NOERROR ) ;
|
||||
}
|
||||
|
||||
LDV_STATUS cdecl Preview(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
return( Run( in, params, out ) ) ;
|
||||
}
|
||||
#pragma warn +par
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ldg_init( Ldg ) ;
|
||||
|
||||
return( 0 ) ;
|
||||
}
|
||||
BIN
tools/vision/ldv/src/light/light.ldv
Normal file
BIN
tools/vision/ldv/src/light/light.ldv
Normal file
Binary file not shown.
13
tools/vision/ldv/src/light/light.prj
Normal file
13
tools/vision/ldv/src/light/light.prj
Normal file
@@ -0,0 +1,13 @@
|
||||
LIGHT.LDV
|
||||
.C [ ]
|
||||
.S [ ]
|
||||
.L [ ]
|
||||
=
|
||||
pcstart.o
|
||||
LIGHT.C
|
||||
pcgemlib.lib
|
||||
pcstdlib.lib
|
||||
pctoslib.lib
|
||||
pcfltlib.lib
|
||||
..\..\ldg.lib
|
||||
..\..\mt_aes.lib
|
||||
552
tools/vision/ldv/src/optimg/optimg.c
Normal file
552
tools/vision/ldv/src/optimg/optimg.c
Normal file
@@ -0,0 +1,552 @@
|
||||
/*
|
||||
*
|
||||
*
|
||||
* Version PureC / Gcc
|
||||
*/
|
||||
|
||||
#define PCGEMLIB 1 /* mettre 1 si les utilisateurs de Pure C
|
||||
* utilise les librairies GEM Pure C */
|
||||
|
||||
/* Fichiers headers */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <portab.h>
|
||||
#if PCGEMLIB
|
||||
#include <aes.h>
|
||||
#include <vdi.h>
|
||||
#else
|
||||
#include <aesbind.h>
|
||||
#include <vdibind.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "..\..\ldg.h"
|
||||
#include "..\..\vapi.h"
|
||||
#include "..\..\ldv.h"
|
||||
#include "..\..\mt_aes.h"
|
||||
|
||||
/* Prototypages */
|
||||
LDV_INFOS* cdecl GetLDVCapabilities(VAPI *vapi) ;
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
|
||||
typedef struct _ANALYSIS_DATA
|
||||
{
|
||||
/* Internal data during analysis */
|
||||
unsigned char* pixel ; /* Pixel under analysis */
|
||||
long add_pixel ; /* Offset to next pixel to analyze */
|
||||
|
||||
/* For indexes */
|
||||
short* pt_img ;
|
||||
|
||||
long npixels_sofar ;
|
||||
long npixels_add ;
|
||||
long npixels_total ;
|
||||
}
|
||||
ANALYSIS_DATA, *PANALYSIS_DATA ;
|
||||
|
||||
/* This is our structure to held image data */
|
||||
/* And analyze outcome */
|
||||
typedef struct _IMG_REPORT
|
||||
{
|
||||
/* Inputs */
|
||||
LDV_IMAGE* in ;
|
||||
char* profile ;
|
||||
char save_options[6][32] ; /* 0: 1 plane, 1: 4 planes, 2:8 planes, 3:16 planes, 4:24 planes, 5:32 planes */
|
||||
unsigned char limit_black ;
|
||||
unsigned char limit_white ;
|
||||
unsigned char diff_grey ;
|
||||
unsigned char enforce_smaller ;
|
||||
short enforce_dither ;
|
||||
short dither_method ;
|
||||
short dither_outplanes ;
|
||||
short dither_param ;
|
||||
|
||||
ANALYSIS_DATA d ;
|
||||
|
||||
/* Outcome */
|
||||
char is_dualtone ;
|
||||
char is_grey ;
|
||||
long ncolors ;
|
||||
}
|
||||
IMG_REPORT, *PIMG_REPORT ;
|
||||
|
||||
/* Variables globales */
|
||||
PROC Proc[] = {
|
||||
"GetLDVCapabilities", "LDV capabilties", (void *)GetLDVCapabilities,
|
||||
/* No preRun "PreRun", "Before Run", (void *)PreRun, */
|
||||
"Run", "LDV routine", (void *)Run,
|
||||
/* No preview "Preview", "Preview", (void *)Preview, */
|
||||
} ;
|
||||
|
||||
char Info[] = "LDV";
|
||||
|
||||
LDGLIB Ldg[] = {
|
||||
0x0102, /* version de la lib, recommand<6E> */
|
||||
2, /* nombre de fonction dans la lib */
|
||||
Proc, /* Pointeurs vers nos fonctions */
|
||||
Info, /* Information sur la lib */
|
||||
0x0, /* Flags de la lib, obligatoire */
|
||||
NULL,
|
||||
};
|
||||
|
||||
#define CAPS (LDVF_ATARIFORMAT | LDVF_OPINPLACE | LDVF_SUPPORTPROG | LDVF_SUPPORTCANCEL | LDVF_NOSELECTION | LDVF_NOCHANGE)
|
||||
|
||||
/* Note that for this LDV, no matter what is returned as #nplanes for output */
|
||||
/* As no LDV_IMAGE is returned, a file is generated */
|
||||
LDV_INFOS LdvInfos = {
|
||||
(short) sizeof(LDV_INFOS), /* Taille de cette structure */
|
||||
TLDV_MODIFYIMG, /* Type du LDV */
|
||||
"Jean Lusetti", /* Auteurs */
|
||||
{
|
||||
{ 1, 1, CAPS }, /* Capacites pour 1 plan */
|
||||
{ 4, 1, CAPS }, /* Capacites pour 4 plans */
|
||||
{ 8, 1, CAPS }, /* Capacites pour 8 plans */
|
||||
{ 16, 1, CAPS }, /* Capacites pour 16 plans */
|
||||
{ 32, 1, CAPS }, /* Capacites pour 32 plans */
|
||||
{ 0, 0, 0UL } /* Fin de la liste des capacites */
|
||||
},
|
||||
} ;
|
||||
|
||||
VAPI* Vapi = NULL ;
|
||||
|
||||
/* VAPI macro check */
|
||||
#define CHECK_VAPI(vapi) if ( (vapi == NULL) || (vapi->Header.Version < 0x0109) ) return ELDV_BADVAPIVERSION ;
|
||||
|
||||
unsigned char u5bto8b[32] ;
|
||||
unsigned char u6bto8b[64] ;
|
||||
|
||||
/*
|
||||
* Fonctions de la librairie
|
||||
*/
|
||||
|
||||
LDV_INFOS* cdecl GetLDVCapabilities(VAPI* vapi)
|
||||
{
|
||||
Vapi = vapi ;
|
||||
|
||||
return( &LdvInfos ) ;
|
||||
}
|
||||
|
||||
static void GetDefaultSaveOptions(IMG_REPORT* img_report)
|
||||
{
|
||||
strcpy( &img_report->save_options[0][0], "fmt=TIF;compression=lzw" ) ; /* 1 Plane */
|
||||
strcpy( &img_report->save_options[1][0], "fmt=TIF;compression=lzw" ) ; /* 4 Planes */
|
||||
strcpy( &img_report->save_options[2][0], "fmt=TIF;compression=lzw" ) ; /* 8 Planes */
|
||||
strcpy( &img_report->save_options[3][0], "fmt=JPG;quality=90" ) ; /* 16 Planes */
|
||||
strcpy( &img_report->save_options[4][0], "fmt=JPG;quality=90" ) ; /* 24 Planes */
|
||||
strcpy( &img_report->save_options[5][0], "fmt=JPG;quality=90" ) ; /* 32 Planes */
|
||||
}
|
||||
|
||||
static short LoadProfile(IMG_REPORT* img_report)
|
||||
{
|
||||
long profile_found = 0 ;
|
||||
short i ;
|
||||
char* path_ldv ;
|
||||
char* language ;
|
||||
char* keys[] = { "1", "4", "8", "16", "24", "32" } ;
|
||||
|
||||
if ( img_report->profile == NULL ) return -1 ;
|
||||
|
||||
path_ldv = Vapi->CoGetLDVPath() ;
|
||||
language = Vapi->CoGetCurrentLanguage() ;
|
||||
if ( path_ldv && language )
|
||||
{
|
||||
long found ;
|
||||
char filename[256] ;
|
||||
char buffer[128] ;
|
||||
|
||||
sprintf( filename, "%s\\%s\\OPTIMG.INI", path_ldv, language ) ;
|
||||
Vapi->LoDoLog(LL_INFO,"optimg.ldv: Looking into %s to find profile %s", filename, img_report->profile) ;
|
||||
for ( i = 0; i < ARRAY_SIZE(keys); i++ )
|
||||
if ( !profile_found ) profile_found = Vapi->InGetKeyFromFile( filename, img_report->profile, keys[i], &img_report->save_options[i][0] ) ;
|
||||
if ( !profile_found )
|
||||
{
|
||||
sprintf( filename, "%s\\OPTIMG.INI", path_ldv ) ;
|
||||
Vapi->LoDoLog(LL_INFO,"optimg.ldv: Looking into %s to find profile %s", filename, img_report->profile) ;
|
||||
Vapi->LoDoLog(LL_INFO,"optimg.ldv: Looking into non language specific %s to find profile %s ...", filename, img_report->profile) ;
|
||||
for ( i = 0; i < ARRAY_SIZE(keys); i++ )
|
||||
profile_found = Vapi->InGetKeyFromFile( filename, img_report->profile, keys[i], &img_report->save_options[i][0] ) ;
|
||||
}
|
||||
found = Vapi->InGetKeyFromFile( filename, img_report->profile, "limit_black", buffer ) ;
|
||||
if ( found ) img_report->limit_black = (unsigned char) atoi( buffer ) ;
|
||||
else img_report->limit_black = 0 ;
|
||||
found = Vapi->InGetKeyFromFile( filename, img_report->profile, "limit_white", buffer ) ;
|
||||
if ( found ) img_report->limit_white = (unsigned char) atoi( buffer ) ;
|
||||
else img_report->limit_white = 255 ;
|
||||
found = Vapi->InGetKeyFromFile( filename, img_report->profile, "diff_grey", buffer ) ;
|
||||
if ( found ) img_report->diff_grey = (unsigned char) atoi( buffer ) ;
|
||||
else img_report->diff_grey = 0 ;
|
||||
found = Vapi->InGetKeyFromFile( filename, img_report->profile, "enforce_smaller", buffer ) ;
|
||||
if ( found ) img_report->enforce_smaller = (unsigned char) atoi( buffer ) ;
|
||||
else img_report->enforce_smaller = 0 ;
|
||||
|
||||
/* Keys to enforce dither method */
|
||||
found = Vapi->InGetKeyFromFile( filename, img_report->profile, "enforce_dither", buffer ) ;
|
||||
if ( found ) img_report->enforce_dither = (short) atoi( buffer ) ;
|
||||
else img_report->enforce_dither = 0 ;
|
||||
if ( img_report->enforce_dither )
|
||||
{
|
||||
found = Vapi->InGetKeyFromFile( filename, img_report->profile, "dither_method", buffer ) ;
|
||||
if ( found ) img_report->dither_method = (short) atoi( buffer ) ;
|
||||
else img_report->dither_method = 0 ;
|
||||
found = Vapi->InGetKeyFromFile( filename, img_report->profile, "dither_outplanes", buffer ) ;
|
||||
if ( found ) img_report->dither_outplanes = (short) atoi( buffer ) ;
|
||||
else img_report->dither_outplanes = 0 ;
|
||||
found = Vapi->InGetKeyFromFile( filename, img_report->profile, "dither_param", buffer ) ;
|
||||
if ( found ) img_report->dither_param = (short) atoi( buffer ) ;
|
||||
else img_report->dither_param = 0 ;
|
||||
}
|
||||
}
|
||||
else Vapi->LoDoLog(LL_WARNING,"optimg.ldv: Can't access LDV (%s) or language path (%s)!", path_ldv, language) ;
|
||||
|
||||
return !profile_found ; /* 0 if found */
|
||||
}
|
||||
|
||||
static long md_grey(long abs_diff, long max_diff)
|
||||
{
|
||||
if ( abs_diff > max_diff ) return abs_diff ;
|
||||
else return max_diff ;
|
||||
}
|
||||
|
||||
static void fast_isgrey(IMG_REPORT* img_report)
|
||||
{
|
||||
/* Quick check to see if all pixels in diagonal are grey */
|
||||
MFDB* in = &img_report->in->Raster ;
|
||||
long add_pixel = (in->fd_nplanes >> 3) ;
|
||||
unsigned char* pixel = in->fd_addr ;
|
||||
unsigned short pix16, diff_grey = img_report->diff_grey ;
|
||||
short h ;
|
||||
unsigned char r, g, b ;
|
||||
|
||||
add_pixel += add_pixel*16L*(long)in->fd_wdwidth ; /* Offset to next pixel in diagonal */
|
||||
for( h = 0 ; img_report->is_grey && (h < in->fd_h-1); h++, pixel += add_pixel )
|
||||
{
|
||||
if ( in->fd_nplanes == 16 )
|
||||
{
|
||||
pix16 = *pixel ; /* RRRRRGGGGGGBBBBB*/
|
||||
r = u5bto8b[pix16 >> 11] ; /* Value on 5 bits remapped to 8 bits */
|
||||
g = u6bto8b[(pix16 >> 5) & 0x1F] ; /* Value on 6 bits remapped to 8 bits */
|
||||
b = u5bto8b[pix16 & 0x1F] ; /* Value on 5 bits remapped to 8 bits */
|
||||
}
|
||||
else
|
||||
{
|
||||
r = pixel[0] ;
|
||||
g = pixel[1] ;
|
||||
b = pixel[2] ;
|
||||
}
|
||||
if ( abs( r-g ) > diff_grey ) img_report->is_grey = 0 ;
|
||||
else if ( abs( r-b ) > diff_grey ) img_report->is_grey = 0 ;
|
||||
else if ( abs( g-b ) > diff_grey ) img_report->is_grey = 0 ;
|
||||
}
|
||||
|
||||
if ( !img_report->is_grey )
|
||||
{
|
||||
if ( in->fd_nplanes == 16 ) Vapi->LoDoLog(LL_INFO,"optimg.ldv: fast_isgrey, not grey: %d %d %d (%X)", (short)r, (short)g, (short)b, pix16) ;
|
||||
else Vapi->LoDoLog(LL_INFO,"optimg.ldv: fast_isgrey, not grey: %d %d %d", (short)r, (short)g, (short)b) ;
|
||||
}
|
||||
}
|
||||
|
||||
static short AnalyzeFromVISION(IMG_REPORT* img_report)
|
||||
{
|
||||
HISTO histo ;
|
||||
short status ;
|
||||
|
||||
Vapi->LoDoLog(LL_INFO,"optimg.ldv: Requesting VISION to compute histogram...") ;
|
||||
Vapi->PrSetText( 1, "Requesting histograms to VISION..." ) ;
|
||||
histo.norm = 256 ; /* Normalize stats to 0...256 scale */
|
||||
status = Vapi->ImComputeHistogram( img_report->in, &histo ) ;
|
||||
Vapi->LoDoLog(LL_INFO,"optimg.ldv: histogram done with status %d", status) ;
|
||||
if ( status == 0 )
|
||||
{
|
||||
long max_diff_grey = 0 ;
|
||||
long r, g, b, ref_diff_grey ;
|
||||
short i, grey1 = 0 ;
|
||||
|
||||
ref_diff_grey = img_report->diff_grey ;
|
||||
for ( i = 0; img_report->is_grey && (i < HISTO_SIZE); i++ )
|
||||
{
|
||||
r = histo.red[i] ;
|
||||
g = histo.green[i] ;
|
||||
b = histo.blue[i] ;
|
||||
max_diff_grey = md_grey( labs( r-g ), max_diff_grey ) ;
|
||||
max_diff_grey = md_grey( labs( r-b ), max_diff_grey ) ;
|
||||
max_diff_grey = md_grey( labs( g-b ), max_diff_grey ) ;
|
||||
if ( max_diff_grey > ref_diff_grey ) img_report->is_grey = 0 ;
|
||||
}
|
||||
Vapi->LoDoLog(LL_INFO,"optimg.ldv: max difference grey=%ld", max_diff_grey) ;
|
||||
|
||||
/* As histogram will report "perfect grey" if image has colors fully aligned (i.e. full 16M picture), let's make a fast check on grey levels */
|
||||
if ( img_report->is_grey && (img_report->in->Raster.fd_nplanes > 8) )
|
||||
{
|
||||
fast_isgrey( img_report ) ;
|
||||
if ( img_report->is_grey ) grey1 = 1 ;
|
||||
}
|
||||
if ( !img_report->is_grey )
|
||||
{
|
||||
i-- ;
|
||||
Vapi->LoDoLog(LL_INFO,"optimg.ldv: image is not grey level and so not dual-tone") ;
|
||||
if ( grey1 ) Vapi->LoDoLog(LL_INFO,"optimg.ldv: RGB[%d]=%ld,%ld,%ld", i, r, g, b) ;
|
||||
img_report->is_dualtone = 0 ;
|
||||
}
|
||||
else if ( img_report->limit_black < img_report->limit_white )
|
||||
{
|
||||
for ( i = img_report->limit_black; img_report->is_dualtone && (i < img_report->limit_white); i++ )
|
||||
{
|
||||
if ( histo.grey[i] > ref_diff_grey ) img_report->is_dualtone = 0 ;
|
||||
}
|
||||
if ( !img_report->is_dualtone )
|
||||
{
|
||||
i-- ;
|
||||
Vapi->LoDoLog(LL_INFO,"optimg.ldv: image is not dual tone") ;
|
||||
Vapi->LoDoLog(LL_INFO,"optimg.ldv: Grey[%d]=%ld", i, histo.grey[i]) ;
|
||||
}
|
||||
}
|
||||
img_report->ncolors = histo.nb_colors_used ;
|
||||
}
|
||||
|
||||
return status ;
|
||||
}
|
||||
|
||||
static LDV_STATUS ImgAnalyze(IMG_REPORT* img_report)
|
||||
{
|
||||
LDV_IMAGE* in = img_report->in ;
|
||||
short status ;
|
||||
|
||||
img_report->is_dualtone = 1 ;
|
||||
img_report->is_grey = 1 ;
|
||||
|
||||
if ( LoadProfile( img_report ) != 0 )
|
||||
{
|
||||
/* For some reason, profile is not found */
|
||||
/* Let's defaut to TIF/JPEG outputs */
|
||||
Vapi->LoDoLog(LL_INFO, "optimg.ldv: getting hard-coded default profile") ;
|
||||
GetDefaultSaveOptions( img_report ) ;
|
||||
}
|
||||
|
||||
if ( in->Raster.fd_nplanes == 1 ) return 1 ;
|
||||
|
||||
Vapi->LoDoLog(LL_INFO, "optimg.ldv: image is %dx%dx%d", in->Raster.fd_w, in->Raster.fd_h, in->Raster.fd_nplanes) ;
|
||||
Vapi->LoDoLog(LL_INFO, "optimg.ldv: ImgAnalyze enforce_smaller = %d", (short)img_report->enforce_smaller) ;
|
||||
Vapi->LoDoLog(LL_INFO, "optimg.ldv: ImgAnalyze limit_black = %d", (short)img_report->limit_black) ;
|
||||
Vapi->LoDoLog(LL_INFO, "optimg.ldv: ImgAnalyze limit_white = %d", (short)img_report->limit_white) ;
|
||||
Vapi->LoDoLog(LL_INFO, "optimg.ldv: ImgAnalyze diff_grey = %d", (short)img_report->diff_grey) ;
|
||||
Vapi->LoDoLog(LL_INFO, "optimg.ldv: ImgAnalyze enforce_dither = %d", (short)img_report->enforce_dither) ;
|
||||
if ( img_report->enforce_dither )
|
||||
{
|
||||
Vapi->LoDoLog(LL_INFO, "optimg.ldv: ImgAnalyze method = %d", (short)img_report->dither_method) ;
|
||||
Vapi->LoDoLog(LL_INFO, "optimg.ldv: ImgAnalyze outplanes = %d", (short)img_report->dither_outplanes) ;
|
||||
Vapi->LoDoLog(LL_INFO, "optimg.ldv: ImgAnalyze param = %d", (short)img_report->dither_param) ;
|
||||
}
|
||||
|
||||
if ( img_report->enforce_dither )
|
||||
{
|
||||
Vapi->LoDoLog(LL_INFO,"optimg.ldv: profile enforces dither method=%d, outplanes=%d, param=%d", img_report->dither_method, img_report->dither_outplanes, img_report->dither_param ) ;
|
||||
status = 1 ;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = ( AnalyzeFromVISION( img_report ) == 0 ) ;
|
||||
if ( img_report->is_grey ) { Vapi->LoDoLog(LL_INFO,"optimg.ldv: image is grey level") ; status = 1 ; }
|
||||
if ( img_report->is_dualtone ) { Vapi->LoDoLog(LL_INFO,"optimg.ldv: image is dual tone") ; status = 1 ; }
|
||||
Vapi->LoDoLog(LL_INFO,"optimg.ldv: %ld colors found", img_report->ncolors) ;
|
||||
}
|
||||
|
||||
return status ;
|
||||
}
|
||||
|
||||
static char* GetSaveOptions(IMG_REPORT* img_report, short nplanes)
|
||||
{
|
||||
short planes[] = { 1, 4, 8, 16, 24, 32 } ;
|
||||
short i ;
|
||||
char* save_options = NULL ;
|
||||
|
||||
for ( i = 0; (save_options == NULL) && (i < ARRAY_SIZE(planes)); i++ )
|
||||
if ( planes[i] == nplanes ) save_options = &img_report->save_options[i][0] ;
|
||||
|
||||
Vapi->LoDoLog(LL_INFO, "optimg.ldv: GetSaveOptions(%d planes): %s", nplanes, save_options ? save_options:NULL) ;
|
||||
return save_options ;
|
||||
}
|
||||
|
||||
static char* GetBestImgMatch(IMG_REPORT* img_report, long* method, long* param, LDV_IMAGE* out)
|
||||
{
|
||||
LDV_IMAGE* in = img_report->in ;
|
||||
|
||||
out->Raster.fd_nplanes = in->Raster.fd_nplanes ;
|
||||
*method = -1 ;
|
||||
*param = 0 ;
|
||||
|
||||
if ( img_report->enforce_dither )
|
||||
{
|
||||
out->Raster.fd_nplanes = img_report->dither_outplanes ;
|
||||
*method = img_report->dither_method ;
|
||||
*param = img_report->dither_param ;
|
||||
}
|
||||
else if ( img_report->is_dualtone )
|
||||
{
|
||||
out->Raster.fd_nplanes = 1 ;
|
||||
*method = 4 ;
|
||||
*param = 50 ;
|
||||
}
|
||||
else if ( img_report->is_grey )
|
||||
{
|
||||
out->Raster.fd_nplanes = (img_report->ncolors <= 16L) ? 4:8 ;
|
||||
*method = 2 ;
|
||||
}
|
||||
else if ( img_report->ncolors < 2048L )
|
||||
{
|
||||
if ( in->Raster.fd_nplanes > 8 )
|
||||
{
|
||||
out->Raster.fd_nplanes = 8 ;
|
||||
*method = 3 ;
|
||||
}
|
||||
}
|
||||
|
||||
return GetSaveOptions( img_report, out->Raster.fd_nplanes ) ;
|
||||
}
|
||||
|
||||
static long file_size(char* name)
|
||||
{
|
||||
FILE* stream = fopen( name, "rb" ) ;
|
||||
long size ;
|
||||
|
||||
if ( stream == NULL ) return -1 ;
|
||||
|
||||
fseek( stream, 0, SEEK_END ) ;
|
||||
size = ftell( stream ) ;
|
||||
fclose( stream ) ;
|
||||
|
||||
return size ;
|
||||
}
|
||||
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE* in, LDV_PARAMS* params, LDV_IMAGE* out)
|
||||
{
|
||||
LDV_STATUS status = ELDV_NOERROR ;
|
||||
IMG_REPORT img_report ;
|
||||
short copy_file = 1 ; /* In case we don't find a better choice than the current one */
|
||||
char in_file[256] ;
|
||||
char out_file[256] ;
|
||||
char buf[256] ;
|
||||
char* pout_file ;
|
||||
char* profile ;
|
||||
|
||||
CHECK_VAPI( Vapi ) ;
|
||||
|
||||
pout_file = params->Param[0].str ;
|
||||
profile = params->Param[1].str ;
|
||||
Vapi->LoDoLog(LL_INFO, "optimg.ldv: dest:%s, profile=%s", pout_file ? pout_file:"<null>", profile ? profile:"<null>") ;
|
||||
if ( pout_file == NULL ) return ELDV_INVALIDPARAMETER ;
|
||||
|
||||
status = Vapi->ImGetStdData( in, "filename", in_file, sizeof(in_file) ) ;
|
||||
if ( !LDV_SUCCESS( status ) ) return status ;
|
||||
|
||||
strcpy( out_file, pout_file ) ;
|
||||
if ( Vapi->FiFolderExist( pout_file ) )
|
||||
{
|
||||
char* last_slash = strrchr( in_file, '\\' ) ;
|
||||
|
||||
Vapi->LoDoLog(LL_INFO, "optimg.ldv: %s is a folder", pout_file ) ;
|
||||
if ( last_slash ) strcat( out_file, last_slash ) ; /* Just copy filename without folder before */
|
||||
else strcat( out_file, in_file ) ;
|
||||
}
|
||||
|
||||
sprintf( buf, "Analyzing %s...", in_file ) ;
|
||||
Vapi->PrSetText( 0, buf ) ;
|
||||
Vapi->PrSetText( 1, "Requesting histograms to VISION..." ) ;
|
||||
if ( LDVPROG_CANCEL( Vapi->PrSetProgEx( 0 ) ) ) { Vapi->LoDoLog(LL_INFO, "optimg.ldv: user requested cancel") ; return ELDV_CANCELLED ; }
|
||||
memset( &img_report, 0, sizeof(img_report) ) ;
|
||||
img_report.in = in ;
|
||||
img_report.profile = profile ;
|
||||
if ( ImgAnalyze( &img_report ) == 1 )
|
||||
{
|
||||
long method, param ;
|
||||
char* save_options ;
|
||||
|
||||
save_options = GetBestImgMatch( &img_report, &method, ¶m, out ) ;
|
||||
if ( save_options )
|
||||
{
|
||||
Vapi->LoDoLog(LL_INFO,"optimg.ldv: dither method=%ld", method) ;
|
||||
sprintf( buf, "Optimizing %s...", in_file ) ;
|
||||
Vapi->PrSetText( 0, buf ) ;
|
||||
Vapi->PrSetText( 1, "Requesting dithering to VISION..." ) ;
|
||||
if ( LDVPROG_CANCEL( Vapi->PrSetProgEx( 33 ) ) ) status = ELDV_CANCELLED ;
|
||||
else if ( method != -1 ) status = Vapi->ImDither( method, param, in, out ) ;
|
||||
if ( LDV_SUCCESS( status ) )
|
||||
{
|
||||
char local_outfile[256] ; /* As we have to set the format as extension */
|
||||
char buffer[128] ;
|
||||
char out_ext[16] ;
|
||||
char* c ;
|
||||
char* ext ;
|
||||
|
||||
if ( method != -1 ) Vapi->ImFree( in ) ; /* We just dither the image sucessfully, let's free the original one */
|
||||
else memcpy( out, in, sizeof(LDV_IMAGE) ) ;
|
||||
if ( sscanf( save_options, "fmt=%s", buffer ) == 1 ) /* format is the first field returned by GetBestImgMatch */
|
||||
{
|
||||
c = strchr( buffer, ';' ) ;
|
||||
if ( c ) { *c = 0 ; strcpy( out_ext, buffer ) ; }
|
||||
else strcpy( out_ext, buffer ) ;
|
||||
strcpy( local_outfile, out_file ) ;
|
||||
c = strrchr( local_outfile, '\\' ) ;
|
||||
if ( c ) ext = strrchr( 1+c, '.' ) ;
|
||||
else ext = strrchr( local_outfile, '.' ) ;
|
||||
if ( ext ) *(1+ext) = 0 ;
|
||||
if ( c ) strcat( 1+c, out_ext ) ;
|
||||
Vapi->LoDoLog(LL_INFO, "optimg.ldv: optimizing image file %s to %s with options: %s", in_file, local_outfile, save_options ) ;
|
||||
Vapi->PrSetText( 1, "Requesting saving to VISION..." ) ;
|
||||
if ( LDVPROG_CANCEL( Vapi->PrSetProgEx( 66 ) ) ) status = ELDV_CANCELLED ;
|
||||
else status = Vapi->ImSave( local_outfile, out, save_options ) ;
|
||||
if ( LDV_SUCCESS( status ) )
|
||||
{
|
||||
if ( img_report.enforce_smaller )
|
||||
{
|
||||
long l1, l2 ;
|
||||
|
||||
l1 = file_size( in_file ) ;
|
||||
l2 = file_size( local_outfile ) ;
|
||||
if ( (l2 > 0) && (l1 > l2) ) copy_file = 0 ;
|
||||
else { unlink( local_outfile ) ; Vapi->LoDoLog(LL_INFO, "optimg.ldv: optimized file is bigger (%ldKB vs %ldKB), keeping original one", l1>>10, l2>>10 ) ; }
|
||||
}
|
||||
else copy_file = 0 ;
|
||||
}
|
||||
else { Vapi->LoDoLog(LL_ERROR, "optimg.ldv: ImSave returned %ld", status ) ; status = ELDV_GENERALFAILURE ; }
|
||||
}
|
||||
else { Vapi->LoDoLog(LL_ERROR, "optimg.ldv: image format not found in save options %s", save_options ) ; status = ELDV_GENERALFAILURE ; }
|
||||
}
|
||||
else Vapi->LoDoLog(LL_ERROR, "optimg.ldv: ImDither returned %ld", status ) ;
|
||||
}
|
||||
else Vapi->LoDoLog(LL_INFO, "optimg.ldv: can't find a better setting" ) ;
|
||||
}
|
||||
else Vapi->LoDoLog(LL_INFO, "optimg.ldv: ImgAnalyze did not identify a possible optimization" ) ;
|
||||
|
||||
if ( status == ELDV_CANCELLED ) Vapi->LoDoLog(LL_INFO, "optimg.ldv: user requested cancel") ;
|
||||
else if ( copy_file )
|
||||
{
|
||||
Vapi->LoDoLog(LL_INFO, "optimg.ldv: duplicating image file %s to %s", in_file, out_file ) ;
|
||||
Vapi->PrSetText( 1, "Duplicating original file..." ) ;
|
||||
Vapi->PrSetProgEx( 85 ) ;
|
||||
status = Vapi->FiCopyFileR( in_file, out_file ) ;
|
||||
if ( !LDV_SUCCESS( status ) )
|
||||
{
|
||||
Vapi->LoDoLog(LL_ERROR, "optimg.ldv: FiCopyFileR returned %ld", status ) ;
|
||||
status = ELDV_GENERALFAILURE ;
|
||||
}
|
||||
}
|
||||
Vapi->PrSetText( 1, "" ) ;
|
||||
|
||||
return status ;
|
||||
}
|
||||
|
||||
static void uinit()
|
||||
{
|
||||
short i ;
|
||||
|
||||
for ( i = 0; i < 32; i++ ) u5bto8b[i] = (unsigned char) (0.5+(i*256.0)/32.0) ;
|
||||
for ( i = 0; i < 64; i++ ) u6bto8b[i] = (unsigned char) (0.5+(i*256.0)/64.0) ;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ldg_init( Ldg ) ;
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
BIN
tools/vision/ldv/src/optimg/optimg.ldv
Normal file
BIN
tools/vision/ldv/src/optimg/optimg.ldv
Normal file
Binary file not shown.
13
tools/vision/ldv/src/optimg/optimg.prj
Normal file
13
tools/vision/ldv/src/optimg/optimg.prj
Normal file
@@ -0,0 +1,13 @@
|
||||
OPTIMG.LDV
|
||||
.C [ ]
|
||||
.S [ ]
|
||||
.L [ ]
|
||||
=
|
||||
pcstart.o
|
||||
OPTIMG.C
|
||||
pcgemlib.lib
|
||||
pcstdlib.lib
|
||||
pctoslib.lib
|
||||
pcfltlib.lib
|
||||
..\..\ldg.lib
|
||||
..\..\mt_aes.lib
|
||||
345
tools/vision/ldv/src/pixel/pixel.c
Normal file
345
tools/vision/ldv/src/pixel/pixel.c
Normal file
@@ -0,0 +1,345 @@
|
||||
/*
|
||||
*
|
||||
*
|
||||
* Version PureC / Gcc
|
||||
*/
|
||||
|
||||
#define PCGEMLIB 1 /* mettre 1 si les utilisateurs de Pure C
|
||||
* utilise les librairies GEM Pure C */
|
||||
|
||||
/* Fichiers headers */
|
||||
|
||||
#include <portab.h>
|
||||
#if PCGEMLIB
|
||||
#include <aes.h>
|
||||
#include <vdi.h>
|
||||
#else
|
||||
#include <aesbind.h>
|
||||
#include <vdibind.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include "..\..\ldg.h"
|
||||
#include "..\..\vapi.h"
|
||||
#include "..\..\ldv.h"
|
||||
#include "..\..\mt_aes.h"
|
||||
|
||||
/* Prototypages */
|
||||
LDV_INFOS * cdecl GetLDVCapabilities(VAPI *vapi) ;
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
LDV_STATUS cdecl Preview(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
|
||||
/* Variables globales */
|
||||
PROC Proc[] = {
|
||||
"GetLDVCapabilities", "Capacit<EFBFBD>s du LDV", (void *)GetLDVCapabilities,
|
||||
"PreRun", "Init du Run", (void *)PreRun,
|
||||
"Run", "Fonction du LDV", (void *)Run,
|
||||
"Preview", "Pre-Visu", (void *)Preview,
|
||||
} ;
|
||||
|
||||
char Info[] = "LDV";
|
||||
|
||||
LDGLIB Ldg[] = {
|
||||
0x0101, /* version de la lib, recommand<6E> */
|
||||
4, /* nombre de fonction dans la lib */
|
||||
Proc, /* Pointeurs vers nos fonctions */
|
||||
Info, /* Information sur la lib */
|
||||
0x0, /* Flags de la lib, obligatoire */
|
||||
NULL, /* Fermeture, liberation de VDIHandle (inutilise) */
|
||||
};
|
||||
|
||||
#define CAPS (LDVF_ATARIFORMAT | LDVF_SUPPORTPREVIEW | LDVF_SUPPORTPROG | LDVF_REALTIMEPARAMS | LDVF_OPINPLACE | LDVF_SUPPORTCANCEL)
|
||||
|
||||
LDV_INFOS LdvInfos = {
|
||||
(short) sizeof(LDV_INFOS), /* Taille de cette structure */
|
||||
TLDV_MODIFYIMG, /* Type du LDV */
|
||||
"Jean Lusetti", /* Auteurs */
|
||||
{
|
||||
{ 16, 16, CAPS }, /* Capacites pour 16 plans */
|
||||
/* Qui le fera ? { 24, 24, CAPS }, */
|
||||
{ 32, 32, CAPS }, /* Capacites pour 32 plans */
|
||||
{ 0, 0, 0UL } /* Fin de la liste des capacites */
|
||||
},
|
||||
} ;
|
||||
/* Ce LDV ne peut marcher qu'avec une versio de VAPI >= 1.02 */
|
||||
/* Du <20> un bug dans la version 1.01 */
|
||||
#define CHK_VAPIVERSION(vapi) if ( ( vapi == NULL ) || ( vapi->Header.Version < 0x102 ) ) return( ELDV_BADVAPIVERSION ) ;
|
||||
|
||||
/* Petites macros bien utiles ... */
|
||||
#define RVB16( r, v, b ) ( (r << 11) + (v << 5) + (b) )
|
||||
#define RVB32( r, v, b ) ( ((long)(r) << 24) + ((long)(v) << 16) + ((long)(b << 8)) )
|
||||
|
||||
VAPI *Vapi = NULL ;
|
||||
unsigned short powerx, powery ;
|
||||
unsigned long p2 ;
|
||||
|
||||
/*
|
||||
Notez que ce LDV ne se sert pas de VDIHandle, OnClose... puisque aucune fonction VDI (vo_cpyfm par ex.) n'est utilisee
|
||||
int VDIHandle = -1 ;
|
||||
|
||||
|
||||
void OnClose(void)
|
||||
{
|
||||
if ( VDIHandle != -1 ) v_clsvwk( VDIHandle ) ;
|
||||
VDIHandle = -1 ;
|
||||
}
|
||||
|
||||
int vdihandle(void)
|
||||
{
|
||||
int work_in[11], work_out[57], i ;
|
||||
|
||||
for ( i = 0; i < 10; work_in[i++] = 1 ) ;
|
||||
work_in[10] = 2 ;
|
||||
v_opnvwk( work_in, &i, work_out ) ;
|
||||
|
||||
return( i ) ;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
* Fonctions de la librairie
|
||||
*/
|
||||
|
||||
LDV_INFOS * cdecl GetLDVCapabilities(VAPI *vapi)
|
||||
{
|
||||
Vapi = vapi ;
|
||||
|
||||
return( &LdvInfos ) ;
|
||||
}
|
||||
|
||||
#pragma warn -par
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
CHK_VAPIVERSION( Vapi ) ;
|
||||
|
||||
/* La transformation se fait "sur place" */
|
||||
|
||||
return( ELDV_NOERROR ) ;
|
||||
}
|
||||
#pragma warn +par
|
||||
|
||||
unsigned short Pixelize16(unsigned short *pt, long nb_lpts)
|
||||
{
|
||||
unsigned short *last_pt = pt ;
|
||||
unsigned long rsum = 0 ;
|
||||
unsigned long gsum = 0 ;
|
||||
unsigned long bsum = 0 ;
|
||||
unsigned short pixel, *ptu ;
|
||||
unsigned short red, green, blue ;
|
||||
short x, y ;
|
||||
|
||||
for ( y = 0; y < powery; y++, last_pt += nb_lpts )
|
||||
{
|
||||
ptu = last_pt ;
|
||||
for ( x = 0; x < powerx; x++, ptu++ )
|
||||
{
|
||||
pixel = *ptu ;
|
||||
red = pixel >> 11 ; /* Sur 5 bits */
|
||||
green = ( pixel >> 5 ) & 0x3F ; /* Sur 6 bits */
|
||||
blue = pixel & 0x1F ; /* Sur 5 bits */
|
||||
rsum += (unsigned long) red ;
|
||||
gsum += (unsigned long) green ;
|
||||
bsum += (unsigned long) blue ;
|
||||
}
|
||||
}
|
||||
|
||||
red = (unsigned short) (rsum / p2) ;
|
||||
green = (unsigned short) (gsum / p2) ;
|
||||
blue = (unsigned short) (bsum / p2) ;
|
||||
pixel = RVB16( red, green, blue ) ;
|
||||
|
||||
return( pixel ) ;
|
||||
}
|
||||
|
||||
LDV_STATUS Run16(LDV_IMAGE *in, LDV_PARAMS *params)
|
||||
{
|
||||
unsigned short new_pixel, *pt, *tmp_pt, *dpix ;
|
||||
unsigned long po2 ;
|
||||
long yoffset, nb_lpts ;
|
||||
short power, x, y ;
|
||||
short pc, cancel = 0 ;
|
||||
short iter = 0 ;
|
||||
|
||||
power = params->Param[0].s ;
|
||||
po2 = power * power ;
|
||||
nb_lpts = in->Raster.fd_w ;
|
||||
if ( nb_lpts & 0x0F ) nb_lpts++ ;
|
||||
yoffset = nb_lpts * (long)(params->y1) ;
|
||||
for ( y = params->y1; !cancel && (y < params->y2); y += power, yoffset += nb_lpts*power )
|
||||
{
|
||||
powerx = power ;
|
||||
if ( y + power - 1 > params->y2 )
|
||||
{
|
||||
powery = 1 + params->y2 - y ;
|
||||
p2 = powerx * powery ;
|
||||
}
|
||||
else
|
||||
{
|
||||
powery = power ;
|
||||
p2 = po2 ;
|
||||
}
|
||||
pt = (unsigned short *)(in->Raster.fd_addr) + yoffset + params->x1 ;
|
||||
for ( x = params->x1; x < params->x2 - powerx; x += powerx, pt += powerx )
|
||||
{
|
||||
new_pixel = Pixelize16( pt, nb_lpts ) ;
|
||||
for ( tmp_pt = pt; tmp_pt < pt + powery*nb_lpts; tmp_pt += nb_lpts )
|
||||
for ( dpix = tmp_pt; dpix < tmp_pt + powerx; dpix++ ) *dpix = new_pixel ;
|
||||
}
|
||||
/* Residuel sur x (evite un test pour chaque paquet power x power) */
|
||||
if ( x < params->x2 )
|
||||
{
|
||||
powerx = params->x2 - x ;
|
||||
p2 = powerx * powery ;
|
||||
new_pixel = Pixelize16( pt, nb_lpts ) ;
|
||||
for ( tmp_pt = pt; tmp_pt < pt + powery*nb_lpts; tmp_pt += nb_lpts )
|
||||
for ( dpix = tmp_pt; dpix < tmp_pt + powerx; dpix++ ) *dpix = new_pixel ;
|
||||
}
|
||||
if ( Vapi && ( ( iter++ & 0x0F ) == 0x0F ) )
|
||||
{
|
||||
pc = (short) ( ( 100L * (long)(y - params->y1) ) / (long)(params->y2 - power- params->y1) ) ;
|
||||
if ( Vapi->PrSetProgEx )
|
||||
{
|
||||
cancel = Vapi->PrSetProgEx( pc ) ;
|
||||
}
|
||||
else
|
||||
Vapi->PrSetProg( pc ) ;
|
||||
}
|
||||
}
|
||||
|
||||
return( cancel ? ELDV_CANCELLED : ELDV_NOERROR ) ;
|
||||
}
|
||||
|
||||
unsigned long Pixelize32(unsigned long *pt, long nb_lpts)
|
||||
{
|
||||
unsigned long *last_pt = pt ;
|
||||
unsigned long rsum = 0 ;
|
||||
unsigned long gsum = 0 ;
|
||||
unsigned long bsum = 0 ;
|
||||
unsigned long pixel, *ptu ;
|
||||
unsigned long red, green, blue ;
|
||||
short x, y ;
|
||||
|
||||
for ( y = 0; y < powery; y++, last_pt += nb_lpts )
|
||||
{
|
||||
ptu = last_pt ;
|
||||
for ( x = 0; x < powerx; x++, ptu++ )
|
||||
{
|
||||
pixel = *ptu ;
|
||||
pixel >>= 8 ;
|
||||
bsum += pixel & 0xFF ;
|
||||
pixel >>= 8 ;
|
||||
gsum += pixel & 0xFF ;
|
||||
pixel >>= 8 ;
|
||||
rsum += pixel ;
|
||||
}
|
||||
}
|
||||
|
||||
red = rsum / p2 ;
|
||||
green = gsum / p2 ;
|
||||
blue = bsum / p2 ;
|
||||
pixel = RVB32( red, green, blue ) ;
|
||||
|
||||
return( pixel ) ;
|
||||
}
|
||||
|
||||
LDV_STATUS Run32(LDV_IMAGE *in, LDV_PARAMS *params)
|
||||
{
|
||||
unsigned long new_pixel, *pt, *tmp_pt, *dpix ;
|
||||
unsigned long po2 ;
|
||||
long yoffset, nb_lpts ;
|
||||
short power, x, y ;
|
||||
short pc, cancel = 0 ;
|
||||
short iter = 0 ;
|
||||
|
||||
power = params->Param[0].s ;
|
||||
po2 = power * power ;
|
||||
nb_lpts = in->Raster.fd_w ;
|
||||
if ( nb_lpts & 0x0F ) nb_lpts++ ;
|
||||
yoffset = nb_lpts * (long)(params->y1) ;
|
||||
for ( y = params->y1; !cancel && (y < params->y2); y += power, yoffset += nb_lpts*power )
|
||||
{
|
||||
powerx = power ;
|
||||
if ( y + power - 1 > params->y2 )
|
||||
{
|
||||
powery = 1 + params->y2 - y ;
|
||||
p2 = powerx * powery ;
|
||||
}
|
||||
else
|
||||
{
|
||||
powery = power ;
|
||||
p2 = po2 ;
|
||||
}
|
||||
pt = (unsigned long *)(in->Raster.fd_addr) + yoffset + params->x1 ;
|
||||
for ( x = params->x1; x < params->x2 - powerx; x += powerx, pt += powerx )
|
||||
{
|
||||
new_pixel = Pixelize32( pt, nb_lpts ) ;
|
||||
for ( tmp_pt = pt; tmp_pt < pt + powery*nb_lpts; tmp_pt += nb_lpts )
|
||||
for ( dpix = tmp_pt; dpix < tmp_pt + powerx; dpix++ ) *dpix = new_pixel ;
|
||||
}
|
||||
/* Residuel sur x (evite un test pour chaque paquet power x power) */
|
||||
if ( x < params->x2 )
|
||||
{
|
||||
powerx = params->x2 - x ;
|
||||
p2 = powerx * powery ;
|
||||
new_pixel = Pixelize32( pt, nb_lpts ) ;
|
||||
for ( tmp_pt = pt; tmp_pt < pt + powery*nb_lpts; tmp_pt += nb_lpts )
|
||||
for ( dpix = tmp_pt; dpix < tmp_pt + powerx; dpix++ ) *dpix = new_pixel ;
|
||||
}
|
||||
if ( Vapi && ( ( iter++ & 0x0F ) == 0x0F ) )
|
||||
{
|
||||
pc = (short) ( ( 100L * (long)(y - params->y1) ) / (long)(params->y2 - power- params->y1) ) ;
|
||||
if ( Vapi->PrSetProgEx )
|
||||
{
|
||||
cancel = Vapi->PrSetProgEx( pc ) ;
|
||||
}
|
||||
else
|
||||
Vapi->PrSetProg( pc ) ;
|
||||
}
|
||||
}
|
||||
|
||||
return( cancel ? ELDV_CANCELLED : ELDV_NOERROR ) ;
|
||||
}
|
||||
|
||||
#pragma warn -par
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
LDV_STATUS status ;
|
||||
|
||||
CHK_VAPIVERSION( Vapi ) ;
|
||||
|
||||
if ( ( in->RasterFormat & CAPS ) == 0 ) return( ELDV_IMGFORMATMISMATCH ) ;
|
||||
|
||||
/* if ( VDIHandle == -1 ) VDIHandle = vdihandle() ; (inutile) */
|
||||
|
||||
switch( in->Raster.fd_nplanes )
|
||||
{
|
||||
case 16 : status = Run16( in, params ) ;
|
||||
break ;
|
||||
/*
|
||||
case 24 : status = Run24( in, params ) ;
|
||||
break ;
|
||||
*/
|
||||
case 32 : status = Run32( in, params ) ;
|
||||
break ;
|
||||
|
||||
default : status = ELDV_NBPLANESNOTSUPPORTED ;
|
||||
break ;
|
||||
}
|
||||
|
||||
return( status ) ;
|
||||
}
|
||||
#pragma warn +par
|
||||
|
||||
LDV_STATUS cdecl Preview(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
return( Run( in, params, out ) ) ;
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ldg_init( Ldg ) ;
|
||||
|
||||
return( 0 ) ;
|
||||
}
|
||||
BIN
tools/vision/ldv/src/pixel/pixel.ldv
Normal file
BIN
tools/vision/ldv/src/pixel/pixel.ldv
Normal file
Binary file not shown.
13
tools/vision/ldv/src/pixel/pixel.prj
Normal file
13
tools/vision/ldv/src/pixel/pixel.prj
Normal file
@@ -0,0 +1,13 @@
|
||||
PIXEL.LDV
|
||||
.C [ ]
|
||||
.S [ ]
|
||||
.L [ ]
|
||||
=
|
||||
pcstart.o
|
||||
PIXEL.C
|
||||
;PIXEL.S
|
||||
pcgemlib.lib
|
||||
pcstdlib.lib
|
||||
pctoslib.lib
|
||||
..\..\ldg.lib
|
||||
..\..\mt_aes.lib
|
||||
74
tools/vision/ldv/src/pixel/pixel.s
Normal file
74
tools/vision/ldv/src/pixel/pixel.s
Normal file
@@ -0,0 +1,74 @@
|
||||
.EXPORT Pixelize16
|
||||
|
||||
MACRO GET_FRGB16
|
||||
|
||||
MOVE.W (A0),D0
|
||||
MOVE.W D0,D1
|
||||
ROL.W #5,D1
|
||||
ANDI.W #$1F,D1 ; D1.W = Composante ROUGE
|
||||
|
||||
MOVE.W D0,D2
|
||||
LSR.W #5,D2
|
||||
ANDI.W #$3F,D2 ; D2.W = Composante VERTE (0...63)
|
||||
|
||||
MOVE.W D0,D3
|
||||
ANDI.W #$1F,D3 ; D3.W = Composante BLEU (0...31)
|
||||
|
||||
ENDM
|
||||
|
||||
MACRO SET_FRGB16
|
||||
|
||||
MOVE.W D3,D0 ; D3 = Composante Bleu
|
||||
LSL.W #5,D2
|
||||
ADD.W D2,D0 ; D0 += Composante Verte
|
||||
ROR.W #5,D1
|
||||
ADD.W D1,D0 ; D0 += Composante Rouge
|
||||
|
||||
ENDM
|
||||
|
||||
*unsigned short Pixelize16(unsigned short *pt, long nb_lpts, short powerx, short powery)
|
||||
*
|
||||
*{
|
||||
* unsigned long rsum = 0 ;
|
||||
* unsigned long gsum = 0 ;
|
||||
* unsigned long bsum = 0 ;
|
||||
* unsigned long p2 = powerx * powery ;
|
||||
* unsigned short val, pixel, *ptu ;
|
||||
* unsigned short red, green, blue ;
|
||||
* short x, y ;
|
||||
*
|
||||
* for ( y = 0; y < powery; y++ )
|
||||
* {
|
||||
* ptu = pt + y * nb_lpts ;
|
||||
* for ( x = 0; x < powerx; x++, ptu++ )
|
||||
* {
|
||||
* val = *ptu ;
|
||||
* red = val >> 11 ; /* Sur 5 bits */
|
||||
* green = ( val >> 5 ) & 0x3F ; /* Sur 6 bits */
|
||||
* blue = val & 0x1F ; /* Sur 5 bits */
|
||||
* rsum += (unsigned long) red ;
|
||||
* gsum += (unsigned long) green ;
|
||||
* bsum += (unsigned long) blue ;
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* red = (unsigned short) (rsum / p2) ;
|
||||
* green = (unsigned short) (gsum / p2) ;
|
||||
* blue = (unsigned short) (bsum / p2) ;
|
||||
* pixel = RVB16( red, green, blue ) ;
|
||||
*
|
||||
* return( pixel ) ;
|
||||
}
|
||||
|
||||
* unsigned short Pixelize16(unsigned short *pt, long nb_lpts, long power)
|
||||
* D0 A0 D0 D1
|
||||
Pixelize16:
|
||||
MOVEM.L D0-D7/A0-A6,-(SP)
|
||||
|
||||
MOVE.L D0,D4
|
||||
MOVE.L D1,D5
|
||||
MOVE.L A0,A1
|
||||
GET_FRGB16
|
||||
|
||||
|
||||
MOVEM.L (SP)+,D0-D7/A0-A6 ; Restauration du contexte
|
||||
241
tools/vision/ldv/src/puzzle/puzzle.c
Normal file
241
tools/vision/ldv/src/puzzle/puzzle.c
Normal file
@@ -0,0 +1,241 @@
|
||||
/*
|
||||
*
|
||||
*
|
||||
* Version PureC / Gcc
|
||||
*/
|
||||
|
||||
#define PCGEMLIB 1 /* mettre 1 si les utilisateurs de Pure C
|
||||
* utilise les librairies GEM Pure C */
|
||||
|
||||
/* Fichiers headers */
|
||||
|
||||
#include <portab.h>
|
||||
#if PCGEMLIB
|
||||
#include <aes.h>
|
||||
#include <vdi.h>
|
||||
#else
|
||||
#include <aesbind.h>
|
||||
#include <vdibind.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "..\..\ldg.h"
|
||||
#include "..\..\vapi.h"
|
||||
#include "..\..\ldv.h"
|
||||
#include "..\..\mt_aes.h"
|
||||
|
||||
/* Prototypages */
|
||||
LDV_INFOS * cdecl GetLDVCapabilities(VAPI *vapi) ;
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
LDV_STATUS cdecl Preview(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
|
||||
void OnClose(void) ;
|
||||
|
||||
/* Variables globales */
|
||||
PROC Proc[] = {
|
||||
"GetLDVCapabilities", "Capacit<EFBFBD>s du LDV", (void *)GetLDVCapabilities,
|
||||
"PreRun", "Init du Run", (void *)PreRun,
|
||||
"Run", "Fonction du LDV", (void *)Run,
|
||||
"Preview", "Pre-Visu", (void *)Preview,
|
||||
} ;
|
||||
|
||||
char Info[] = "LDV";
|
||||
|
||||
LDGLIB Ldg[] = {
|
||||
0x0102, /* version de la lib, recommand<6E> */
|
||||
4, /* nombre de fonction dans la lib */
|
||||
Proc, /* Pointeurs vers nos fonctions */
|
||||
Info, /* Information sur la lib */
|
||||
0x0, /* Flags de la lib, obligatoire */
|
||||
OnClose, /* Fermeture, liberation de VDIHandle */
|
||||
};
|
||||
|
||||
#define CAPS (LDVF_SPECFORMAT | LDVF_SUPPORTPREVIEW | LDVF_SUPPORTPROG | LDVF_REALTIMEPARAMS | LDVF_SUPPORTCANCEL | LDVF_NOSELECTION)
|
||||
|
||||
LDV_INFOS LdvInfos = {
|
||||
(short) sizeof(LDV_INFOS), /* Taille de cette structure */
|
||||
TLDV_MODIFYIMG, /* Type du LDV */
|
||||
"Jean Lusetti", /* Auteurs */
|
||||
{
|
||||
{ 1, 1, CAPS }, /* Capacites pour 1 plan */
|
||||
{ 2, 2, CAPS }, /* Capacites pour 2 plans */
|
||||
{ 4, 4, CAPS }, /* Capacites pour 4 plans */
|
||||
{ 8, 8, CAPS }, /* Capacites pour 8 plans */
|
||||
{ 16, 16, CAPS }, /* Capacites pour 16 plans */
|
||||
{ 24, 24, CAPS }, /* Capacites pour 24 plans */
|
||||
{ 32, 32, CAPS }, /* Capacites pour 32 plans */
|
||||
{ 0, 0, 0UL } /* Fin de la liste des capacites */
|
||||
},
|
||||
} ;
|
||||
|
||||
VAPI *Vapi = NULL ;
|
||||
int VDIHandle = -1 ;
|
||||
short *ToBeMixed = NULL ; /* Tableau (1,2,...) a melanger */
|
||||
short Nw, Nh, Entropy ;
|
||||
|
||||
void OnClose(void)
|
||||
{
|
||||
if ( VDIHandle != -1 ) v_clsvwk( VDIHandle ) ;
|
||||
VDIHandle = -1 ;
|
||||
if ( ToBeMixed ) free( ToBeMixed ) ;
|
||||
ToBeMixed = NULL ;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fonctions de la librairie
|
||||
*/
|
||||
|
||||
LDV_INFOS * cdecl GetLDVCapabilities(VAPI *vapi)
|
||||
{
|
||||
Vapi = vapi ;
|
||||
|
||||
return( &LdvInfos ) ;
|
||||
}
|
||||
|
||||
int vdihandle(void)
|
||||
{
|
||||
int work_in[11], work_out[57], i ;
|
||||
|
||||
for ( i = 0; i < 10; work_in[i++] = 1 ) ;
|
||||
work_in[10] = 2 ;
|
||||
v_opnvwk( work_in, &i, work_out ) ;
|
||||
|
||||
return( i ) ;
|
||||
}
|
||||
|
||||
short* SetMixedArray(short Nw, short Nh, short entropy)
|
||||
{
|
||||
short nb = Nw * Nh ;
|
||||
|
||||
if ( ToBeMixed ) free( ToBeMixed ) ;
|
||||
ToBeMixed = (short *) malloc( nb * sizeof(short) ) ;
|
||||
if ( ToBeMixed )
|
||||
{
|
||||
short i, j, k, l, *pt ;
|
||||
|
||||
pt = ToBeMixed ;
|
||||
for ( i = 0; i < nb; i++ ) *pt++ = i ; /* Un tableau bien trie ... */
|
||||
for ( i = 0; i < entropy*entropy; i++ )
|
||||
{
|
||||
j = rand() % nb ; /* On prend 2 elements au hasard */
|
||||
k = rand() % nb ;
|
||||
l = ToBeMixed[j] ; /* Et on les permute ... */
|
||||
ToBeMixed[j] = ToBeMixed[k] ;
|
||||
ToBeMixed[k] = l ;
|
||||
}
|
||||
}
|
||||
|
||||
return ToBeMixed ;
|
||||
}
|
||||
|
||||
LDV_STATUS UpdateMixedArray(LDV_PARAMS *params)
|
||||
{
|
||||
short old_nw = Nw ;
|
||||
short old_nh = Nh ;
|
||||
short old_entropy = Entropy ;
|
||||
|
||||
Nw = params->Param[0].s ;
|
||||
Nh = params->Param[1].s ;
|
||||
Entropy = params->Param[2].s ;
|
||||
|
||||
if ( (old_nw != Nw) || (old_nh != Nh) || (old_entropy != Entropy) )
|
||||
if ( SetMixedArray( Nw, Nh, Entropy ) == NULL ) return ELDV_NOTENOUGHMEMORY ;
|
||||
|
||||
return ELDV_NOERROR ;
|
||||
}
|
||||
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
LDV_STATUS status ;
|
||||
|
||||
status = UpdateMixedArray( params ) ;
|
||||
if ( !LDV_SUCCESS(status) ) return status ;
|
||||
|
||||
out->Raster.fd_w = in->Raster.fd_w ;
|
||||
out->Raster.fd_h = in->Raster.fd_h ;
|
||||
|
||||
return ELDV_NOERROR ;
|
||||
}
|
||||
|
||||
#pragma warn -par
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
LDV_STATUS status ;
|
||||
long cancel, pc ;
|
||||
short *src_num = ToBeMixed ;
|
||||
short dst_num ;
|
||||
int xy[8] ;
|
||||
int x, y, w, h ;
|
||||
int nw, nh, mw, mh ;
|
||||
|
||||
status = UpdateMixedArray( params ) ;
|
||||
if ( !LDV_SUCCESS(status) ) return status ;
|
||||
|
||||
if ( VDIHandle == -1 ) VDIHandle = vdihandle() ;
|
||||
|
||||
cancel = 0 ;
|
||||
w = in->Raster.fd_w / Nw ;
|
||||
h = in->Raster.fd_h / Nh ;
|
||||
mw = in->Raster.fd_w % Nw ;
|
||||
if ( mw )
|
||||
{
|
||||
/* Les "restes" de bloc sont recopies tels quels */
|
||||
xy[0] = xy[4] = in->Raster.fd_w - mw - 1 ;
|
||||
xy[1] = xy[5] = 0 ;
|
||||
xy[2] = xy[6] = in->Raster.fd_w - 1 ;
|
||||
xy[3] = xy[7] = in->Raster.fd_h - 1 ;
|
||||
vro_cpyfm( VDIHandle, S_ONLY, xy, &in->Raster, &out->Raster ) ;
|
||||
}
|
||||
mh = in->Raster.fd_h % Nh ;
|
||||
if ( mh )
|
||||
{
|
||||
/* Les "restes" de bloc sont recopies tels quels */
|
||||
xy[0] = xy[4] = 0 ;
|
||||
xy[1] = xy[5] = in->Raster.fd_h - mh - 1 ;
|
||||
xy[2] = xy[6] = in->Raster.fd_w - 1 ;
|
||||
xy[3] = xy[7] = in->Raster.fd_h - 1 ;
|
||||
vro_cpyfm( VDIHandle, S_ONLY, xy, &in->Raster, &out->Raster ) ;
|
||||
}
|
||||
y = 0 ;
|
||||
for ( nh = 0; !cancel && ( nh < Nh ); nh++, y += h )
|
||||
{
|
||||
xy[1] = y ;
|
||||
xy[3] = y + h - 1 ;
|
||||
x = 0 ;
|
||||
for ( nw = 0; nw < Nw; nw++, x += w )
|
||||
{
|
||||
dst_num = *src_num++ ;
|
||||
xy[0] = x ;
|
||||
xy[2] = x + w - 1 ;
|
||||
xy[4] = ( dst_num % Nw ) * w ;
|
||||
xy[5] = ( dst_num / Nw ) * h ;
|
||||
xy[6] = xy[4] + w - 1 ;
|
||||
xy[7] = xy[5] + h - 1 ;
|
||||
vro_cpyfm( VDIHandle, S_ONLY, xy, &in->Raster, &out->Raster ) ;
|
||||
}
|
||||
pc = ( 100L * y ) / in->Raster.fd_h ;
|
||||
cancel = Vapi->PrSetProgEx( pc ) ;
|
||||
}
|
||||
|
||||
if ( cancel ) status = ELDV_CANCELLED ;
|
||||
|
||||
return( status ) ;
|
||||
}
|
||||
#pragma warn +par
|
||||
|
||||
LDV_STATUS cdecl Preview(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
return( Run( in, params, out ) ) ;
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ldg_init( Ldg ) ;
|
||||
|
||||
srand( 256 ) ;
|
||||
|
||||
return( 0 ) ;
|
||||
}
|
||||
BIN
tools/vision/ldv/src/puzzle/puzzle.ldv
Normal file
BIN
tools/vision/ldv/src/puzzle/puzzle.ldv
Normal file
Binary file not shown.
12
tools/vision/ldv/src/puzzle/puzzle.prj
Normal file
12
tools/vision/ldv/src/puzzle/puzzle.prj
Normal file
@@ -0,0 +1,12 @@
|
||||
PUZZLE.LDV
|
||||
.C [ ]
|
||||
.S [ ]
|
||||
.L [ ]
|
||||
=
|
||||
pcstart.o
|
||||
PUZZLE.C
|
||||
pcgemlib.lib
|
||||
pcstdlib.lib
|
||||
pctoslib.lib
|
||||
..\..\ldg.lib
|
||||
..\..\mt_aes.lib
|
||||
128
tools/vision/ldv/src/rotate/rotate.c
Normal file
128
tools/vision/ldv/src/rotate/rotate.c
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
*
|
||||
*
|
||||
* Version PureC / Gcc
|
||||
*/
|
||||
|
||||
#define PCGEMLIB 1 /* mettre 1 si les utilisateurs de Pure C
|
||||
* utilise les librairies GEM Pure C */
|
||||
|
||||
/* Fichiers headers */
|
||||
|
||||
#include <portab.h>
|
||||
#if PCGEMLIB
|
||||
#include <aes.h>
|
||||
#include <vdi.h>
|
||||
#else
|
||||
#include <aesbind.h>
|
||||
#include <vdibind.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "..\..\ldg.h"
|
||||
#include "..\..\vapi.h"
|
||||
#include "..\..\ldv.h"
|
||||
#include "..\..\mt_aes.h"
|
||||
|
||||
/* Prototypages */
|
||||
LDV_INFOS* cdecl GetLDVCapabilities(VAPI *vapi) ;
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
LDV_STATUS cdecl Preview(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
|
||||
void OnClose(void) ;
|
||||
|
||||
/* Variables globales */
|
||||
PROC Proc[] = {
|
||||
"GetLDVCapabilities", "Capacit<EFBFBD>s du LDV", (void *)GetLDVCapabilities,
|
||||
"PreRun", "Init du Run", (void *)PreRun,
|
||||
"Run", "Fonction du LDV", (void *)Run,
|
||||
"Preview", "Pre-Visu", (void *)Preview,
|
||||
} ;
|
||||
|
||||
char Info[] = "LDV";
|
||||
|
||||
LDGLIB Ldg[] = {
|
||||
0x0101, /* version de la lib, recommand<6E> */
|
||||
4, /* nombre de fonction dans la lib */
|
||||
Proc, /* Pointeurs vers nos fonctions */
|
||||
Info, /* Information sur la lib */
|
||||
0x0, /* Flags de la lib, obligatoire */
|
||||
NULL,
|
||||
};
|
||||
|
||||
#define BP_CAPS (LDVF_SPECFORMAT | LDVF_SUPPORTPREVIEW | LDVF_SUPPORTPROG | LDVF_REALTIMEPARAMS | LDVF_SUPPORTCANCEL | LDVF_NOSELECTION)
|
||||
#define TC_CAPS (LDVF_SPECFORMAT | LDVF_SUPPORTPREVIEW | LDVF_SUPPORTPROG | LDVF_REALTIMEPARAMS | LDVF_SUPPORTCANCEL | LDVF_NOSELECTION)
|
||||
|
||||
LDV_INFOS LdvInfos = {
|
||||
(short) sizeof(LDV_INFOS), /* Taille de cette structure */
|
||||
TLDV_MODIFYIMG, /* Type du LDV */
|
||||
"Jean Lusetti", /* Auteurs */
|
||||
{
|
||||
{ 1, 1, BP_CAPS }, /* Capacites pour 1 plan */
|
||||
{ 2, 2, BP_CAPS }, /* Capacites pour 2 plans */
|
||||
{ 4, 4, BP_CAPS }, /* Capacites pour 4 plans */
|
||||
{ 8, 8, BP_CAPS }, /* Capacites pour 8 plans */
|
||||
{ 16, 16, TC_CAPS }, /* Capacites pour 16 plans */
|
||||
{ 32, 32, TC_CAPS }, /* Capacites pour 32 plans */
|
||||
{ 0, 0, 0UL } /* Fin de la liste des capacites */
|
||||
},
|
||||
} ;
|
||||
|
||||
VAPI *Vapi = NULL ;
|
||||
|
||||
/* Petite macro de verification pour VAPI */
|
||||
#define CHECK_VAPI(vapi) if ( ( vapi == NULL ) || ( vapi->Header.Version < 0x0103 ) ) return( ELDV_BADVAPIVERSION ) ;
|
||||
|
||||
|
||||
/*
|
||||
* Fonctions de la librairie
|
||||
*/
|
||||
|
||||
LDV_INFOS* cdecl GetLDVCapabilities(VAPI *vapi)
|
||||
{
|
||||
Vapi = vapi ;
|
||||
|
||||
return( &LdvInfos ) ;
|
||||
}
|
||||
|
||||
#pragma warn -par
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
long angle ;
|
||||
|
||||
CHECK_VAPI( Vapi ) ;
|
||||
|
||||
angle = (long) params->Param[0].s ;
|
||||
Vapi->RaRasterRotateGetDstMFDB( &in->Raster, &out->Raster, angle ) ;
|
||||
|
||||
return( ELDV_NOERROR ) ;
|
||||
}
|
||||
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
LDV_STATUS status ;
|
||||
long angle ;
|
||||
|
||||
CHECK_VAPI( Vapi ) ;
|
||||
|
||||
angle = (long) params->Param[0].s ;
|
||||
status = Vapi->RaRasterRotate( &in->Raster, &out->Raster, angle, 0x03 ) ; /* 0x03 = 0x01 (progress) | 0x02 (cancel) */
|
||||
|
||||
return( status ) ;
|
||||
}
|
||||
|
||||
LDV_STATUS cdecl Preview(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
return( Run( in, params, out ) ) ;
|
||||
}
|
||||
#pragma warn +par
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ldg_init( Ldg ) ;
|
||||
|
||||
return( 0 ) ;
|
||||
}
|
||||
BIN
tools/vision/ldv/src/rotate/rotate.ldv
Normal file
BIN
tools/vision/ldv/src/rotate/rotate.ldv
Normal file
Binary file not shown.
13
tools/vision/ldv/src/rotate/rotate.prj
Normal file
13
tools/vision/ldv/src/rotate/rotate.prj
Normal file
@@ -0,0 +1,13 @@
|
||||
ROTATE.LDV
|
||||
.C [ ]
|
||||
.S [ ]
|
||||
.L [ ]
|
||||
=
|
||||
pcstart.o
|
||||
ROTATE.C
|
||||
pcgemlib.lib
|
||||
pcstdlib.lib
|
||||
pctoslib.lib
|
||||
pcfltlib.lib
|
||||
..\..\ldg.lib
|
||||
..\..\mt_aes.lib
|
||||
187
tools/vision/ldv/src/xwave/xwave.c
Normal file
187
tools/vision/ldv/src/xwave/xwave.c
Normal file
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
*
|
||||
*
|
||||
* Version PureC / Gcc
|
||||
*/
|
||||
|
||||
#define PCGEMLIB 1 /* mettre 1 si les utilisateurs de Pure C
|
||||
* utilise les librairies GEM Pure C */
|
||||
|
||||
/* Fichiers headers */
|
||||
|
||||
#include <portab.h>
|
||||
#if PCGEMLIB
|
||||
#include <aes.h>
|
||||
#include <vdi.h>
|
||||
#else
|
||||
#include <aesbind.h>
|
||||
#include <vdibind.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "..\..\ldg.h"
|
||||
#include "..\..\vapi.h"
|
||||
#include "..\..\ldv.h"
|
||||
#include "..\..\mt_aes.h"
|
||||
|
||||
/* Prototypages */
|
||||
LDV_INFOS * cdecl GetLDVCapabilities(VAPI *vapi) ;
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
LDV_STATUS cdecl Preview(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
|
||||
void OnClose(void) ;
|
||||
|
||||
/* Variables globales */
|
||||
PROC Proc[] = {
|
||||
"GetLDVCapabilities", "Capacit<EFBFBD>s du LDV", (void *)GetLDVCapabilities,
|
||||
"PreRun", "Init du Run", (void *)PreRun,
|
||||
"Run", "Fonction du LDV", (void *)Run,
|
||||
"Preview", "Pre-Visu", (void *)Preview,
|
||||
} ;
|
||||
|
||||
char Info[] = "LDV";
|
||||
|
||||
LDGLIB Ldg[] = {
|
||||
0x0102, /* version de la lib, recommand<6E> */
|
||||
4, /* nombre de fonction dans la lib */
|
||||
Proc, /* Pointeurs vers nos fonctions */
|
||||
Info, /* Information sur la lib */
|
||||
0x0, /* Flags de la lib, obligatoire */
|
||||
OnClose, /* Fermeture, liberation de VDIHandle */
|
||||
};
|
||||
|
||||
#define CAPS (LDVF_SPECFORMAT | LDVF_SUPPORTPREVIEW | LDVF_SUPPORTPROG | LDVF_REALTIMEPARAMS | LDVF_SUPPORTCANCEL)
|
||||
|
||||
LDV_INFOS LdvInfos = {
|
||||
(short) sizeof(LDV_INFOS), /* Taille de cette structure */
|
||||
TLDV_MODIFYIMG, /* Type du LDV */
|
||||
"Jean Lusetti", /* Auteurs */
|
||||
{
|
||||
{ 1, 1, CAPS }, /* Capacites pour 1 plan */
|
||||
{ 2, 2, CAPS }, /* Capacites pour 2 plans */
|
||||
{ 4, 4, CAPS }, /* Capacites pour 4 plans */
|
||||
{ 8, 8, CAPS }, /* Capacites pour 8 plans */
|
||||
{ 16, 16, CAPS }, /* Capacites pour 16 plans */
|
||||
{ 24, 24, CAPS }, /* Capacites pour 24 plans */
|
||||
{ 32, 32, CAPS }, /* Capacites pour 32 plans */
|
||||
{ 0, 0, 0UL } /* Fin de la liste des capacites */
|
||||
},
|
||||
} ;
|
||||
|
||||
VAPI *Vapi = NULL ;
|
||||
int VDIHandle = -1 ;
|
||||
|
||||
void OnClose(void)
|
||||
{
|
||||
if ( VDIHandle != -1 ) v_clsvwk( VDIHandle ) ;
|
||||
VDIHandle = -1 ;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fonctions de la librairie
|
||||
*/
|
||||
|
||||
LDV_INFOS * cdecl GetLDVCapabilities(VAPI *vapi)
|
||||
{
|
||||
Vapi = vapi ;
|
||||
|
||||
return( &LdvInfos ) ;
|
||||
}
|
||||
|
||||
int vdihandle(void)
|
||||
{
|
||||
int work_in[11], work_out[57], i ;
|
||||
|
||||
for ( i = 0; i < 10; work_in[i++] = 1 ) ;
|
||||
work_in[10] = 2 ;
|
||||
v_opnvwk( work_in, &i, work_out ) ;
|
||||
|
||||
return( i ) ;
|
||||
}
|
||||
|
||||
#pragma warn -par
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
out->Raster.fd_w = in->Raster.fd_w ;
|
||||
out->Raster.fd_h = in->Raster.fd_h ;
|
||||
|
||||
return( ELDV_NOERROR ) ;
|
||||
}
|
||||
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
float angle, phi ;
|
||||
float amplitude ;
|
||||
int xy[8] ;
|
||||
short line ;
|
||||
short xoffset ;
|
||||
short pc, cancel = 0 ;
|
||||
|
||||
if ( VDIHandle == -1 ) VDIHandle = vdihandle() ;
|
||||
|
||||
if (
|
||||
( params->x1 != 0 ) || ( params->x2 != in->Raster.fd_w -1 ) ||
|
||||
( params->y1 != 0 ) || ( params->y2 != in->Raster.fd_h -1 )
|
||||
)
|
||||
{
|
||||
/* Bloc a l'interieur de l'image */
|
||||
xy[0] = xy[4] = 0 ;
|
||||
xy[1] = xy[5] = 0 ;
|
||||
xy[2] = xy[6] = in->Raster.fd_w - 1 ;
|
||||
xy[3] = xy[7] = in->Raster.fd_h - 1 ;
|
||||
vro_cpyfm( VDIHandle, S_ONLY, xy, &in->Raster, &out->Raster ) ;
|
||||
}
|
||||
else
|
||||
if ( Vapi && Vapi->RaImgWhite ) Vapi->RaImgWhite( &out->Raster ) ;
|
||||
|
||||
amplitude = (float)params->Param[0].s / 10.0 ;
|
||||
phi = M_PI * (float)params->Param[1].s / 10.0 / (float)(params->y2 - params->y1) ;
|
||||
for ( line = params->y1 ; !cancel && (line <= params->y2); line++ )
|
||||
{
|
||||
angle = (float) (line - params->y1) * phi ;
|
||||
xoffset = (short) (amplitude * ( 1+ sin( angle ) ) ) ;
|
||||
if ( params->x2 - xoffset < params->x1 ) xoffset = params->x2 - params->x1 ;
|
||||
if ( params->x2 - xoffset > in->Raster.fd_w - 1 ) xoffset = params->x2 - in->Raster.fd_w + 1 ;
|
||||
if ( params->x1 + xoffset > out->Raster.fd_w - 1 ) xoffset = out->Raster.fd_w - params->x1 - 1 ;
|
||||
if ( params->x2 < params->x1 + xoffset ) xoffset = params->x2 - params->x1 ;
|
||||
xy[0] = params->x1 ;
|
||||
xy[1] = line ;
|
||||
xy[2] = params->x2 - xoffset ;
|
||||
xy[3] = line ;
|
||||
xy[4] = params->x1 + xoffset ;
|
||||
xy[5] = line ;
|
||||
xy[6] = params->x2 ;
|
||||
xy[7] = line ;
|
||||
vro_cpyfm( VDIHandle, S_ONLY, xy, &in->Raster, &out->Raster ) ;
|
||||
if ( Vapi && ( line & 0x0F) == 0x0F )
|
||||
{
|
||||
/* Appelle la routine de progression une fois sur 16 */
|
||||
/* NB : en mode preview, VISION ignorera cet appel, */
|
||||
/* inutile donc de s'en soucier */
|
||||
pc = (short) ( ( 100L * (long)(line - params->y1) ) / (long)(params->y2 - params->y1) ) ;
|
||||
if ( Vapi->PrSetProgEx )
|
||||
{
|
||||
cancel = Vapi->PrSetProgEx( pc ) ;
|
||||
}
|
||||
else
|
||||
Vapi->PrSetProg( pc ) ;
|
||||
}
|
||||
}
|
||||
|
||||
return( cancel ? ELDV_CANCELLED : ELDV_NOERROR ) ;
|
||||
}
|
||||
|
||||
LDV_STATUS cdecl Preview(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
return( Run( in, params, out ) ) ;
|
||||
}
|
||||
#pragma warn +par
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ldg_init( Ldg ) ;
|
||||
return( 0 ) ;
|
||||
}
|
||||
BIN
tools/vision/ldv/src/xwave/xwave.ldv
Normal file
BIN
tools/vision/ldv/src/xwave/xwave.ldv
Normal file
Binary file not shown.
13
tools/vision/ldv/src/xwave/xwave.prj
Normal file
13
tools/vision/ldv/src/xwave/xwave.prj
Normal file
@@ -0,0 +1,13 @@
|
||||
xwave.ldv
|
||||
.C [ ]
|
||||
.S [ ]
|
||||
.L [ ]
|
||||
=
|
||||
pcstart.o
|
||||
xwave.c
|
||||
pcgemlib.lib
|
||||
pcstdlib.lib
|
||||
pctoslib.lib
|
||||
pcfltlib.lib
|
||||
..\..\ldg.lib
|
||||
..\..\mt_aes.lib
|
||||
269
tools/vision/ldv/src/ypersc/ypersc.c
Normal file
269
tools/vision/ldv/src/ypersc/ypersc.c
Normal file
@@ -0,0 +1,269 @@
|
||||
/*
|
||||
*
|
||||
*
|
||||
* Version PureC / Gcc
|
||||
*/
|
||||
|
||||
#define PCGEMLIB 1 /* mettre 1 si les utilisateurs de Pure C
|
||||
* utilise les librairies GEM Pure C */
|
||||
|
||||
/* Fichiers headers */
|
||||
|
||||
#include <portab.h>
|
||||
#if PCGEMLIB
|
||||
#include <aes.h>
|
||||
#include <vdi.h>
|
||||
#else
|
||||
#include <aesbind.h>
|
||||
#include <vdibind.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "..\..\ldg.h"
|
||||
#include "..\..\vapi.h"
|
||||
#include "..\..\ldv.h"
|
||||
#include "..\..\mt_aes.h"
|
||||
|
||||
/* Prototypages */
|
||||
LDV_INFOS * cdecl GetLDVCapabilities(VAPI *vapi) ;
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
LDV_STATUS cdecl Preview(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
|
||||
void OnClose(void) ;
|
||||
|
||||
/* Variables globales */
|
||||
PROC Proc[] = {
|
||||
"GetLDVCapabilities", "Capacit<EFBFBD>s du LDV", (void *)GetLDVCapabilities,
|
||||
"PreRun", "Init du Run", (void *)PreRun,
|
||||
"Run", "Fonction du LDV", (void *)Run,
|
||||
"Preview", "Pre-Visu", (void *)Preview,
|
||||
} ;
|
||||
|
||||
char Info[] = "LDV";
|
||||
|
||||
LDGLIB Ldg[] = {
|
||||
0x0101, /* version de la lib, recommand<6E> */
|
||||
4, /* nombre de fonction dans la lib */
|
||||
Proc, /* Pointeurs vers nos fonctions */
|
||||
Info, /* Information sur la lib */
|
||||
0x0, /* Flags de la lib, obligatoire */
|
||||
OnClose, /* Fermeture, liberation de VDIHandle */
|
||||
};
|
||||
|
||||
#define BP_CAPS (LDVF_ATARIFORMAT | LDVF_SUPPORTPREVIEW | LDVF_SUPPORTPROG | LDVF_REALTIMEPARAMS | LDVF_SUPPORTCANCEL | LDVF_NOSELECTION)
|
||||
#define TC_CAPS (LDVF_SPECFORMAT | LDVF_SUPPORTPREVIEW | LDVF_SUPPORTPROG | LDVF_REALTIMEPARAMS | LDVF_SUPPORTCANCEL)
|
||||
|
||||
LDV_INFOS LdvInfos = {
|
||||
(short) sizeof(LDV_INFOS), /* Taille de cette structure */
|
||||
TLDV_MODIFYIMG, /* Type du LDV */
|
||||
"Jean Lusetti", /* Auteurs */
|
||||
{
|
||||
{ 1, 1, BP_CAPS }, /* Capacites pour 1 plan */
|
||||
{ 2, 2, BP_CAPS }, /* Capacites pour 2 plans */
|
||||
{ 4, 4, BP_CAPS }, /* Capacites pour 4 plans */
|
||||
{ 8, 8, BP_CAPS }, /* Capacites pour 8 plans */
|
||||
{ 16, 16, TC_CAPS }, /* Capacites pour 16 plans */
|
||||
{ 32, 32, TC_CAPS }, /* Capacites pour 32 plans */
|
||||
{ 0, 0, 0UL } /* Fin de la liste des capacites */
|
||||
},
|
||||
} ;
|
||||
|
||||
VAPI *Vapi = NULL ;
|
||||
int VDIHandle = -1 ;
|
||||
|
||||
void OnClose(void)
|
||||
{
|
||||
if ( VDIHandle != -1 ) v_clsvwk( VDIHandle ) ;
|
||||
VDIHandle = -1 ;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fonctions de la librairie
|
||||
*/
|
||||
|
||||
LDV_INFOS * cdecl GetLDVCapabilities(VAPI *vapi)
|
||||
{
|
||||
Vapi = vapi ;
|
||||
|
||||
return( &LdvInfos ) ;
|
||||
}
|
||||
|
||||
int vdihandle(void)
|
||||
{
|
||||
int work_in[11], work_out[57], i ;
|
||||
|
||||
for ( i = 0; i < 10; work_in[i++] = 1 ) ;
|
||||
work_in[10] = 2 ;
|
||||
v_opnvwk( work_in, &i, work_out ) ;
|
||||
|
||||
return( i ) ;
|
||||
}
|
||||
|
||||
#pragma warn -par
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
out->Raster.fd_w = in->Raster.fd_w ;
|
||||
out->Raster.fd_h = in->Raster.fd_h ;
|
||||
|
||||
return( ELDV_NOERROR ) ;
|
||||
}
|
||||
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
MFDB dst_line ;
|
||||
int xy[8] ;
|
||||
long *pt32_in, *pt32_out ;
|
||||
short *pt16_in, *pt16_out ;
|
||||
unsigned char *pt8_in = NULL, *pt8_out ;
|
||||
long wscale, wout, wpixel, xpixel ;
|
||||
long angle, depth, src_line32, yoffset, lo_line_in, lo_line_out ;
|
||||
short line, y1, y2 ;
|
||||
short wlen, pc, cancel = 0 ;
|
||||
|
||||
if ( Vapi->Header.Version < 0x102 ) return( ELDV_BADVAPIVERSION ) ;
|
||||
|
||||
if ( VDIHandle == -1 ) VDIHandle = vdihandle() ;
|
||||
|
||||
if (
|
||||
( params->x1 != 0 ) || ( params->x2 != in->Raster.fd_w -1 ) ||
|
||||
( params->y1 != 0 ) || ( params->y2 != in->Raster.fd_h -1 )
|
||||
)
|
||||
{
|
||||
xy[0] = xy[4] = 0 ;
|
||||
xy[1] = xy[5] = 0 ;
|
||||
xy[2] = xy[6] = in->Raster.fd_w - 1 ;
|
||||
xy[3] = xy[7] = in->Raster.fd_h - 1 ;
|
||||
vro_cpyfm( VDIHandle, S_ONLY, xy, &in->Raster, &out->Raster ) ;
|
||||
xy[0] = params->x1 ; xy[1] = params->y1 ;
|
||||
xy[2] = params->x2 ; xy[3] = params->y2 ;
|
||||
xy[4] = params->x1 ; xy[5] = params->y1 ;
|
||||
xy[6] = params->x2 ; xy[7] = params->y2 ;
|
||||
vro_cpyfm( VDIHandle, ALL_WHITE, xy, &in->Raster, &out->Raster ) ;
|
||||
}
|
||||
else
|
||||
Vapi->RaImgWhite( &out->Raster ) ;
|
||||
|
||||
wpixel = 1+params->x2-params->x1 ;
|
||||
lo_line_in = ALIGN16( in->Raster.fd_w ) ;
|
||||
lo_line_out = ALIGN16( out->Raster.fd_w ) ;
|
||||
angle = (long) params->Param[0].s ;
|
||||
depth = (long) params->Param[1].s ;
|
||||
y1 = (long) params->y1 + (long) ( ((long)(params->y2 - params->y1)*angle) / 1000 ) ;
|
||||
y2 = (long) params->y1 + params->y2 - y1 ;
|
||||
|
||||
yoffset = ((long) (params->y2 - params->y1)) << 16 ;
|
||||
yoffset /= (long) (y2 - y1 ) ;
|
||||
if ( y1 > y2 )
|
||||
{
|
||||
short tmp ;
|
||||
|
||||
tmp = y1 ;
|
||||
y1 = y2 ;
|
||||
y2 = tmp ;
|
||||
src_line32 = params->y2 ;
|
||||
src_line32 <<= 16 ;
|
||||
}
|
||||
else
|
||||
{
|
||||
src_line32 = params->y1 ;
|
||||
src_line32 <<= 16 ;
|
||||
}
|
||||
|
||||
/* Mode bitplan : allocation memoire pour conversion index <--> format ATARI */
|
||||
/* pt16_... est utilise pour le mode 16 bits et le mode bit-plan (avec reajustement) */
|
||||
if ( in->Raster.fd_nplanes <= 8 )
|
||||
{
|
||||
size_t win ;
|
||||
|
||||
win = ALIGN16( in->Raster.fd_w ) ;
|
||||
wout = ALIGN16( out->Raster.fd_w ) ;
|
||||
pt8_in = (unsigned char *) malloc( win + wout ) ; /* Car on alloue aussi pour la remise a l'echelle */
|
||||
if ( pt8_in == NULL ) return ELDV_NOTENOUGHMEMORY ;
|
||||
pt8_out = pt8_in + in->Raster.fd_w ;
|
||||
|
||||
/* Pour conversions conversion index --> format ATARI (Vapi->RaInd2raster) */
|
||||
memcpy( &dst_line, &out->Raster, sizeof(MFDB) ) ;
|
||||
dst_line.fd_h = 1 ;
|
||||
|
||||
lo_line_in /= ( 16 / in->Raster.fd_nplanes ) ;
|
||||
lo_line_out /= ( 16 / in->Raster.fd_nplanes ) ;
|
||||
pt16_in = (short *) in->Raster.fd_addr ;
|
||||
pt16_out = (short *) out->Raster.fd_addr ;
|
||||
pt16_out += (long)(y1) * lo_line_out ;
|
||||
}
|
||||
else if ( in->Raster.fd_nplanes == 16 )
|
||||
{
|
||||
pt16_in = (short *) in->Raster.fd_addr ;
|
||||
pt16_out = (short *) out->Raster.fd_addr ;
|
||||
pt16_out += (long)(y1) * lo_line_out ;
|
||||
}
|
||||
else
|
||||
{
|
||||
pt32_in = (long *) in->Raster.fd_addr ;
|
||||
pt32_out = (long *) out->Raster.fd_addr ;
|
||||
pt32_out += (long)(y1) * lo_line_out ;
|
||||
}
|
||||
|
||||
wscale = ( wpixel * depth ) / 100L ;
|
||||
wlen = ALIGN16( 1+params->x2 ) ;
|
||||
for ( line = y1 ; !cancel && (line <= y2); line++, src_line32 += yoffset )
|
||||
{
|
||||
wout = wpixel - ( wscale * (line-y1) / (y2-y1) ) ;
|
||||
xpixel = params->x1 + ( ( wpixel - wout ) >> 1 ) ;
|
||||
switch( in->Raster.fd_nplanes )
|
||||
{
|
||||
case 1 :
|
||||
case 2 :
|
||||
case 4 :
|
||||
case 8 :
|
||||
Vapi->RaRaster2Ind( pt16_in + (src_line32 >> 16) * lo_line_in, wlen, in->Raster.fd_nplanes, pt8_in ) ;
|
||||
memset( pt8_out, 0, xpixel ) ;
|
||||
Vapi->MeSCopyMemory8( pt8_out + xpixel, pt8_in + params->x1, wout, wpixel ) ;
|
||||
dst_line.fd_addr = pt16_out ;
|
||||
Vapi->RaInd2RasterInit( &dst_line, xpixel+wout-1 ) ;
|
||||
Vapi->RaInd2Raster( pt8_out, xpixel+wout-1 ) ;
|
||||
pt16_out += lo_line_out ;
|
||||
break ;
|
||||
|
||||
case 16 : Vapi->MeSCopyMemory16( pt16_out + xpixel,
|
||||
pt16_in + (long)params->x1 + (src_line32 >> 16) * lo_line_in,
|
||||
wout, wpixel ) ;
|
||||
pt16_out += lo_line_out ;
|
||||
break ;
|
||||
|
||||
case 32 : Vapi->MeSCopyMemory32( pt32_out + xpixel,
|
||||
pt32_in + (long)params->x1 + (src_line32 >> 16) * lo_line_in,
|
||||
wout, wpixel ) ;
|
||||
pt32_out += lo_line_out ;
|
||||
default: break ;
|
||||
}
|
||||
if ( Vapi && ( line & 0x0F) == 0x0F )
|
||||
{
|
||||
/* Appelle la routine de progression une fois sur 16 */
|
||||
/* NB : en mode preview, VISION ignorera cet appel, */
|
||||
/* inutile donc de s'en soucier */
|
||||
pc = (short) ( ( 100L * (long)(line - y1) ) / (long)(y2 - y1) ) ;
|
||||
cancel = Vapi->PrSetProgEx( pc ) ;
|
||||
}
|
||||
}
|
||||
|
||||
if ( pt8_in ) free( pt8_in ) ;
|
||||
|
||||
return( cancel ? ELDV_CANCELLED : ELDV_NOERROR ) ;
|
||||
}
|
||||
|
||||
LDV_STATUS cdecl Preview(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
return( Run( in, params, out ) ) ;
|
||||
}
|
||||
#pragma warn +par
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ldg_init( Ldg ) ;
|
||||
|
||||
return( 0 ) ;
|
||||
}
|
||||
BIN
tools/vision/ldv/src/ypersc/ypersc.ldv
Normal file
BIN
tools/vision/ldv/src/ypersc/ypersc.ldv
Normal file
Binary file not shown.
13
tools/vision/ldv/src/ypersc/ypersc.prj
Normal file
13
tools/vision/ldv/src/ypersc/ypersc.prj
Normal file
@@ -0,0 +1,13 @@
|
||||
YPERSC.LDV
|
||||
.C [ ]
|
||||
.S [ ]
|
||||
.L [ ]
|
||||
=
|
||||
pcstart.o
|
||||
YPERSC.C
|
||||
pcgemlib.lib
|
||||
pcstdlib.lib
|
||||
pctoslib.lib
|
||||
pcfltlib.lib
|
||||
..\..\ldg.lib
|
||||
..\..\mt_aes.lib
|
||||
187
tools/vision/ldv/src/ywave/ywave.c
Normal file
187
tools/vision/ldv/src/ywave/ywave.c
Normal file
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
*
|
||||
*
|
||||
* Version PureC / Gcc
|
||||
*/
|
||||
|
||||
#define PCGEMLIB 1 /* mettre 1 si les utilisateurs de Pure C
|
||||
* utilise les librairies GEM Pure C */
|
||||
|
||||
/* Fichiers headers */
|
||||
|
||||
#include <portab.h>
|
||||
#if PCGEMLIB
|
||||
#include <aes.h>
|
||||
#include <vdi.h>
|
||||
#else
|
||||
#include <aesbind.h>
|
||||
#include <vdibind.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "..\..\ldg.h"
|
||||
#include "..\..\vapi.h"
|
||||
#include "..\..\ldv.h"
|
||||
#include "..\..\mt_aes.h"
|
||||
|
||||
/* Prototypages */
|
||||
LDV_INFOS * cdecl GetLDVCapabilities(VAPI *vapi) ;
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
LDV_STATUS cdecl Preview(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out) ;
|
||||
|
||||
void OnClose(void) ;
|
||||
|
||||
/* Variables globales */
|
||||
PROC Proc[] = {
|
||||
"GetLDVCapabilities", "Capacit<EFBFBD>s du LDV", (void *)GetLDVCapabilities,
|
||||
"PreRun", "Init du Run", (void *)PreRun,
|
||||
"Run", "Fonction du LDV", (void *)Run,
|
||||
"Preview", "Pre-Visu", (void *)Preview,
|
||||
} ;
|
||||
|
||||
char Info[] = "LDV";
|
||||
|
||||
LDGLIB Ldg[] = {
|
||||
0x0101, /* version de la lib, recommand<6E> */
|
||||
4, /* nombre de fonction dans la lib */
|
||||
Proc, /* Pointeurs vers nos fonctions */
|
||||
Info, /* Information sur la lib */
|
||||
0x0, /* Flags de la lib, obligatoire */
|
||||
OnClose, /* Fermeture, liberation de VDIHandle */
|
||||
};
|
||||
|
||||
#define CAPS (LDVF_SPECFORMAT | LDVF_SUPPORTPREVIEW | LDVF_SUPPORTPROG | LDVF_REALTIMEPARAMS | LDVF_SUPPORTCANCEL)
|
||||
|
||||
LDV_INFOS LdvInfos = {
|
||||
(short) sizeof(LDV_INFOS), /* Taille de cette structure */
|
||||
TLDV_MODIFYIMG, /* Type du LDV */
|
||||
"Jean Lusetti", /* Auteurs */
|
||||
{
|
||||
{ 1, 1, CAPS }, /* Capacites pour 1 plan */
|
||||
{ 2, 2, CAPS }, /* Capacites pour 2 plans */
|
||||
{ 4, 4, CAPS }, /* Capacites pour 4 plans */
|
||||
{ 8, 8, CAPS }, /* Capacites pour 8 plans */
|
||||
{ 16, 16, CAPS }, /* Capacites pour 16 plans */
|
||||
{ 24, 24, CAPS }, /* Capacites pour 24 plans */
|
||||
{ 32, 32, CAPS }, /* Capacites pour 32 plans */
|
||||
{ 0, 0, 0UL } /* Fin de la liste des capacites */
|
||||
},
|
||||
} ;
|
||||
|
||||
VAPI *Vapi = NULL ;
|
||||
int VDIHandle = -1 ;
|
||||
|
||||
void OnClose(void)
|
||||
{
|
||||
if ( VDIHandle != -1 ) v_clsvwk( VDIHandle ) ;
|
||||
VDIHandle = -1 ;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fonctions de la librairie
|
||||
*/
|
||||
|
||||
LDV_INFOS * cdecl GetLDVCapabilities(VAPI *vapi)
|
||||
{
|
||||
Vapi = vapi ;
|
||||
|
||||
return( &LdvInfos ) ;
|
||||
}
|
||||
|
||||
int vdihandle(void)
|
||||
{
|
||||
int work_in[11], work_out[57], i ;
|
||||
|
||||
for ( i = 0; i < 10; work_in[i++] = 1 ) ;
|
||||
work_in[10] = 2 ;
|
||||
v_opnvwk( work_in, &i, work_out ) ;
|
||||
|
||||
return( i ) ;
|
||||
}
|
||||
|
||||
#pragma warn -par
|
||||
LDV_STATUS cdecl PreRun(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
out->Raster.fd_w = in->Raster.fd_w ;
|
||||
out->Raster.fd_h = in->Raster.fd_h ;
|
||||
|
||||
return( ELDV_NOERROR ) ;
|
||||
}
|
||||
|
||||
LDV_STATUS cdecl Run(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
float angle, phi ;
|
||||
float amplitude ;
|
||||
int xy[8] ;
|
||||
short row ;
|
||||
short yoffset ;
|
||||
short pc, cancel = 0 ;
|
||||
|
||||
if ( VDIHandle == -1 ) VDIHandle = vdihandle() ;
|
||||
|
||||
if (
|
||||
( params->x1 != 0 ) || ( params->x2 != in->Raster.fd_w -1 ) ||
|
||||
( params->y1 != 0 ) || ( params->y2 != in->Raster.fd_h -1 )
|
||||
)
|
||||
{
|
||||
/* Bloc a l'interieur de l'image */
|
||||
xy[0] = xy[4] = 0 ;
|
||||
xy[1] = xy[5] = 0 ;
|
||||
xy[2] = xy[6] = in->Raster.fd_w - 1 ;
|
||||
xy[3] = xy[7] = in->Raster.fd_h - 1 ;
|
||||
vro_cpyfm( VDIHandle, S_ONLY, xy, &in->Raster, &out->Raster ) ;
|
||||
}
|
||||
else
|
||||
if ( Vapi && Vapi->RaImgWhite ) Vapi->RaImgWhite( &out->Raster ) ;
|
||||
|
||||
amplitude = (float)params->Param[0].s / 10.0 ;
|
||||
phi = M_PI * (float)params->Param[1].s / 10.0 / (float)(params->x2 - params->x1) ;
|
||||
for ( row = params->x1 ; !cancel && (row <= params->x2); row++ )
|
||||
{
|
||||
angle = (float) (row - params->x1) * phi ;
|
||||
yoffset = (short) (amplitude * ( 1+ sin( angle ) ) ) ;
|
||||
if ( params->y2 - yoffset < params->y1 ) yoffset = params->y2 - params->y1 ;
|
||||
if ( params->y2 - yoffset > in->Raster.fd_h - 1 ) yoffset = params->y2 - in->Raster.fd_h + 1 ;
|
||||
if ( params->y1 + yoffset > out->Raster.fd_h - 1 ) yoffset = out->Raster.fd_h - params->y1 - 1 ;
|
||||
if ( params->y2 < params->y1 + yoffset ) yoffset = params->y2 - params->y1 ;
|
||||
xy[0] = row ;
|
||||
xy[1] = params->y1 ;
|
||||
xy[2] = row ;
|
||||
xy[3] = params->y2 - yoffset ;
|
||||
xy[4] = row ;
|
||||
xy[5] = params->y1 + yoffset ;
|
||||
xy[6] = row ;
|
||||
xy[7] = params->y2 ;
|
||||
vro_cpyfm( VDIHandle, S_ONLY, xy, &in->Raster, &out->Raster ) ;
|
||||
if ( Vapi && ( row & 0x0F) == 0x0F )
|
||||
{
|
||||
/* Appelle la routine de progression une fois sur 16 */
|
||||
/* NB : en mode preview, VISION ignorera cet appel, */
|
||||
/* inutile donc de s'en soucier */
|
||||
pc = (short) ( ( 100L * (long)(row - params->x1) ) / (long)(params->x2 - params->x1) ) ;
|
||||
if ( Vapi->PrSetProgEx )
|
||||
{
|
||||
cancel = Vapi->PrSetProgEx( pc ) ;
|
||||
}
|
||||
else
|
||||
Vapi->PrSetProg( pc ) ;
|
||||
}
|
||||
}
|
||||
|
||||
return( cancel ? ELDV_CANCELLED : ELDV_NOERROR ) ;
|
||||
}
|
||||
|
||||
LDV_STATUS cdecl Preview(LDV_IMAGE *in, LDV_PARAMS *params, LDV_IMAGE *out)
|
||||
{
|
||||
return( Run( in, params, out ) ) ;
|
||||
}
|
||||
#pragma warn +par
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ldg_init( Ldg ) ;
|
||||
return( 0 ) ;
|
||||
}
|
||||
BIN
tools/vision/ldv/src/ywave/ywave.ldv
Normal file
BIN
tools/vision/ldv/src/ywave/ywave.ldv
Normal file
Binary file not shown.
13
tools/vision/ldv/src/ywave/ywave.prj
Normal file
13
tools/vision/ldv/src/ywave/ywave.prj
Normal file
@@ -0,0 +1,13 @@
|
||||
ywave.ldv
|
||||
.C [ ]
|
||||
.S [ ]
|
||||
.L [ ]
|
||||
=
|
||||
pcstart.o
|
||||
ywave.c
|
||||
pcgemlib.lib
|
||||
pcstdlib.lib
|
||||
pctoslib.lib
|
||||
pcfltlib.lib
|
||||
..\..\ldg.lib
|
||||
..\..\mt_aes.lib
|
||||
Reference in New Issue
Block a user