FUNCTION qImage_cw_BoxImage, state, box, image=image, $ screen=screen, sub_img=sub_img, sub_box=sub_box ;+ ; NAME: ; qImage_cw_BoxImage ; PURPOSE: ; Extracts an area from the current image ; CATEGORY: ; Compound widget qImage_cw ; CALLING SEQUENCE: ; status = qImage_cw_BoxImage(state, box, sub_img=sub_img, sub_box=sub_box) ; status = qImage_cw_BoxImage(state, box, image=image, sub_img=sub_img) ; INPUTS: ; state array[1]; type: structure ; qImage_cw state structure ; box array[2,2]; type: integer ; area to be extracted from the original image ; if not specified then box = [[0,0], [n-1,m-1]] (the full ; image or screen) is assumed. ; ; /screen NOT set: ; The box is specified as pixel indices into the original ; image, but can extend outside the image, or even lie ; completely outside the image. ; OPTIONAL INPUT PARAMETERS: ; /screen if set the extraction is done for the byte-scaled image on the display ; rather than the raw image ; image=image array[n,m]; type: float ; array to be used as current image, instead of the user value ; of state.wid_image ; (this keyword is used only in href=qImage_cw_Set_Value=) ; OUTPUTS: ; status scalar; type: byte ; 0: if 'box' does not include any pixels inside the image ; 1: if a valid 'sub_img' was extracted ; OPTIONAL OUTPUT PARAMETERS: ; sub_img=sub_img ; array[*,*]; type: same as current image ; subarray containing requested area ; sub_box=sub_box ; array[2,2]; box with indices into 'image' of elements ; returned in sub_img ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; InitVar, IsType, qImage_cw_BoxCosine ; PROCEDURE: ; The pedestal from the value of the state.background widget is subtracted ; STATE INFO USED: ; widget_control, state.wid_background, get_value=pedestal1 ; widget_control, state.wid_image, get_uvalue=image, /no_copy ; STATE INFO MODIFIED: ; widget_control, state.wid_image, set_uvalue=image, /no_copy ; MODIFICATION HISTORY: ; MAR-2000, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ;- InitVar, screen, /key screen_size = qImage_cw_Property(state, /screen_size) ; Window size IF screen_size[0] EQ -1 THEN $ ; Probably no image on screen yet RETURN, 0 CASE screen OF 0: BEGIN from_state = IsType(image, /undefined) IF from_state THEN widget_control, state.wid_image, get_uvalue=image, /no_copy status = IsType(image, /defined) IF status THEN BEGIN image_size = size(image, /dim) ;slider_origin = qImage_cw_Property(state, /slider_origin) IF IsType(box, /undefined) THEN message, 'no box ??????????????' ;InitVar, box, [slider_origin, [slider_origin+screen_size-1]] ; ??? ;InitVar, box, [[0,0], [image_size-1]] ; Find 'truncated box' = part of box that lies inside image area. ; If tbox = box then the whole area lies inside the image. tbox = [ [box[0:1] > 0], [box[2:3] < (image_size-1)] ] ; If the whole input box lies outside the image than tbox at this point ; is an invalid box with tbox[2] < tbox[0] or tbox[3] < tbox[1]. status = tbox[2] GE tbox[0] AND tbox[3] GE tbox[1] IF status THEN BEGIN sub_box = tbox sub_img = image[tbox[0]:tbox[2],tbox[1]:tbox[3]] widget_control, state.wid_background, get_value=pedestal1, get_uvalue=pedestal2 IF pedestal1 NE 0 THEN sub_img = sub_img-pedestal1 sub_img = qImage_cw_BoxCosine(state, sub_img, sub_box) IF pedestal2 NE 0 THEN sub_img = sub_img-pedestal2 ENDIF IF from_state THEN widget_control, state.wid_image, set_uvalue=image, /no_copy ENDIF END 1: BEGIN InitVar, box, [[0,0], [screen_size-1]] tbox = [ [box[0:1] > 0], [box[2:3] < (screen_size-1)] ] status = tbox[0] LE tbox[2] AND tbox[1] LE tbox[3] CASE status OF 0: message, /info, 'illegal box size, ('+strjoin(strjoin(strcompress(tbox,/rem),','),'),(')+')' 1: BEGIN IF IsType(image, /undefined) THEN BEGIN wold = !d.window widget_control, state.wid_draw, get_value=wnew IF wold NE wnew THEN wset, wnew image = tvrd() IF wold NE wnew THEN wset, wold ENDIF status = IsType(image, /defined) IF status THEN BEGIN sub_box = tbox sub_img = image[tbox[0]:tbox[2],tbox[1]:tbox[3]] ENDIF END ENDCASE END ENDCASE RETURN, status & END