* The generated image is now really back and white.
* Display speedup.
pull/1/head
Remi Chateauneu 2012-01-08 16:09:44 +00:00 zatwierdzone przez David Freese
rodzic ae363526ed
commit 6b7067ed77
3 zmienionych plików z 42 dodań i 40 usunięć

Wyświetl plik

@ -35,7 +35,7 @@ private:
int bufsize;
int width;
int height;
int depth;
static const int depth = 3;
int numcol;
int slantdir;
void slant_corr(int x, int y);
@ -48,7 +48,16 @@ public:
picture(int, int, int, int, int bg_col = 0);
~picture();
void video(unsigned char *, int);
void pixel(unsigned char, int);
void pixel(unsigned char data, int pos) {
if (pos < 0 || pos >= bufsize) {
return ;
}
FL_LOCK_D();
vidbuf[pos] = data;
if (pos % (width * depth) == 0)
redraw();
FL_UNLOCK_D();
}
unsigned char pixel(int);
int handle(int);
void draw();

Wyświetl plik

@ -321,9 +321,6 @@ int wefax_pic::update_rx_pic_col(unsigned char data, int pix_pos )
/// Each time the received image becomes too high, we increase its height.
static const int curr_pix_incr_height = 100 ;
/// Maybe there is a slant.
pix_pos = ( double )pix_pos * slant_factor_default() + 0.5 ;
/// Three ints per pixel. It is safer to recalculate the
/// row index to avoid any buffer overflow, because the given
/// row is invalid if the image was horizontally moved.
@ -449,11 +446,17 @@ void wefax_pic::update_rx_pic_bw(unsigned char data, int pix_pos )
return ;
};
/// The image must be horizontally shifted.
pix_pos += center_val_prev ;
pix_pos += center_val_prev * bytes_per_pix ;
if( pix_pos < 0 ) {
pix_pos = 0 ;
}
/// Maybe there is a slant.
pix_pos = ( double )pix_pos * slant_factor_default() + 0.5 ;
/// Must be a multiple of the number of bytes per pixel.
pix_pos = ( pix_pos / bytes_per_pix ) * bytes_per_pix ;
static int last_row_number = 0 ;
update_rx_pic_col(data, pix_pos);
@ -1082,9 +1085,7 @@ void wefax_pic::create_rx_viewer(int pos_x, int pos_y,int win_wid, int hei_win)
wefax_slider_rx_center = new Fl_Slider(wid_off_low, hei_off_low, wid_btn_curr, height_btn, _(title_center));
wefax_slider_rx_center->type(FL_HORIZONTAL);
wefax_slider_rx_center->align(FL_ALIGN_LEFT);
/// Multiplied by three because of color image.
double range_rx_center = bytes_per_pix * (double)wid_img ;
wefax_slider_rx_center->range(-range_rx_center, range_rx_center);
/// The range is set when the image size in pixels is known.
wefax_slider_rx_center->step(1.0);
wefax_slider_rx_center->callback(wefax_cb_pic_rx_center, 0);
wefax_slider_rx_center->tooltip(_("Align image horizontally."));
@ -1146,6 +1147,10 @@ void wefax_pic::resize_rx_viewer(int wid_img)
snprintf( buffer_width, sizeof(buffer_width), "%d", wid_img );
wefax_out_rx_width->value(buffer_width);
/// This is a number of pixels.
double range_rx_center = wid_img / 2.0 ;
wefax_slider_rx_center->range(-range_rx_center, range_rx_center);
wefax_pic_rx_win->redraw();
FL_UNLOCK_D();
}

Wyświetl plik

