void select_assign(Node var_node, Node expr_node, Symbol type_name) /*;select_assign*/ { Symbol var_name, expr_name; var_name = N_UNQ(var_node); expr_name = N_UNQ(expr_node); if (is_simple_type(type_name) && is_simple_name(var_node) && !is_renaming(var_name) ) { if ((is_simple_name(expr_node) && N_KIND(expr_node) != as_null && !is_renaming(expr_name)) || (N_KIND(expr_node) == as_selector || N_KIND(expr_node) == as_index || N_KIND(expr_node) == as_all)) { gen_address(expr_node); gen_ks(I_INDIRECT_POP, kind_of(type_name), var_name); } else { gen_value(expr_node); gen_ks(I_POP, kind_of(type_name), var_name); } } else { gen_address(var_node); select_move(expr_node, type_name); } }
static void select_move(Node node, Symbol type_name) /*;select_move*/ { if (is_simple_type(type_name)) { if ((N_KIND(node) != as_null && is_simple_name(node) && !is_renaming(N_UNQ(node))) || (N_KIND(node) == as_selector || N_KIND(node) == as_index || N_KIND(node) == as_all)) { gen_address(node); gen_k(I_INDIRECT_MOVE, kind_of(type_name)); } else { gen_value(node); gen_k(I_MOVE, kind_of(type_name)); } } else { if (is_array_type(type_name)) { gen_value(node); gen(I_ARRAY_MOVE); } else { gen_value(node); gen_s(I_RECORD_MOVE, type_name); } } }
Handle Window_menu( Handle self, Bool set, Handle menu) { if ( var-> stage > csFrozen) return nilHandle; if ( !set) return var-> menu; if ( menu && !kind_of( menu, CMenu)) return nilHandle; if ( menu && (( PMenu) menu)-> owner != self) my-> set_menuItems( self, ((( PMenu) menu)-> self)-> get_items( menu, "")); else { apc_window_set_menu( self, menu); var-> menu = menu; if ( menu) { int i; ColorSet menuColor; memcpy( menuColor, var-> menuColor, sizeof( ColorSet)); for ( i = 0; i < ciMaxId + 1; i++) apc_menu_set_color( menu, menuColor[ i], i); memcpy( var-> menuColor, menuColor, sizeof( ColorSet)); apc_menu_set_font( menu, &var-> menuFont); } } return nilHandle; }
Handle Widget_shape( Handle self, Bool set, Handle mask) { if ( var-> stage > csFrozen) return nilHandle; if ( !set) { if ( apc_widget_get_shape( self, nilHandle)) { HV * profile = newHV(); Handle i = Object_create( "Prima::Image", profile); sv_free(( SV *) profile); apc_widget_get_shape( self, i); --SvREFCNT( SvRV((( PAnyObject) i)-> mate)); return i; } else return nilHandle; } if ( mask && !kind_of( mask, CImage)) { warn("RTC008A: Illegal object reference passed to Widget::shape"); return nilHandle; } if ( mask && (( PImage( mask)-> type & imBPP) != imbpp1)) { Handle i = CImage( mask)-> dup( mask); ++SvREFCNT( SvRV( PImage( i)-> mate)); CImage( i)-> set_conversion( i, ictNone); CImage( i)-> set_type( i, imBW); apc_widget_set_shape( self, i); --SvREFCNT( SvRV( PImage( i)-> mate)); Object_destroy( i); } else apc_widget_set_shape( self, mask); return nilHandle; }
Handle Window_icon( Handle self, Bool set, Handle icon) { if ( var-> stage > csFrozen) return nilHandle; if ( !set) { if ( apc_window_get_icon( self, nilHandle)) { HV * profile = newHV(); Handle i = Object_create( "Prima::Icon", profile); sv_free(( SV *) profile); apc_window_get_icon( self, i); --SvREFCNT( SvRV((( PAnyObject) i)-> mate)); return i; } else return nilHandle; } if ( icon && !kind_of( icon, CImage)) { warn("Illegal object reference passed to Window::icon"); return nilHandle; } my-> first_that( self, (void*)icon_notify, (void*)icon); apc_window_set_icon( self, icon); opt_clear( optOwnerIcon); return nilHandle; }
Handle Widget_pointerIcon( Handle self, Bool set, Handle icon) { enter_method; Point hotSpot; if ( var-> stage > csFrozen) return nilHandle; if ( !set) { HV * profile = newHV(); Handle icon = Object_create( "Prima::Icon", profile); sv_free(( SV *) profile); apc_pointer_get_bitmap( self, icon); --SvREFCNT( SvRV((( PAnyObject) icon)-> mate)); return icon; } if ( icon != nilHandle && !kind_of( icon, CIcon)) { warn("RTC083: Illegal object reference passed to Widget::pointerIcon"); return nilHandle; } hotSpot = my-> get_pointerHotSpot( self); apc_pointer_set_user( self, icon, hotSpot); if ( var-> pointerType == crUser) my-> first_that( self, (void*)sptr, nil); return nilHandle; }
static SV * image_server( Handle self, PClipboardFormatReg instance, int function, SV * data) { ClipboardDataRec c; switch( function) { case cefInit: return ( SV *) cfBitmap; case cefFetch: { HV * profile = newHV(); c. image = Object_create( "Prima::Image", profile); sv_free(( SV *) profile); if ( apc_clipboard_get_data( self, cfBitmap, &c)) { --SvREFCNT( SvRV( PImage(c. image)-> mate)); return newSVsv( PImage(c. image)-> mate); } Object_destroy( c. image); } break; case cefStore: c. image = gimme_the_mate( data); if ( !kind_of( c. image, CImage)) { warn("Not an image passed to clipboard"); return nilSV; } instance-> success = apc_clipboard_set_data( self, cfBitmap, &c); instance-> written = true; break; } return nilSV; }
Bool Timer_validate_owner( Handle self, Handle * owner, HV * profile) { dPROFILE; *owner = pget_H( owner); if ( !kind_of( *owner, CWidget)) return false; return inherited validate_owner( self, owner, profile); }
Bool Window_validate_owner( Handle self, Handle * owner, HV * profile) { dPROFILE; *owner = pget_H( owner); if ( *owner != application && !kind_of( *owner, CWidget)) return false; return inherited validate_owner( self, owner, profile); }
static Bool icon_notify ( Handle self, Handle child, Handle icon) { if ( kind_of( child, CWindow) && (( PWindow) child)-> options. optOwnerIcon) { (( PWindow) child)-> self-> set_icon( child, icon); (( PWindow) child)-> options. optOwnerIcon = 1; } return false; }
HICON image_make_icon_handle( Handle img, Point size, Point * hotSpot) { PIcon i = ( PIcon) img; HICON r; ICONINFO ii; int bpp = i-> type & imBPP; Bool noSZ = i-> w != size. x || i-> h != size. y; Bool noBPP = bpp != 1 && bpp != 4 && bpp != 8 && bpp != 24; HDC dc; XBITMAPINFO bi; Bool notAnIcon = !kind_of( img, CIcon); ii. fIcon = hotSpot ? false : true; ii. xHotspot = hotSpot ? hotSpot-> x : 0; ii. yHotspot = hotSpot ? hotSpot-> y : 0; if ( noSZ || noBPP) { i = ( PIcon)( i-> self-> dup( img)); if ( noSZ) i-> self-> set_size(( Handle) i, size); if ( noBPP) i-> self-> set_type(( Handle) i, ( bpp < 4) ? 1 : (( bpp < 8) ? 4 : (( bpp < 24) ? 8 : 24)) ); } if (!( dc = dc_alloc())) { if (( Handle) i != img) Object_destroy(( Handle) i); return NULL; } image_get_binfo(( Handle)i, &bi); if ( bi. bmiHeader. biClrUsed > 0) bi. bmiHeader. biClrUsed = bi. bmiHeader. biClrImportant = i-> palSize; if ( !( ii. hbmColor = CreateDIBitmap( dc, &bi. bmiHeader, CBM_INIT, i-> data, ( BITMAPINFO*) &bi, DIB_RGB_COLORS))) apiErr; bi. bmiHeader. biBitCount = bi. bmiHeader. biPlanes = 1; bi. bmiColors[ 0]. rgbRed = bi. bmiColors[ 0]. rgbGreen = bi. bmiColors[ 0]. rgbBlue = 0; bi. bmiColors[ 1]. rgbRed = bi. bmiColors[ 1]. rgbGreen = bi. bmiColors[ 1]. rgbBlue = 255; if ( !( ii. hbmMask = CreateDIBitmap( dc, &bi. bmiHeader, CBM_INIT, notAnIcon ? NULL : i-> mask, ( BITMAPINFO*) &bi, DIB_RGB_COLORS))) apiErr; dc_free(); if ( !( r = CreateIconIndirect( &ii))) apiErr; DeleteObject( ii. hbmColor); DeleteObject( ii. hbmMask); if (( Handle) i != img) Object_destroy(( Handle) i); return r; }
void Application_detach( Handle self, Handle objectHandle, Bool kill) { inherited detach( self, objectHandle, kill); if ( var-> autoClose && ( var-> widgets. count == 1) && kind_of( objectHandle, CWidget) && ( objectHandle != var-> hintWidget) ) my-> close( self); }
Handle Application_top_frame( Handle self, Handle from) { while ( from) { if ( kind_of( from, CWindow) && (( PWidget( from)-> owner == application) || !CWidget( from)-> get_clipOwner(from)) ) return from; from = PWidget( from)-> owner; } return application; }
Bool Window_execute_shared( Handle self, Handle insertBefore) { if ( var-> modal || var-> nextSharedModal) return false; if ( insertBefore && (( insertBefore == self) || ( !kind_of( insertBefore, CWindow)) || ( PWindow( insertBefore)-> modal != mtShared) || ( CWindow( insertBefore)-> get_horizon( insertBefore) != my-> get_horizon( self)))) insertBefore = nilHandle; return apc_window_execute_shared( self, insertBefore); }
void AbstractMenu_init( Handle self, HV * profile) { dPROFILE; inherited init( self, profile); var-> anchored = kind_of( self, CMenu); my-> update_sys_handle( self, profile); my-> set_items( self, pget_sv( items)); if ( var-> system) apc_menu_update( self, nil, var-> tree); if ( pget_B( selected)) my-> set_selected( self, true); CORE_INIT_TRANSIENT(AbstractMenu); }
/* checks if Handle in is allowed to be a master for self - used for gt::Pack */ static Handle Widget_check_in( Handle self, Handle in, Bool barf) { Handle h = in; /* check overall validity */ if ( !in || !kind_of( in, CWidget)) { if ( barf) croak("%s: invalid 'in': not a widget", "RTC008F: Prima::Widget::pack"); else return nilHandle; } /* check direct inheritance */ while ( h) { if ( h == self) { if ( barf) croak("%s: invalid 'in': is already a child", "RTC008F: Prima::Widget::pack"); else return nilHandle; } h = PWidget( h)-> owner; } /* check slaves chain */ h = PWidget( in)-> packSlaves; while ( h) { if ( h == in) { if ( barf) croak("%s: invalid 'in': already a pack slave", "RTC008F: Prima::Widget::pack"); else return nilHandle; } h = PWidget( h)-> geomInfo. next; } h = PWidget( in)-> placeSlaves; while ( h) { if ( h == in) { if ( barf) croak("%s: invalid 'in': already a place slave", "RTC008F: Prima::Widget::pack"); else return nilHandle; } h = PWidget( h)-> geomInfo. next; } /* place to check other chains if needed */ return in; }
bool Slot::add_connection(Slot *slot) { if (type_id() == NO_TYPE_TAG_ID || slot->type_id() == NO_TYPE_TAG_ID) return false; // one of them is a NoIO assert(type().size() > 0); assert(slot->type().size() > 0); if ((kind_of(Inlet) && can_receive(slot->type()[0])) || (slot->kind_of(Inlet) && slot->can_receive(type()[0]))) { // same type signature or inlet receiving any type // OrderedList makes sure the link is not created again if it already exists. connections_.push(slot); return true; } else { return false; } }
Handle Widget_accelTable( Handle self, Bool set, Handle accelTable) { enter_method; if ( var-> stage > csFrozen) return nilHandle; if ( !set) return var-> accelTable; if ( accelTable && !kind_of( accelTable, CAbstractMenu)) return nilHandle; if ( accelTable && (( PAbstractMenu) accelTable)-> owner != self) my-> set_accelItems( self, CAbstractMenu( accelTable)-> get_items( accelTable, "")); else var-> accelTable = accelTable; return accelTable; }
/* FFT profile keys: inverse => BOOL; direct or inverse transform */ PImage IPA__Global_fft(PImage img,HV *profile) { #define METHOD "IPA::Global::fft" dPROFILE; Bool inverse = 0, failed = false; PImage ret = nil; double * buffer = nil; if ( sizeof(double) % 2) { warn("%s:'double' is even-sized on this platform", METHOD); return nil; } if ( !img || !kind_of(( Handle) img, CImage)) croak("%s: not an image passed", METHOD); if ( !pow2( img-> w)) croak("%s: image width is not a power of 2", METHOD); if ( !pow2( img-> h)) croak("%s: image height is not a power of 2", METHOD); if ( pexist( inverse)) inverse = pget_B( inverse); /* preparing structures */ ret = ( PImage) img-> self-> dup(( Handle) img); if ( !ret) fail( "%s: Return image allocation failed"); ++SvREFCNT( SvRV( ret-> mate)); ret-> self-> set_type(( Handle) ret, imDComplex); if ( ret-> type != imDComplex) { warn("%s:Cannot set image to imDComplex", METHOD); failed = 1; goto EXIT; } buffer = malloc((sizeof(double) * img-> w * 2)); if ( !buffer) { warn("%s: Error allocating %d bytes", METHOD, (int)(sizeof(double) * img-> w * 2)); failed = 1; goto EXIT; } fft_2d(( double *) ret-> data, ret-> w, ret-> h, inverse ? FFT_INVERSE : FFT_DIRECT, buffer); EXIT: free( buffer); if ( ret) --SvREFCNT( SvRV( ret-> mate)); return failed ? nil : ret; #undef METHOD }
Handle Widget_popup( Handle self, Bool set, Handle popup) { enter_method; if ( var-> stage > csFrozen) return nilHandle; if ( !set) return var-> popupMenu; if ( popup && !kind_of( popup, CPopup)) return nilHandle; if ( popup && PAbstractMenu( popup)-> owner != self) my-> set_popupItems( self, CAbstractMenu( popup)-> get_items( popup, "")); else var-> popupMenu = popup; return nilHandle; }
boolean Thought_Bubble::equal_to(Sprite *other, Sprites *pending, SpritesPointer &corresponding_nests, SpritesPointer &expected_corresponding_nests, EqualReason reason) { // new on 060601 if (other->kind_of() != kind_of()) return(FALSE); if (other == this) return(TRUE); Thought_Bubble *other_bubble = (Thought_Bubble *) other; if (pointer_to_cubby() != NULL) { if (other_bubble->pointer_to_cubby() != NULL) { // started using top_level_equal_to on 08061 since no sharing should exist between thought bubble cubby and the rest return(pointer_to_cubby()->top_level_equal_to(other_bubble->pointer_to_cubby(),corresponding_nests,expected_corresponding_nests,reason)); } else { return(FALSE); }; } else { return(other_bubble->pointer_to_cubby() == NULL); }; };
Bool image_screenable( Handle image, Handle screen, int * bitCount) { PImage i = ( PImage) image; if (( i-> type & ( imRealNumber | imComplexNumber | imTrigComplexNumber)) || ( i-> type == imLong || i-> type == imShort)) { if ( bitCount) *bitCount = 8; return false; } if ( i-> type == imRGB) { if ( !screen) return true; if ( kind_of( screen, CPrinter)) /* make printer itself to do the dithering */ return true; if ( dsys( screen) options. aptCompatiblePS || !dsys( screen) ps) { int bpp = guts. displayBMInfo. bmiHeader. biBitCount * guts. displayBMInfo. bmiHeader. biPlanes; if ( bpp) { if ( bitCount) { *bitCount = bpp; if ( *bitCount < 4) *bitCount = 1; else if ( *bitCount < 8) *bitCount = 4; else return true; } return false; } } else { if ( dsys( screen) bpp == 0) { if ( !dsys(screen) ps) { *bitCount = 1; return false; } dsys( screen) bpp = GetDeviceCaps( dsys(screen) ps, BITSPIXEL); } if ( dsys( screen) bpp <= 8) { *bitCount = dsys( screen) bpp; if ( *bitCount < 4) *bitCount = 1; else if ( *bitCount < 8) *bitCount = 4; return false; } } } return true; }
int Window_execute( Handle self, Handle insertBefore) { if ( var-> modal) return mbCancel; protect_object( self); if ( insertBefore && ( insertBefore == self || !kind_of( insertBefore, CWindow) || PWindow( insertBefore)-> modal != mtExclusive)) insertBefore = nilHandle; if ( !apc_window_execute( self, insertBefore)) var-> modalResult = mbCancel; unprotect_object( self); return var-> modalResult; }
const Value Slot::change_link(unsigned char operation, const Value &val) { if (val.is_string()) { // update a link (create/destroy) Object * target = root_->object_at(val.str()); if (!target) return ErrorValue(NOT_FOUND_ERROR, val.str()); if (!target->kind_of(Slot)) { target = target->child("in"); if (target) target = target->first_child(); // target/out/... if (!target) { return ErrorValue(NOT_FOUND_ERROR, val.str()).append(": slot not found"); } } if (kind_of(Outlet)) { // other should be an Inlet target = (Slot*)TYPE_CAST(Inlet, target); } else { // other should be an Outlet target = (Slot*)TYPE_CAST(Outlet,target); } if (!target) { return ErrorValue(BAD_REQUEST_ERROR, "Could not update link with ").append(val.to_json()).append(": incompatible)."); } if (operation == 'c') { // create link if (connect((Slot*)target)) { //std::cout << "LINKED: " << url() << " with " << val << std::endl; return Value(url()).push_back("=>").push_back(target->url()); } else { return ErrorValue(BAD_REQUEST_ERROR, "Could not make the connection with (").append(val.to_json()).append(")."); } } else { // disconnect disconnect((Slot*)target); return Value(url()).push_back("||").push_back(target->url()); } } else { return Value(info()); } }
PImage IPA__Morphology_BWTransform(PImage img,HV *profile) { dPROFILE; const char *method="IPA::Morphology::BWTransform"; PImage oimg; unsigned char *transtbl = nil; if ( !img || !kind_of(( Handle) img, CImage)) croak("%s: not an image passed", "IPA::Morphology::BWTransform"); if (pexist(lookup)) { SV *tblstr=pget_sv(lookup); if (SvPOK(tblstr)) { STRLEN tbllen; transtbl=SvPV(tblstr,tbllen); if (tbllen!=512) { croak("%s: 'lookup' is %d bytes long, must be 512",method,tbllen); } } else { croak("%s : 'lookup' is not a string",method); } } else { croak("%s : 'lookup' option missed",method); } switch (img->type) { case imByte: oimg=bw8bpp_transform(method,img,transtbl,1); break; default: croak("%s: support for this type of images isn't realized yet",method); } return oimg; }
Handle Application_icon( Handle self, Bool set, Handle icon) { if ( var-> stage > csFrozen) return nilHandle; if ( !set) return var-> icon; if ( icon && !kind_of( icon, CImage)) { warn("Illegal object reference passed to Application::icon"); return nilHandle; } if ( icon) { icon = ((( PImage) icon)-> self)-> dup( icon); ++SvREFCNT( SvRV((( PAnyObject) icon)-> mate)); } my-> first_that( self, (void*)icon_notify, (void*)icon); if ( var-> icon) my-> detach( self, var-> icon, true); var-> icon = icon; if ( icon && ( list_index_of( var-> components, icon) < 0)) my-> attach( self, icon); return nilHandle; }
Handle AbstractMenu_image( Handle self, Bool set, char * varName, Handle image) { PMenuItemReg m; PImage i = ( PImage) image; if ( var-> stage > csFrozen) return nilHandle; m = find_menuitem( self, varName, true); if ( m == nil) return nilHandle; if ( !m-> bitmap) return nilHandle; if ( !set) { if ( PObject( m-> bitmap)-> stage == csDead) return nilHandle; return m-> bitmap; } if (( image == nilHandle) || !( kind_of( image, CImage))) { warn("invalid object passed to ::image"); return nilHandle; } if ( i-> w == 0 || i-> h == 0) { warn("invalid object passed to ::image"); return nilHandle; } SvREFCNT_inc( SvRV(( PObject( image))-> mate)); protect_object( image); if ( PObject( m-> bitmap)-> stage < csDead) SvREFCNT_dec( SvRV(( PObject( m-> bitmap))-> mate)); unprotect_object( m-> bitmap); m-> bitmap = image; if ( m-> id > 0) if ( var-> stage <= csNormal && var-> system) apc_menu_item_set_image( self, m); return nilHandle; }
static Bool load( PImgCodec instance, PImgLoadFileInstance fi) { dPROFILE; LoadRec * l = ( LoadRec *) fi-> instance; png_uint_32 width, height; int obd, bit_depth, color_type, interlace_type, bpp, number_passes, pass, filter; HV * profile; Color background; int alpha_opt, channels, trns_n; Bool icon; Handle alpha_image; png_bytep trns_t; png_color_16p trns_p; if (setjmp(png_jmpbuf( l-> png_ptr)) != 0) return false; profile = fi-> profile; png_read_info(l->png_ptr, l->info_ptr); png_get_IHDR(l->png_ptr, l->info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, NULL, &filter); obd = bit_depth; channels = (int) png_get_channels(l->png_ptr, l->info_ptr); icon = kind_of( fi-> object, CIcon); switch ( bit_depth) { case 1: case 4: case 8: break; case 2: png_set_packing(l->png_ptr); bit_depth = 4; break; case 16: png_set_strip_16(l->png_ptr); bit_depth = 8; break; default: sprintf( fi-> errbuf, "Bit depth %d is not supported", bit_depth); return false; } switch ( color_type) { case PNG_COLOR_TYPE_GRAY: bpp = bit_depth | imGrayScale; break; case PNG_COLOR_TYPE_PALETTE: bpp = bit_depth; break; case PNG_COLOR_TYPE_RGB: png_set_bgr(l-> png_ptr); bpp = 24; break; case PNG_COLOR_TYPE_GRAY_ALPHA: bpp = bit_depth | imGrayScale; break; case PNG_COLOR_TYPE_RGB_ALPHA: png_set_bgr(l-> png_ptr); bpp = 24; break; default: sprintf( fi-> errbuf, "Unknown file color type: %d", color_type); return false; } /* gamma stuff */ { double screen_gamma = default_screen_gamma, gamma = 0.45455; Bool has_gamma = false; if ( pexist( screen_gamma)) { screen_gamma = pget_f( screen_gamma); if ( screen_gamma < PNG_GAMMA_THRESHOLD || screen_gamma > PNG_MAX_GAMMA) { sprintf( fi-> errbuf, "Error: screen_gamma value must be within %g..%g", PNG_GAMMA_THRESHOLD, (double)PNG_MAX_GAMMA); return false; } } #ifdef PNG_gAMA_SUPPORTED if ( pexist( gamma)) { gamma = pget_f( gamma); if ( gamma < PNG_GAMMA_THRESHOLD || gamma > PNG_MAX_GAMMA) { sprintf( fi-> errbuf, "Error: gamma value must be within %g..%g", PNG_GAMMA_THRESHOLD, (double)PNG_MAX_GAMMA); return false; } has_gamma = true; } else if ( png_get_gAMA(l-> png_ptr, l-> info_ptr, &gamma)) { has_gamma = true; } #endif if ( has_gamma) png_set_gamma(l->png_ptr, screen_gamma, gamma); } /* alpha option */ if ( pexist( alpha)) { char * c = pget_c( alpha); if ( stricmp( c, "blend") == 0) alpha_opt = ALPHA_OPT_BLEND; else if ( stricmp( c, "split") == 0) { if ( icon) outc("Alpha channel cannot be loaded to an Icon object") else alpha_opt = ALPHA_OPT_SPLIT; } else if ( stricmp( c, "none") == 0) alpha_opt = ALPHA_OPT_NONE; else { snprintf( fi-> errbuf, 256, "unknown alpha option '%s'", c); return false; } } else
/* Object evaluation */ void gen_address(Node node) /*;gen_address*/ { /* * This procedure generates code for the o_expressions * or, in other words, the left-handsides. */ Node pre_node, array_node, range_node, lbd_node, ubd_node, record_node, field_node, id_node; Symbol node_name, type_name, record_name, record_type, field_name, comp_type, proc_name, return_type; int f_off, bse, off, nk; Fortup ft1; #ifdef TRACE if (debug_flag) gen_trace_node("GEN_ADDRESS", node); #endif while (N_KIND(node) == as_insert) { FORTUP(pre_node=(Node), N_LIST(node), ft1); compile(pre_node); ENDFORTUP(ft1); node = N_AST1(node); } node_name = N_UNQ(node); if (is_simple_name(node)) { type_name = get_type(node); if (is_renaming(node_name)) gen_ks(I_PUSH, mu_addr, node_name); else gen_s(I_PUSH_EFFECTIVE_ADDRESS, node_name); /* Arrays are treated in a different manner, depending on their */ /* nature: parameters, constants, variables... */ if (is_array_type(type_name)) { if (is_formal_parameter(node_name)) { type_name = assoc_symbol_get(node_name, FORMAL_TEMPLATE); } gen_s(I_PUSH_EFFECTIVE_ADDRESS, type_name); } } else { switch (nk = N_KIND(node)) { case as_raise: compile(node); break; case as_index: gen_subscript(node); break; case as_slice: array_node = N_AST1(node); range_node = N_AST2(node); /*range_name = N_UNQ(range_node); -- never used ds 7-8-85 */ /* Note: case of type simple name changed into range attribute */ /* by expander */ if (N_KIND(range_node) == as_attribute) { gen_attribute(range_node); } else { /* range */ lbd_node = N_AST1(range_node); ubd_node = N_AST2(range_node); gen_value(lbd_node); gen_value(ubd_node); } if (N_KIND(array_node) == as_attribute) { gen_attribute(array_node); } else { gen_address(array_node); } gen(I_ARRAY_SLICE); break; case as_selector: record_node = N_AST1(node); field_node = N_AST2(node); record_name = N_UNQ(record_node); record_type = get_type(record_node); field_name = N_UNQ(field_node); f_off = FIELD_OFFSET(field_name); if (f_off >= 0 && ((! has_discriminant(record_type)) || NATURE(field_name) == na_discriminant)){ if (is_simple_name(record_node) && !(is_renaming(record_name)) && is_global(record_name)) { reference_of(record_name); bse = REFERENCE_SEGMENT; off = REFERENCE_OFFSET; /* The SETL version has generate(I_PUSH_IMMEDIATE, mu_addr, * ref, field_name); * which we translate as (I_PUSH_EFFECTIVE_ADDRESS ... * ref = [bse, off+f_off]; * Replace use of explicit ref by PUSH_IMMEDIATE */ /* gen_rc(I_PUSH_IMMEDIATE, explicit_ref_new(bse, * off+f_off), ""); */ gen_kv(I_PUSH_IMMEDIATE, mu_word, int_const(bse)); gen_kv(I_PUSH_IMMEDIATE, mu_word, int_const(off+f_off)); } else { gen_address(record_node); if (f_off != 0 ) { gen_ki(I_ADD_IMMEDIATE, mu_word, f_off); } } if (is_array_type(comp_type=TYPE_OF(field_name))) { gen_s(I_PUSH_EFFECTIVE_ADDRESS, comp_type); } } else { gen_address(record_node); gen_s(I_PUSH_EFFECTIVE_ADDRESS, record_type); /* translating following assuming field_name is comment part of *-- instruction ds 7-5-86 * gen_i(I_SELECT, FIELD_NUMBER(field_name), field_name); */ gen_i(I_SELECT, (int) FIELD_NUMBER(field_name)); } break; case as_all: id_node = N_AST1(node); gen_value(id_node); if (is_array_type(N_TYPE(node))) gen_k(I_DEREF, mu_dble); break; case as_call: id_node = N_AST1(node); proc_name = N_UNQ(id_node); return_type = TYPE_OF(proc_name); gen_kc(I_DUPLICATE, kind_of(return_type), "place holder"); compile(node); /* processed from now as a procedure call */ break; case as_un_op: gen_unary(node); break; case as_op: gen_binary(node); break; case as_string_ivalue: gen_value(node); break; default: compiler_error_k("GEN_ADDRESS called with kind ", node); } } }
PImage IPA__Global_band_filter(PImage img,HV *profile) { #define METHOD "IPA::Global::band_filter" dPROFILE; PImage ret; int spatial = 1, homomorph = 0, lw, failed = 0, LowPass = 0; double MinVal = 0.0, Power = 2.0, CutOff = 20.0, Boost = 0.7; double * data, * buffer = nil; if ( sizeof(double) % 2) { warn("%s:'double' is even-sized on this platform", METHOD); return nil; } if ( !img || !kind_of(( Handle) img, CImage)) croak("%s: not an image passed", METHOD); if ( pexist( spatial)) spatial = pget_i( spatial); if ( pexist( homomorph)) homomorph = pget_i( homomorph); if ( pexist( power)) Power = pget_f( power); if ( pexist( cutoff)) CutOff = pget_f( cutoff); if ( pexist( boost)) Boost = pget_f( boost); if ( pexist( low)) LowPass = pget_i( low); if ( homomorph && !spatial) croak("%s:Cannot perform the homomorph equalization in the spatial domain", METHOD); if ( LowPass && ( CutOff < 0.0000001)) croak("%s:cutoff is too small for low pass", METHOD); if ( !spatial && (( img-> type & imCategory) != imComplexNumber)) croak("%s: not an im::DComplex image passed", METHOD); ret = ( PImage) img-> self-> dup(( Handle) img); if ( !ret) fail( "%s: Return image allocation failed"); ++SvREFCNT( SvRV( ret-> mate)); if ( spatial) { ret-> self-> set_type(( Handle) ret, imDComplex); if ( ret-> type != imDComplex) { warn("%s: Cannot convert image to im::DComplex", METHOD); failed = 1; goto EXIT; } } data = ( double *) ret-> data; lw = ret-> w * 2; /* Take log of input image */ if ( homomorph) { long i, k = ret-> w * ret-> h * 2; MinVal = *data; for ( i = 0; i < k; i += 2) if ( MinVal > data[i]) MinVal = data[i]; for ( i = 0; i < k; i += 2) data[i] = ( double) log(( double) ( 1.0 + data[i] - MinVal)); } /* fft */ if ( spatial) { if ( !pow2( img-> w)) croak("%s: image width is not a power of 2", METHOD); if ( !pow2( img-> h)) croak("%s: image height is not a power of 2", METHOD); buffer = malloc((sizeof(double) * ret-> w * 2)); if ( !buffer) { warn("%s: Error allocating %d bytes", METHOD, (int)(sizeof(double) * img-> w * 2)); failed = 1; goto EXIT; } fft_2d( data, ret-> w, ret-> h, FFT_DIRECT, buffer); } butterworth( data, ret-> w, ret-> h, homomorph, LowPass, Power, CutOff, Boost); /* inverse fft */ if ( spatial) { fft_2d( data, ret-> w, ret-> h, FFT_INVERSE, buffer); free( buffer); buffer = nil; } /* Take exp of input image */ if ( homomorph) { long i, k = ret-> w * ret-> h * 2; for ( i = 0; i < k; i += 2) data[i] = ( double) ( exp( data[i]) - 1.0 + MinVal); } /* converting type back */ if ( spatial && ret-> self-> get_preserveType(( Handle) ret)) ret-> self-> set_type(( Handle) ret, img-> type); EXIT: free( buffer); if ( ret) --SvREFCNT( SvRV( ret-> mate)); return failed ? nil : ret; #undef METHOD }