PB_DS_CLASS_T_DEC
void
PB_DS_CLASS_C_DEC::
resize(size_type new_size)
{
  PB_DS_STATIC_ASSERT(access, external_size_access);
  size_type actual_size = size_policy_base::get_nearest_larger_size(1);
  while (actual_size < new_size)
    {
      const size_type pot = size_policy_base::get_nearest_larger_size(actual_size);

      if (pot == actual_size && pot < new_size)
	__throw_resize_error();
      actual_size = pot;
    }

  if (actual_size > 0)
    --actual_size;

  const size_type old_size = m_size;
  __try
    {
      do_resize(actual_size - 1);
    }
  __catch(insert_error& )
    {
      m_size = old_size;
      __throw_resize_error();
    }
Exemplo n.º 2
0
static gboolean sync_timeout_func(gpointer data)
{
    ++waiting_for_sync; /* we timed out waiting for our sync... */
    do_resize(); /* ...so let any pending resizes through */

    if (waiting_for_sync > SYNC_TIMEOUTS)
        return FALSE; /* don't repeat */
    else
        return TRUE; /* keep waiting */
}
Exemplo n.º 3
0
PB_ASSOC_CLASS_T_DEC
inline bool
PB_ASSOC_CLASS_C_DEC::
do_resize_if_needed()
{
  if (!my_resize_base::is_resize_needed())
    return (false);

  do
    do_resize(my_resize_base::get_new_size(m_num_e_p, m_num_used_e));
  while (my_resize_base::is_resize_needed());

  return (true);
}
Exemplo n.º 4
0
PB_ASSOC_CLASS_T_DEC
inline void
PB_ASSOC_CLASS_C_DEC::
do_resize_if_needed_no_throw()
{
  if (!my_resize_base::is_resize_needed())
    return;

  try
    {
      do
	do_resize(my_resize_base::get_new_size(m_num_e_p, m_num_used_e));
      while (my_resize_base::is_resize_needed());
    }
  catch(...)
    { }

  PB_ASSOC_DBG_ONLY(assert_valid();)
    }
Exemplo n.º 5
0
INT_PTR CALLBACK BtrfsDeviceResize::DeviceResizeDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
    try {
        switch (uMsg) {
            case WM_INITDIALOG:
            {
                win_handle h;
                WCHAR s[255];
                wstring t, u;

                EnableThemeDialogTexture(hwndDlg, ETDT_ENABLETAB);

                GetDlgItemTextW(hwndDlg, IDC_RESIZE_DEVICE_ID, s, sizeof(s) / sizeof(WCHAR));
                wstring_sprintf(t, s, dev_id);
                SetDlgItemTextW(hwndDlg, IDC_RESIZE_DEVICE_ID, t.c_str());

                h = CreateFileW(fn.c_str(), FILE_TRAVERSE | FILE_READ_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr,
                                OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, nullptr);

                if (h != INVALID_HANDLE_VALUE) {
                    NTSTATUS Status;
                    IO_STATUS_BLOCK iosb;
                    btrfs_device *devices, *bd;
                    ULONG devsize;
                    bool found = false;
                    HWND slider;

                    devsize = 1024;
                    devices = (btrfs_device*)malloc(devsize);

                    while (true) {
                        Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_GET_DEVICES, nullptr, 0, devices, devsize);
                        if (Status == STATUS_BUFFER_OVERFLOW) {
                            devsize += 1024;

                            free(devices);
                            devices = (btrfs_device*)malloc(devsize);
                        } else
                            break;
                    }

                    if (!NT_SUCCESS(Status)) {
                        free(devices);
                        return false;
                    }

                    bd = devices;

                    while (true) {
                        if (bd->dev_id == dev_id) {
                            memcpy(&dev_info, bd, sizeof(btrfs_device));
                            found = true;
                            break;
                        }

                        if (bd->next_entry > 0)
                            bd = (btrfs_device*)((uint8_t*)bd + bd->next_entry);
                        else
                            break;
                    }

                    if (!found) {
                        free(devices);
                        return false;
                    }

                    free(devices);

                    GetDlgItemTextW(hwndDlg, IDC_RESIZE_CURSIZE, s, sizeof(s) / sizeof(WCHAR));
                    format_size(dev_info.size, u, true);
                    wstring_sprintf(t, s, u.c_str());
                    SetDlgItemTextW(hwndDlg, IDC_RESIZE_CURSIZE, t.c_str());

                    new_size = dev_info.size;

                    GetDlgItemTextW(hwndDlg, IDC_RESIZE_NEWSIZE, new_size_text, sizeof(new_size_text) / sizeof(WCHAR));
                    wstring_sprintf(t, new_size_text, u.c_str());
                    SetDlgItemTextW(hwndDlg, IDC_RESIZE_NEWSIZE, t.c_str());

                    slider = GetDlgItem(hwndDlg, IDC_RESIZE_SLIDER);
                    SendMessageW(slider, TBM_SETRANGEMIN, false, 0);
                    SendMessageW(slider, TBM_SETRANGEMAX, false, (LPARAM)(dev_info.max_size / 1048576));
                    SendMessageW(slider, TBM_SETPOS, true, (LPARAM)(new_size / 1048576));
                } else
                    return false;

                break;
            }

            case WM_COMMAND:
                switch (HIWORD(wParam)) {
                    case BN_CLICKED:
                        switch (LOWORD(wParam)) {
                            case IDOK:
                                do_resize(hwndDlg);
                                return true;

                            case IDCANCEL:
                                EndDialog(hwndDlg, 0);
                                return true;
                        }
                    break;
                }
            break;

            case WM_HSCROLL:
            {
                wstring t, u;

                new_size = UInt32x32To64(SendMessageW(GetDlgItem(hwndDlg, IDC_RESIZE_SLIDER), TBM_GETPOS, 0, 0), 1048576);

                format_size(new_size, u, true);
                wstring_sprintf(t, new_size_text, u.c_str());
                SetDlgItemTextW(hwndDlg, IDC_RESIZE_NEWSIZE, t.c_str());

                EnableWindow(GetDlgItem(hwndDlg, IDOK), new_size > 0 ? true : false);

                break;
            }
        }
    } catch (const exception& e) {
        error_message(hwndDlg, e.what());
    }

    return false;
}
Exemplo n.º 6
0
gboolean moveresize_event(XEvent *e)
{
    gboolean used = FALSE;

    if (!moveresize_in_progress) return FALSE;

    if (e->type == ButtonPress) {
        if (!button) {
            start_x = e->xbutton.x_root;
            start_y = e->xbutton.y_root;
            button = e->xbutton.button; /* this will end it now */
        }
        used = e->xbutton.button == button;
    } else if (e->type == ButtonRelease) {
        if (!button || e->xbutton.button == button) {
            moveresize_end(FALSE);
            used = TRUE;
        }
    } else if (e->type == MotionNotify) {
        if (moving) {
            cur_x = start_cx + e->xmotion.x_root - start_x;
            cur_y = start_cy + e->xmotion.y_root - start_y;
            do_move(FALSE, 0);
            do_edge_warp(e->xmotion.x_root, e->xmotion.y_root);
        } else {
            gint dw, dh;
            ObDirection dir;

            if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPLEFT)) {
                dw = -(e->xmotion.x_root - start_x);
                dh = -(e->xmotion.y_root - start_y);
                dir = OB_DIRECTION_NORTHWEST;
            } else if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOP)) {
                dw = 0;
                dh = -(e->xmotion.y_root - start_y);
                dir = OB_DIRECTION_NORTH;
            } else if (corner ==
                       OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPRIGHT)) {
                dw = (e->xmotion.x_root - start_x);
                dh = -(e->xmotion.y_root - start_y);
                dir = OB_DIRECTION_NORTHEAST;
            } else if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_RIGHT)) {
                dw = (e->xmotion.x_root - start_x);
                dh = 0;
                dir = OB_DIRECTION_EAST;
            } else if (corner ==
                       OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT)) {
                dw = (e->xmotion.x_root - start_x);
                dh = (e->xmotion.y_root - start_y);
                dir = OB_DIRECTION_SOUTHEAST;
            } else if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOM))
            {
                dw = 0;
                dh = (e->xmotion.y_root - start_y);
                dir = OB_DIRECTION_SOUTH;
            } else if (corner ==
                       OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT)) {
                dw = -(e->xmotion.x_root - start_x);
                dh = (e->xmotion.y_root - start_y);
                dir = OB_DIRECTION_SOUTHWEST;
            } else if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_LEFT)) {
                dw = -(e->xmotion.x_root - start_x);
                dh = 0;
                dir = OB_DIRECTION_WEST;
            } else if (corner ==
                       OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_KEYBOARD)) {
                dw = (e->xmotion.x_root - start_x);
                dh = (e->xmotion.y_root - start_y);
                dir = OB_DIRECTION_SOUTHEAST;
            } else
                g_assert_not_reached();

            /* override the client's max state if desired */
            if (ABS(dw) >= config_resist_edge) {
                if (moveresize_client->max_horz) {
                    /* unmax horz */
                    was_max_horz = TRUE;
                    pre_max_area.x = moveresize_client->pre_max_area.x;
                    pre_max_area.width = moveresize_client->pre_max_area.width;

                    moveresize_client->pre_max_area.x = cur_x;
                    moveresize_client->pre_max_area.width = cur_w;
                    client_maximize(moveresize_client, FALSE, 1);
                }
            }
            else if (was_max_horz && !moveresize_client->max_horz) {
                /* remax horz and put the premax back */
                client_maximize(moveresize_client, TRUE, 1);
                moveresize_client->pre_max_area.x = pre_max_area.x;
                moveresize_client->pre_max_area.width = pre_max_area.width;
            }

            if (ABS(dh) >= config_resist_edge) {
                if (moveresize_client->max_vert) {
                    /* unmax vert */
                    was_max_vert = TRUE;
                    pre_max_area.y = moveresize_client->pre_max_area.y;
                    pre_max_area.height =
                        moveresize_client->pre_max_area.height;

                    moveresize_client->pre_max_area.y = cur_y;
                    moveresize_client->pre_max_area.height = cur_h;
                    client_maximize(moveresize_client, FALSE, 2);
                }
            }
            else if (was_max_vert && !moveresize_client->max_vert) {
                /* remax vert and put the premax back */
                client_maximize(moveresize_client, TRUE, 2);
                moveresize_client->pre_max_area.y = pre_max_area.y;
                moveresize_client->pre_max_area.height = pre_max_area.height;
            }

            dw -= cur_w - start_cw;
            dh -= cur_h - start_ch;

            calc_resize(FALSE, 0, &dw, &dh, dir);
            cur_w += dw;
            cur_h += dh;

            if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPLEFT) ||
                corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_LEFT) ||
                corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT))
            {
                cur_x -= dw;
            }
            if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPLEFT) ||
                corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOP) ||
                corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPRIGHT))
            {
                cur_y -= dh;
            }

            do_resize();
        }
        used = TRUE;
    } else if (e->type == KeyPress) {
        KeySym sym = obt_keyboard_keypress_to_keysym(e);

        if (sym == XK_Escape) {
            moveresize_end(TRUE);
            used = TRUE;
        } else if (sym == XK_Return || sym == XK_KP_Enter) {
            moveresize_end(FALSE);
            used = TRUE;
        } else if (sym == XK_Right || sym == XK_Left ||
                   sym == XK_Up || sym == XK_Down)
        {
            if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_KEYBOARD)) {
                resize_with_keys(sym, e->xkey.state);
                used = TRUE;
            } else if (corner ==
                       OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE_KEYBOARD))
            {
                move_with_keys(sym, e->xkey.state);
                used = TRUE;
            }
        }
    }