@ -60,7 +60,6 @@ picture::picture (int X, int Y, int W, int H, int bg_col) :
{
width = W;
height = H;
depth = 3;
bufsize = W * H * depth;
numcol = 0;
slantdir = 0;
@ -84,19 +83,6 @@ void picture::video(unsigned char *data, int len )
FL_UNLOCK_D();
}
void picture::pixel(unsigned char data, int pos)
{
if (pos < 0 || pos >= bufsize) {
LOG_ERROR("Image overflow pos=%d bufsize=%d", pos, bufsize );
return ;
}
FL_LOCK_D();
vidbuf[pos] = data;
if (pos % (width * 3) == 0)
redraw();
FL_UNLOCK_D();
}
unsigned char picture::pixel(int pos)
{
if (pos < 0 || pos >= bufsize) return 0;
@ -183,17 +169,19 @@ void picture::stretch(double the_ratio)
unsigned char * new_vidbuf = new unsigned char[new_bufsize];
/// No interpolation, it takes the nearest pixel.
for( int ix_out = 0 ; ix_out < new_bufsize ; ++ix_out ) {
for( int ix_out = 0 ; ix_out < new_bufsize ; ix_out += depth ) {
/// TODO: ix_out could be double to qvoid this conversion.
int ix_in = ( double )ix_out * the_ratio + 0.5 ;
ix_in = ( ix_in / depth ) * depth ;
if( ix_in >= bufsize ) {
/// Grey value as a filler to indicate the end. For debugging.
memset( new_vidbuf + ix_out, 128, new_bufsize - ix_out );
break ;
}
/// TODO: It might not properly work with color images !!!!
new_vidbuf[ ix_out ] = vidbuf[ ix_in ];
for( int i = 0; i < depth ; ++i )
{
new_vidbuf[ ix_out + i ] = vidbuf[ ix_in + i ];
}
};
delete [] vidbuf ;
@ -208,6 +196,8 @@ void picture::stretch(double the_ratio)
/// Beware that it is not protected by FL_LOCK_D/FL_UNLOCK_D
void picture::shift_horizontal_center(int horizontal_shift)
{
/// This is a number of pixels.
horizontal_shift *= depth ;
if( horizontal_shift < -bufsize ) {
horizontal_shift = -bufsize ;
}
@ -240,14 +230,13 @@ void picture::set_zoom( int the_zoom )
void picture::draw_cb( void *data, int x_screen, int y_screen, int wid_screen, uchar *buf)
{
const picture * ptr_pic = ( const picture * ) data ;
static const int dpth=3 ;
int img_width = ptr_pic->width ;
const unsigned char * in_ptr = ptr_pic->vidbuf ;
const int max_buf_offset = ptr_pic->bufsize - dpth ;
const int max_buf_offset = ptr_pic->bufsize - depth ;
/// Should not happen because tested before. This ensures that memcpy is OK.
if( ptr_pic->zoom == 0 ) {
int in_offset = img_width * y_screen + x_screen ;
memcpy( buf, in_ptr + in_offset * dpth, dpth * wid_screen );
memcpy( buf, in_ptr + in_offset * depth, depth * wid_screen );
return ;
}
@ -265,10 +254,10 @@ void picture::draw_cb( void *data, int x_screen, int y_screen, int wid_screen, u
stride );
return ;
}
int dpth_in_offset = dpth * in_offset ;
int dpth_in_offset = depth * in_offset ;
/// Check the latest offset.
if( dpth_in_offset + dpth * stride * wid_screen >= max_buf_offset ) {
if( dpth_in_offset + depth * stride * wid_screen >= max_buf_offset ) {
LOG_WARN(
"Boom1 y_sc=%d h=%d w=%d wd_sc=%d wdt=%d strd=%d off=%d prd=%d mbo=%d\n",
y_screen,
@ -278,15 +267,15 @@ void picture::draw_cb( void *data, int x_screen, int y_screen, int wid_screen, u
img_width,
stride,
in_offset,
( dpth_in_offset + dpth ),
( dpth_in_offset + depth ),
max_buf_offset );
return ;
}
for( int ix_w = 0, max_w = wid_screen * dpth; ix_w < max_w ; ix_w += dpth ) {
for( int ix_w = 0, max_w = wid_screen * depth; ix_w < max_w ; ix_w += depth ) {
buf[ ix_w ] = in_ptr[ dpth_in_offset ];
buf[ ix_w + 1 ] = in_ptr[ dpth_in_offset + 1 ];
buf[ ix_w + 2 ] = in_ptr[ dpth_in_offset + 2 ];
dpth_in_offset += dpth * stride ;
dpth_in_offset += depth * stride ;
}
return ;
}
@ -306,9 +295,8 @@ void picture::draw_cb( void *data, int x_screen, int y_screen, int wid_screen, u
stride );
return ;
}
/// TODO: Will not properly work for color images.
int dpth_in_offset = dpth * in_offset ;
for( int ix_w = 0, max_w = wid_screen * dpth; ix_w < max_w ; ix_w += dpth ) {
int dpth_in_offset = depth * in_offset ;
for( int ix_w = 0, max_w = wid_screen * depth; ix_w < max_w ; ix_w += depth ) {
#ifndef NDEBUG
if( dpth_in_offset >= max_buf_offset ) {
LOG_WARN(
@ -328,8 +316,8 @@ void picture::draw_cb( void *data, int x_screen, int y_screen, int wid_screen, u
buf[ ix_w ] = in_ptr[ dpth_in_offset ];
buf[ ix_w + 1 ] = in_ptr[ dpth_in_offset + 1 ];
buf[ ix_w + 2 ] = in_ptr[ dpth_in_offset + 2 ];
if( ( ix_w % ( dpth * stride ) ) == 0 ) {
dpth_in_offset += dpth ;
if( ( ix_w % ( depth * stride ) ) == 0 ) {
dpth_in_offset += depth ;
}
}
return ;