#ifdef SYNC
    else if (e->type == obt_display_extension_sync_basep + XSyncAlarmNotify)
    {
        waiting_for_sync = 0; /* we got our sync... */
        do_resize(); /* ...so try resize if there is more change pending */
        used = TRUE;
    }
#endif

    if (used && moveresize_client == focus_client)
        event_update_user_time();

    return used;
}
Exemplo n.º 7
0
static void resize_with_keys(KeySym sym, guint state)
{
    gint dw = 0, dh = 0, pdx = 0, pdy = 0, opx, opy, px, py;
    gint resist = 0;
    ObDirection dir;

    /* pick the edge if it needs to move */
    if (sym == XK_Right) {
        dir = OB_DIRECTION_EAST;
        if (key_resize_edge != OB_DIRECTION_WEST &&
            key_resize_edge != OB_DIRECTION_EAST)
        {
            key_resize_edge = OB_DIRECTION_EAST;
            return;
        }
    } else if (sym == XK_Left) {
        dir = OB_DIRECTION_WEST;
        if (key_resize_edge != OB_DIRECTION_WEST &&
            key_resize_edge != OB_DIRECTION_EAST)
        {
            key_resize_edge = OB_DIRECTION_WEST;
            return;
        }
    } else if (sym == XK_Up) {
        dir = OB_DIRECTION_NORTH;
        if (key_resize_edge != OB_DIRECTION_NORTH &&
            key_resize_edge != OB_DIRECTION_SOUTH)
        {
            key_resize_edge = OB_DIRECTION_NORTH;
            return;
        }
    } else /* if (sym == XK_Down) */ {
        dir = OB_DIRECTION_SOUTH;
        if (key_resize_edge != OB_DIRECTION_NORTH &&
            key_resize_edge != OB_DIRECTION_SOUTH)
        {
            key_resize_edge = OB_DIRECTION_SOUTH;
            return;
        }
    }

    /* shift means jump to edge */
    if (state & obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_SHIFT))
    {
        gint x, y, w, h;

        if (sym == XK_Right)
            dir = OB_DIRECTION_EAST;
        else if (sym == XK_Left)
            dir = OB_DIRECTION_WEST;
        else if (sym == XK_Down)
            dir = OB_DIRECTION_SOUTH;
        else /* if (sym == XK_Up)) */
            dir = OB_DIRECTION_NORTH;

        client_find_resize_directional(moveresize_client, key_resize_edge,
                                       key_resize_edge == dir,
                                       &x, &y, &w, &h);
        dw = w - moveresize_client->area.width;
        dh = h - moveresize_client->area.height;
    } else {
        gint distw, disth;

        /* control means fine grained */
        if (moveresize_client->size_inc.width > 1) {
            distw = moveresize_client->size_inc.width;
            resist = 1;
        }
        else if (state &
                 obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_CONTROL))
        {
            distw = 1;
            resist = 1;
        }
        else {
            distw = KEY_DIST;
            resist = KEY_DIST;
        }
        if (moveresize_client->size_inc.height > 1) {
            disth = moveresize_client->size_inc.height;
            resist = 1;
        }
        else if (state &
                 obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_CONTROL))
        {
            disth = 1;
            resist = 1;
        }
        else {
            disth = KEY_DIST;
            resist = KEY_DIST;
        }

        if (key_resize_edge == OB_DIRECTION_WEST) {
            if (dir == OB_DIRECTION_WEST)
                dw = distw;
            else
                dw = -distw;
        }
        else if (key_resize_edge == OB_DIRECTION_EAST) {
            if (dir == OB_DIRECTION_EAST)
                dw = distw;
            else
                dw = -distw;
        }
        else if (key_resize_edge == OB_DIRECTION_NORTH) {
            if (dir == OB_DIRECTION_NORTH)
                dh = disth;
            else
                dh = -disth;
        }
        else /*if (key_resize_edge == OB_DIRECTION_SOUTH)*/ {
            if (dir == OB_DIRECTION_SOUTH)
                dh = disth;
            else
                dh = -disth;
        }
    }

    if (moveresize_client->max_horz &&
        (key_resize_edge == OB_DIRECTION_WEST ||
         key_resize_edge == OB_DIRECTION_EAST))
    {
        /* unmax horz */
        was_max_horz = TRUE;
        pre_max_area.x = moveresize_client->pre_max_area.x;
        pre_max_area.width = moveresize_client->pre_max_area.width;

        moveresize_client->pre_max_area.x = cur_x;
        moveresize_client->pre_max_area.width = cur_w;
        client_maximize(moveresize_client, FALSE, 1);
    }
    else if (moveresize_client->max_vert &&
             (key_resize_edge == OB_DIRECTION_NORTH ||
              key_resize_edge == OB_DIRECTION_SOUTH))
    {
        /* unmax vert */
        was_max_vert = TRUE;
        pre_max_area.y = moveresize_client->pre_max_area.y;
        pre_max_area.height = moveresize_client->pre_max_area.height;

        moveresize_client->pre_max_area.y = cur_y;
        moveresize_client->pre_max_area.height = cur_h;
        client_maximize(moveresize_client, FALSE, 2);
    }

    calc_resize(TRUE, resist, &dw, &dh, dir);
    if (key_resize_edge == OB_DIRECTION_WEST)
        cur_x -= dw;
    else if (key_resize_edge == OB_DIRECTION_NORTH)
        cur_y -= dh;
    cur_w += dw;
    cur_h += dh;

    /* how to move the pointer to keep up with the change */
    if (key_resize_edge == OB_DIRECTION_WEST)
        pdx = -dw;
    else if (key_resize_edge == OB_DIRECTION_EAST)
        pdx = dw;
    else if (key_resize_edge == OB_DIRECTION_NORTH)
        pdy = -dh;
    else if (key_resize_edge == OB_DIRECTION_SOUTH)
        pdy = dh;

    screen_pointer_pos(&opx, &opy);
    XWarpPointer(obt_display, None, None, 0, 0, 0, 0, pdx, pdy);
    /* steal the motion events this causes */
    XSync(obt_display, FALSE);
    {
        XEvent ce;
        while (xqueue_remove_local(&ce, xqueue_match_type,
                                   GINT_TO_POINTER(MotionNotify)));
    }
    screen_pointer_pos(&px, &py);

    do_resize();

    /* because the cursor moves even though the window does
       not nessesarily (resistance), this adjusts where the cursor
       thinks it started so that it keeps up with where the window
       actually is */
    start_x += (px - opx) - dw;
    start_y += (py - opy) - dh;

}
Exemplo n.º 8
0
int
main( int argc, char **argv ) {	
	irz_config_t *config;
	char *temp_out = tmpnam(NULL);

	FILE *in_fh = NULL;
	FILE *out_fh = NULL;
	
	config = parse_options(argc, argv);
	if( config == NULL ) {
		return EXIT_FAILURE+9;
	}
	
	config->logger = irz_logger_stdio;
	config->logger_cfg = stdout;
	
	in_fh = fopen(config->in_file,"r");
	if( ! in_fh ) {
		char buf[200];
		strerror_r(errno, buf, sizeof(buf));
		irz_log(config, IRZ_ERROR, "Cannot open in-file '%s': %s", config->in_file, buf);
		return EXIT_FAILURE+11;
	}
	
	struct jpeg_compress_struct out_cinfo;
	struct jpeg_decompress_struct in_dinfo;
	struct jpeg_error_mgr       jerr;		
	
	setup_in(&in_dinfo, &jerr, in_fh);

	if( config->debug ) {
		irz_log(config, IRZ_DEBUG, "Image Width: %ipx\n", (int)in_dinfo.image_width);
	        irz_log(config, IRZ_DEBUG, "Image Height: %ipx\n", (int)in_dinfo.image_height);
	        irz_log(config, IRZ_DEBUG, "Tmp Loc: %s\n", temp_out);
	}

	if ( config->out_width != 0 ) {
        	if ( (int)in_dinfo.image_width < (int)config->out_width ) {
            		irz_log(config, IRZ_WARN, "specified width is larger than original image, reducing to %ipx.\n", (int)in_dinfo.image_width);
            		config->out_width = (double)in_dinfo.image_width;
        	}
    	}

    	if ( config->out_height != 0 ) {
        	if ( (int)in_dinfo.image_height < (int)config->out_height ) {
            		irz_log(config, IRZ_WARN, "specified height is larger than original image, reducing to %ipx.\n", (int)in_dinfo.image_height);
            		config->out_height = (double)in_dinfo.image_height;
        	}
    	}
	
	/* Auto-scale width or height if either was not specified */
	if( config->mode == MODE_SCALE ) {		
		if( config->out_height == 0 ) {
			double ratio = (double)config->out_width / (double)in_dinfo.image_width;
			config->out_height = ((double)in_dinfo.image_height * ratio);
		}
		else if( config->out_width == 0 ) {
			double ratio = (double)config->out_height / (double)in_dinfo.image_height;
			config->out_width = ((double)in_dinfo.image_width * ratio);
		}
	}
    	else if( config->mode == MODE_SCALEASPECT ) {
        	double ratio;
        	unsigned int new_width = in_dinfo.image_width;
        	unsigned int new_height = in_dinfo.image_height;

        	if (in_dinfo.image_width > in_dinfo.image_height) {
            		ratio = ( (double)in_dinfo.image_width / (double)in_dinfo.image_height ) ;
        	}
		else {
            		ratio = ( (double)in_dinfo.image_height / (double)in_dinfo.image_width ) ;
        	}

		if( config->debug ) {
        		irz_log(config, IRZ_DEBUG, "Ratio: %f\n", ratio);
		}

        	if (in_dinfo.image_width < in_dinfo.image_height) {
            		if (new_width > config->out_width) {
                		new_width = config->out_width;
                		new_height = ( new_height - ( ( (double)in_dinfo.image_width - (double)config->out_width) * ratio ) );

				if( config->debug ) {
             	   			irz_log(config, IRZ_DEBUG, "aspect changed: width: %u / height: %u\n", new_width, new_height );
				}
            		}

            		if (new_height > config->out_height) {
                		new_width = ( new_width - ( ( (double)new_height - (double)config->out_height) / ratio ) );
                		new_height = config->out_height;

				if( config->debug ) {
             	   			irz_log(config, IRZ_DEBUG, "aspect changed: width: %u / height: %u\n", new_width, new_height );
				}
            		}
        	}
		else {
            		if (new_width > config->out_width) {
                		new_width = config->out_width;
                		new_height = ( new_height - ( ( (double)in_dinfo.image_width - (double)config->out_width) / ratio ) );

				if( config->debug ) {
             	   			irz_log(config, IRZ_DEBUG, "aspect changed: width: %u / height: %u\n", new_width, new_height );
				}
            		}

            		if (new_height > config->out_height) {
                		new_width = ( new_width - ( ( (double)new_height - (double)config->out_height) * ratio ) );
                		new_height = config->out_height;

				if( config->debug ) {
              	  			irz_log(config, IRZ_DEBUG, "aspect changed: width: %u / height: %u\n", new_width, new_height );
				}
            		}
        	}

        	config->out_width = new_width;
        	config->out_height = new_height;
	}
	else if( config->mode == MODE_SCALEFIT ) {
		if( in_dinfo.image_width > config->out_width ) {
			double ratio = (double)config->out_width / (double)in_dinfo.image_width;
			config->out_height = ((double)in_dinfo.image_height * ratio);
			config->out_width = ((double)in_dinfo.image_width * ratio);
		}
		if( in_dinfo.image_height > config->out_height ) {
			double ratio = (double)config->out_height / (double)in_dinfo.image_height;
			config->out_height = ((double)in_dinfo.image_height * ratio);
			config->out_width = ((double)in_dinfo.image_width * ratio);
		}
	}
	else if( config->mode == MODE_CROPMANUAL ) {
		if( (config->crop_x2 - config->crop_x) < 10 ) {
			irz_log(config, IRZ_ERROR, "source crop width too small\n");
			return EXIT_FAILURE+10;
		}
		else if( (config->crop_y2 - config->crop_y) < 10 ) {
			irz_log(config, IRZ_ERROR, "source crop height too small\n");
			return EXIT_FAILURE+10;
		}
		else if( config->crop_x2 > in_dinfo.image_width || config->crop_y2 > in_dinfo.image_height ) {
			irz_log(config, IRZ_ERROR, "source crop area outside of image dimension\n");
			return EXIT_FAILURE+10;
		}
	}

	if( config->debug ) {
        	irz_log(config, IRZ_DEBUG, "Out Width: %upx\n", config->out_width);
        	irz_log(config, IRZ_DEBUG, "Out Height: %upx\n", config->out_height);
	}
	
	out_fh = fopen(temp_out,"wb");
	if( ! out_fh ) {
		char buf[200];
		strerror_r(errno, buf, sizeof(buf));
		irz_log(config, IRZ_ERROR, "Cannot open output file '%s': %s", temp_out, buf);
		return EXIT_FAILURE+12;
	}

	setup_out(&out_cinfo, &jerr, out_fh, config->out_width, config->out_height, config->out_quality);

	int row_stride = in_dinfo.output_width * in_dinfo.output_components;
	JSAMPARRAY buffer;
	buffer = (in_dinfo.mem->alloc_sarray)((j_common_ptr) &in_dinfo, JPOOL_IMAGE, row_stride, 1);
		
	do_resize(&out_cinfo, &in_dinfo, config);

	jpeg_finish_decompress(&in_dinfo);
	jpeg_destroy_decompress(&in_dinfo);
	
	jpeg_finish_compress(&out_cinfo);
	jpeg_destroy_compress(&out_cinfo);
	
	fclose(in_fh);
	fclose(out_fh);
	
	/* XXX: needs to be refactored as rename() won't work across filesystems
	 * temp_out should be in the same directory as out_file */
	if( rename( temp_out, config->out_file ) != 0 ) {
		char buf[200];
		strerror_r(errno, buf, sizeof(buf));
		irz_log(config, IRZ_ERROR, "Cannot rename temporary file '%s' to real file '%s': %s", temp_out, config->out_file, buf);
		return EXIT_FAILURE+13;
	}
	
	free(config);	
	return EXIT_SUCCESS;
}
Exemplo n.º 9
0
int main(int argc, char* argv[]){
 
  char* action;
  Window window;
  int arg[5]={0};

  // Connexion à un serveur X
  display = XOpenDisplay(NULL);
  if(!display){
    printf("Can not open display.\n");
    exit(EXIT_FAILURE);
  }

  // Récupère la valeur par default des différentes variables.
  screen = DefaultScreen(display);
  gc = DefaultGC (display, screen);
  root = RootWindow (display, screen);
  // Détermine l'action à effectuer :
  // On vérifie que le 2er argument (autre que nom fichier) est un id de fenetre :

  if(argc>2 && ((!strncmp(argv[2],"0x",2) && strtoll(argv[2],NULL,16)) || strtoll(argv[2],NULL,10)) ){  

      action = argv[1];
      window = get_window(argv); 
      
      // Si 5 arguments, c'est soit un move, soit un resize:
      if (argc==3){ // 1 seul argument (ex: 0x32422 )
	if(!strcmp(action,"mapRaise"))
	  do_map_and_raise(window);
	else if(!strcmp(action,"map"))
	  do_map(window);
	else if(!strcmp(action,"raise"))
	  do_raise(window);
	else if(!strcmp(action,"destroy"))
	  do_destroy(window);
	else if(!strcmp(action,"focus"))
	  do_focus(window);
	else if(!strcmp(action,"minimize"))
	  do_minimize(window);
	else if(!strcmp(action,"set_desktop"))
	  set_desktop((int)strtoll(argv[2],NULL,10));
	else
	  fail();
      }
      else if(argc==4){ // 2 arguments (ex : 0x4242535 1 )
	if(!strcmp(action,"set_desktop_for_window")){
	  set_desktop(strtoll(argv[3],NULL,10));
	  set_desktop_for_window(window,strtoll(argv[3],NULL,10));
	}
	else if(!strcmp(action,"set_viewport"))
	  set_viewport((int)strtoll(argv[2],NULL,10),(int)strtoll(argv[3],NULL,10));
	else
	  fail();
      }
      else if(argc==5){ 

	arg[0]=(int)strtoll(argv[3],NULL,10);
	arg[1]=(int)strtoll(argv[4],NULL,10);
	if(!strcmp(action,"move"))
	  do_move(window, arg[0], arg[1]); 
	else if(!strcmp(action,"resize"))
	  do_resize(window,arg[0],arg[1]); 
	else
	  fail();
      }
      else if(argc==7){

	arg[0]=(int)strtoll(argv[3],NULL,10);
	arg[1]=(int)strtoll(argv[4],NULL,10);
	arg[2]=(int)strtoll(argv[5],NULL,10);
	arg[3]=(int)strtoll(argv[6],NULL,10);

	if(!strcmp(action,"moveResize"))
	  do_move_and_resize(window, arg[0], arg[1], arg[2], arg[3]); 
	else
	  fail();
      }
      else
	fail();
  }
  else
    fail();
  
  
  XCloseDisplay(display);
  return EXIT_SUCCESS;
  
}
Exemplo n.º 10
0
LRESULT CALLBACK
dialog_callback (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int wmId, wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;
    Frame* curr;
    switch (message) {
    case WM_COMMAND:
	wmId    = LOWORD(wParam);
	wmEvent = HIWORD(wParam);
	// Parse the menu selections:
	switch (wmId)
	{
	case IDM_ABOUT:
	    DialogBox (globals.hinst, (LPCTSTR) IDD_ABOUTBOX, hwnd, (DLGPROC) about_callback);
	    break;
	case IDM_FILE_OPEN:
	    break;
	case IDM_EXIT:
	    DestroyWindow (hwnd);
	    break;
	case IDM_SOURCE_MATROX:
	    ise_grab_set_source (&globals.ig, ISE_IMAGE_SOURCE_MATROX_HIRES_FLUORO);
	    highlight_source_menu (hwnd);
	    break;
	case IDM_SOURCE_BITFLOW:
	    ise_grab_set_source (&globals.ig, ISE_IMAGE_SOURCE_BITFLOW_LORES_FLUORO); //default is low
	    highlight_source_menu (hwnd);
	    break;
	case IDM_SOURCE_SYNTHETIC:
	    ise_grab_set_source (&globals.ig, ISE_IMAGE_SOURCE_SIMULATED_HIRES_FLUORO);
	    highlight_source_menu (hwnd);
	    break;
	case IDM_SOURCE_INTERNAL:
	    ise_grab_set_source (&globals.ig, ISE_IMAGE_SOURCE_INTERNAL_FLUORO);
	    highlight_source_menu (hwnd);
	    break;
	case IDM_SOURCE_FILE:
	    ise_grab_set_source (&globals.ig, ISE_IMAGE_SOURCE_FILE_HIRES_FLUORO); //default is high;
            fileload_open (&globals.ig.fileload);             
            highlight_source_menu (hwnd);
            globals.loadfrom_file = !globals.loadfrom_file;
                        //blt_frame_gl (0, curr, curr->img, ISE_IMAGE_SOURCE_FILE_HIRES_FLUORO);
	    break;
	case IDM_SOURCE_SETTINGS:
	    DialogBox (globals.hinst, (LPCTSTR) IDD_SOURCE_DIALOG, hwnd, (DLGPROC) source_settings_callback);
	    break;
	case IDM_OPTIONS_DROP_DARK:
	    handle_ddf ();
	    highlight_dialog_buttons ();
	    break;
	case IDM_OPTIONS_WRITE_DARK:
	    handle_wdf ();
	    highlight_dialog_buttons ();
	    break;
	case IDM_OPTIONS_HOLD_BRIGHT:
	    handle_hbf ();
	    highlight_dialog_buttons ();
	    break;

	case IDC_BUTTON_PAUSE:
	case IDC_BUTTON_STOP:
	    switch (wmEvent) {
	    case BN_CLICKED:
		handle_button_stop ();
		highlight_dialog_buttons ();
		return 1;
	    default:
		return DefWindowProc(hwnd, message, wParam, lParam);
	    }
	case IDC_BUTTON_GRAB:
	    switch (wmEvent) {
	    case BN_CLICKED:
		handle_button_grab ();
		highlight_dialog_buttons ();
		return 1;
	    default:
		return DefWindowProc(hwnd, message, wParam, lParam);
	    }
	case IDC_BUTTON_REC:
	    switch (wmEvent) {
	    case BN_CLICKED:
		handle_button_rec ();
		highlight_dialog_buttons ();
		return 1;
	    default:
		return DefWindowProc(hwnd, message, wParam, lParam);
	    }
	case IDC_BUTTON_RESET:
	    switch (wmEvent) {
	    case BN_CLICKED:
		handle_button_reset ();
		globals.notify[hwnd_to_idx (hwnd)] = 1;
		highlight_dialog_buttons ();
		return 1;
	    default:
		return DefWindowProc(hwnd, message, wParam, lParam);
	    }
	case IDC_BUTTON_AWL:
	    switch (wmEvent) {
	    case BN_CLICKED:
		handle_button_awl ();
		highlight_dialog_buttons ();
		return 1;
	    default:
		return DefWindowProc(hwnd, message, wParam, lParam);
	    }
	case IDC_BUTTON_GATE:
	    switch (wmEvent) {
	    case BN_CLICKED:
		handle_button_gate ();
		highlight_dialog_buttons ();
		return 1;
	    default:
		return DefWindowProc(hwnd, message, wParam, lParam);
	    }
	case IDC_BUTTON_TRACK:
	    switch (wmEvent) {
	    case BN_CLICKED:
		handle_button_track ();
		highlight_dialog_buttons ();
		return 1;
	    default:
		return DefWindowProc(hwnd, message, wParam, lParam);
	    }
	/* Replay buttons */
	case IDC_BUTTON_REWBEG:
	    switch (wmEvent) {
	    case BN_CLICKED:
		ise_fluoro_rewind_display ();
		gdi_rewind_frame_slider (hwnd_to_idx (hwnd));
		highlight_dialog_buttons ();
		return 1;
	    default:
		return DefWindowProc(hwnd, message, wParam, lParam);
	    }
	case IDC_BUTTON_REPLAY:
	    switch (wmEvent) {
	    case BN_CLICKED:
		handle_button_replay ();
		globals.notify[hwnd_to_idx (hwnd)] = 1;
		highlight_dialog_buttons ();
		return 1;
	    default:
		return DefWindowProc(hwnd, message, wParam, lParam);
	    }
	}
	break;
    case WM_LBUTTONUP:
	{
	    int x = LOWORD(lParam);
	    int y = HIWORD(lParam);
	    int idx = hwnd_to_idx (hwnd);
	    handle_mouse_lbutton_up (idx, x, y);
	}
	break;
    case WM_RBUTTONUP:
	{
	    int x = LOWORD(lParam);
	    int y = HIWORD(lParam);
	    gl_zoom_at_pos (hwnd_to_idx (hwnd), x, y);
	    globals.notify[hwnd_to_idx (hwnd)] = 1;
	}
	break;
    case WM_MOUSEMOVE:
	{
	    int x = LOWORD(lParam);
	    int y = HIWORD(lParam);
	    int idx = hwnd_to_idx (hwnd);
	    handle_mouse_motion (idx, x, y);
	}
	break;
    case WM_SIZE:
        // Resize window
        if (wParam != SIZE_MINIMIZED) {
	    do_resize (hwnd);
	    resize_gl_window (hwnd_to_idx (hwnd));
	}
        break;
    case WM_PAINT:
	{
	    debug_printf ("Got WM_PAINT event\n");
	    hdc = BeginPaint(hwnd, &ps);
	    globals.notify[hwnd_to_idx (hwnd)] = 1;
	    EndPaint(hwnd, &ps);
	}
	break;
    case WM_HSCROLL:
	{
	    handle_slider_frame (hwnd);
	    return 1;
	}
    case WM_VSCROLL:
	{
	    HWND sb_hwnd = (HWND) lParam;
	    unsigned short bot, top;

	    bot = (unsigned short) SendDlgItemMessage (hwnd, IDC_SLIDER_BOT, TBM_GETPOS, 0, 0);
	    top = (unsigned short) SendDlgItemMessage (hwnd, IDC_SLIDER_TOP, TBM_GETPOS, 0, 0);
	    if (sb_hwnd == GetDlgItem(hwnd, IDC_SLIDER_BOT)) {
		if (bot > top) {
		    SendDlgItemMessage (hwnd, IDC_SLIDER_TOP, TBM_SETPOS, TRUE, bot);
		    bot = top;
		}
	    }
	    if (sb_hwnd == GetDlgItem(hwnd, IDC_SLIDER_TOP)) {
		if (top < bot) {
		    SendDlgItemMessage (hwnd, IDC_SLIDER_BOT, TBM_SETPOS, TRUE, top);
		    bot = top;
		}
	    }
	    update_wl_status (hwnd_to_idx(hwnd), bot, top);
	    update_lut (hwnd, (long) bot, (long) top);
	    globals.notify[hwnd_to_idx (hwnd)] = 1;
	}
	return 0;
    case WM_NOTIFY:
	{
	    NMHDR *pnmh = (LPNMHDR) lParam;
	    if (wParam == IDC_SLIDER_BOT) {
		return 0;
	    }
	}
	return 0;
    case WM_INITDIALOG:
	return TRUE;
    case WM_CLOSE:
    case WM_DESTROY:
	PostQuitMessage(0);
	globals.quit = 1;
	break;
    default:
	return 0;
    }
    return 0;
}
static void animationUpdate(struct Animation *animation, const AnimationProgress progress){
  int percent = progress * 100 / ANIMATION_NORMALIZED_MAX;
  do_resize(percent);
}
Exemplo n.º 12
0
static LRESULT CALLBACK wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
    int x, y, w, h;
    msg_t m;

    x = GET_X_LPARAM(lparam);
    y = GET_Y_LPARAM(lparam);
    w = LOWORD(lparam);
    h = HIWORD(lparam);

    switch (msg) {
    case WM_CLOSE:
        PostQuitMessage(0);
        break;
    case WM_SIZE:
        if (init_done)
            do_resize(w, h);
        break;
    case WM_MOVE:
        break;
    case WM_EXITSIZEMOVE:
        break;
    case WM_MOUSELEAVE:
        tracking = 0;
        break;
    case WM_MOUSEMOVE:
        if (clipcursor)
            update_clip(hwnd); //TODO: shouldnt be here

        if (!tracking) {
            TrackMouseEvent(&tme);
            tracking = 1;
        }
        input_mmove(&input, x, y, 0);
        break;
    case WM_LBUTTONDOWN:
        input_mdown(&input, x, y, 0, 0);
        break;
    case WM_LBUTTONUP:
        input_mup(&input, x, y, 0, 0);
        break;
    case WM_RBUTTONDOWN:
        input_mdown(&input, x, y, 0, 2);
        break;
    case WM_RBUTTONUP:
        input_mup(&input, x, y, 0, 2);
        break;
    case WM_MBUTTONDOWN:
        input_mdown(&input, x, y, 0, 1);
        break;
    case WM_MBUTTONUP:
        input_mup(&input, x, y, 0, 1);
        break;
    case WM_MOUSEWHEEL:
        input_mwheel(&input, (double) (int16_t)HIWORD(wparam) / 120.0);
        break;
    case WM_KEYDOWN:
        if (wparam == VK_F1) {
            if (!clipcursor)
                update_clip(hwnd);
            else
                ClipCursor(0);
            clipcursor = !clipcursor;
            break;
        }
        input_keydown(&input, wparam, wparam);
        break;
    case WM_KEYUP:
        input_keyup(&input, wparam);
        break;
    case WM_USER:
        m.v = wparam;
        do_msg(m.id, m.v8, m.v16, m.value, (void*)lparam);
        break;
    default:
        return DefWindowProc(hwnd, msg, wparam, lparam);
    }

    return 0;
}
Exemplo n.º 13
0
 virtual void dim(const Dim& dim) {
   m_stride = dim.ncols(); do_resize(dim.nrows() * dim.ncols()); }
Exemplo n.º 14
0
 virtual void dimensions(size_t rows, size_t cols) {
   m_stride = cols; do_resize(rows * cols); }
Exemplo n.º 15
0
 virtual void ncols(size_t ncols) {
   m_stride = ncols;
   do_resize((m_size / m_stride) * m_stride);
 }
Exemplo n.º 16
0
 virtual void nrows(size_t nrows) {
   do_resize(nrows * m_stride);
 }