Пример #1
0
void k2file_get_overlay_bitmap(WILLUSBITMAP *bmp,double *dpi,char *filename,char *pagelist)

    {
    int i,c,c2,src_type,np;
    char mupdffilename[MAXFILENAMELEN];
    static K2PDFOPT_SETTINGS _k2settings;
    K2PDFOPT_SETTINGS *k2settings;
    WILLUSBITMAP *tmp,_tmp;

    (*dpi)=100.;
    src_type = get_source_type(filename);
    if (src_type!=SRC_TYPE_PDF && src_type!=SRC_TYPE_DJVU)
        return;
    strncpy(mupdffilename,filename,MAXFILENAMELEN-1);
    mupdffilename[MAXFILENAMELEN-1]='\0';
    k2settings=&_k2settings;
    k2pdfopt_settings_init(k2settings);
    k2settings->document_scale_factor=1.0;
    k2settings->usegs=-1;
    np=file_numpages(filename,mupdffilename,src_type,&k2settings->usegs);
    for (c=0,i=1;i<=np;i++)
        if (pagelist_includes_page(pagelist,i,np))
            c++;
#ifdef HAVE_K2GUI
    if (k2gui_active())
        {
        k2gui_overlay_set_num_pages(c);
        k2gui_overlay_set_pages_completed(0,NULL);
        }
#endif
    tmp=&_tmp;
    bmp_init(tmp);
    for (c=c2=0,i=1;i<=np;i++)
        {
        int status;

        if (!pagelist_includes_page(pagelist,i,np))
            continue;
        status=bmp_get_one_document_page(tmp,k2settings,src_type,mupdffilename,i,100.,8,NULL);
        c2++;
#ifdef HAVE_K2GUI
        if (k2gui_active())
            k2gui_overlay_set_pages_completed(c2,NULL);
#endif
        if (status)
            {
#ifdef HAVE_K2GUI
            if (k2gui_active())
                k2gui_overlay_error(filename,i,status);
#endif
            continue;
            }
        c++;
        if (c==1)
            bmp_copy(bmp,tmp);
        else
            bmp8_merge(bmp,tmp,c);
        }
    bmp_free(tmp);
    }
Пример #2
0
static int k2_handle_preview(K2PDFOPT_SETTINGS *k2settings,MASTERINFO *masterinfo,
                             int k2mark_page_count,WILLUSBITMAP *markedbmp,
                             K2PDFOPT_OUTPUT *k2out)

    {
    int status;

    status= (masterinfo->preview_captured 
                      || (k2settings->show_marked_source
                           && abs(k2settings->preview_page)==k2mark_page_count));
    if (status)
        {
        if (k2settings->show_marked_source)
            bmp_copy(masterinfo->preview_bitmap,markedbmp);
/*
printf("Got preview bitmap:  %d x %d x %d.\n",
masterinfo->preview_bitmap->width,masterinfo->preview_bitmap->height,masterinfo->preview_bitmap->bpp);
*/
        if (k2out->bmp==NULL)
            {
            bmp_write(masterinfo->preview_bitmap,"k2pdfopt_out.png",NULL,100);
            bmp_free(masterinfo->preview_bitmap);
            }
        }
    return(status);
    }
Пример #3
0
static void wrapbmp_hyphen_erase(WRAPBMP *wrapbmp,K2PDFOPT_SETTINGS *k2settings)

    {
    WILLUSBITMAP *bmp,_bmp;
    int bw,bpp,c0,c1,c2,i;

    if (wrapbmp->hyphen.ch<0)
        return;
#if (WILLUSDEBUGX & 16)
printf("@hyphen_erase, bmp=%d x %d x %d\n",wrapbmp->bmp.width,wrapbmp->bmp.height,wrapbmp->bmp.bpp);
printf("    ch=%d, c2=%d, r1=%d, r2=%d\n",wrapbmp->hyphen.ch,wrapbmp->hyphen.c2,wrapbmp->hyphen.r1,wrapbmp->hyphen.r2);
#endif
    bmp=&_bmp;
    bmp_init(bmp);
    bmp->bpp = wrapbmp->bmp.bpp;
    if (bmp->bpp==8)
        for (i=0;i<256;i++)
            bmp->red[i]=bmp->blue[i]=bmp->green[i]=i;
    bmp->height = wrapbmp->bmp.height;
    if (k2settings->src_left_to_right)
        {
        bmp->width = wrapbmp->hyphen.c2+1;
        c0=0;
        c1=wrapbmp->hyphen.ch;
        c2=bmp->width-1;
        }
    else
        {
        bmp->width = wrapbmp->bmp.width - wrapbmp->hyphen.c2;
        c0=wrapbmp->hyphen.c2;
        c1=0;
        c2=wrapbmp->hyphen.ch-wrapbmp->hyphen.c2;
        }
    bmp_alloc(bmp);
    bpp=bmp->bpp==24 ? 3 : 1;
    bw=bpp*bmp->width;
    for (i=0;i<bmp->height;i++)
        memcpy(bmp_rowptr_from_top(bmp,i),bmp_rowptr_from_top(&wrapbmp->bmp,i)+bpp*c0,bw);
    bw=(c2-c1+1)*bpp;
    if (bw>0)
        for (i=wrapbmp->hyphen.r1;i<=wrapbmp->hyphen.r2;i++)
            memset(bmp_rowptr_from_top(bmp,i)+bpp*c1,255,bw);
#if (WILLUSDEBUGX & 16)
{
static int count=1;
char filename[256];
sprintf(filename,"be%04d.png",count);
bmp_write(&wrapbmp->bmp,filename,stdout,100);
sprintf(filename,"ae%04d.png",count);
bmp_write(bmp,filename,stdout,100);
count++;
}
#endif
    bmp_copy(&wrapbmp->bmp,bmp);
    bmp_free(bmp);
    }
Пример #4
0
int main() {
    // Init components
    components_init();
    
    // Load fonts
    f_small = font_load("font_small");
    f_large = font_load("font_large");
    
    // Load images
    img_blood = bmp_load("images/blood.bmp");
    bmp_image *img_space = bmp_load("images/space.bmp");
    bmp_image *img_ufo1 = bmp_load("images/ufo1.bmp");
    bmp_image *img_ufo2 = bmp_load("images/ufo2.bmp");
    bmp_image *img_ufo3 = bmp_load("images/ufo3.bmp");
    bmp_image *img_ufo4 = bmp_load("images/ufo4.bmp");
    bmp_image *img_ufo5 = bmp_load("images/ufo5.bmp");
    bmp_image *img_rabby = bmp_load("rabbit.bmp");
    bmp_image *img_powerup1 = bmp_load("images/pow1.bmp");
    bmp_image *img_powerup2 = bmp_load("images/pow1.bmp");
    bmp_image *img_powerup3 = bmp_load("images/pow1.bmp");
    bmp_image *img_powerup4 = bmp_load("images/pow1.bmp");
    bmp_image *img_rabby_red = bmp_copy(img_rabby);
    bmp_tint(img_rabby_red, 255, 128, 128);
    bmp_tint(img_powerup3, 0, 250, 29);
    bmp_tint(img_powerup2, 0, 0, 255);
    bmp_tint(img_powerup1, 255, 255, 29);
    
    // Create drawables
    space = drawable_create_bmp(img_space);
    ufo1 = drawable_create_bmp(img_ufo1);
    ufo2 = drawable_create_bmp(img_ufo2);
    ufo3 = drawable_create_bmp(img_ufo3);
    ufo4 = drawable_create_bmp(img_ufo4);
    ufo5 = drawable_create_bmp(img_ufo5);
    rabby = drawable_create_bmp(img_rabby);
    bullet = drawable_create_rect(4, 4, 255, 255, 255);
    rabby_red = drawable_create_bmp(img_rabby_red);
    power_sprite[0] = drawable_create_bmp(img_powerup1);
    power_sprite[1] = drawable_create_bmp(img_powerup2);
    power_sprite[2] = drawable_create_bmp(img_powerup3);
    power_sprite[3] = drawable_create_bmp(img_powerup4);
    
    // Start midi player in another thread
    pthread_t thread_midi;
    int result = pthread_create(&thread_midi, NULL, midi_run, NULL);
    
    // Loop game
    while (1) {
        engine_init();
        init();
        engine_run();
        dispose();
        engine_dispose();
    }
}
Пример #5
0
void imagenes_abrir(configuracion_t *config)
{
	// Cargo la imagen
	if ( (src_img = bmp_read (config->archivo_entrada)) == 0 ) {
    	fprintf(stderr, "Error abriendo la imagen fuente\n");
		exit(EXIT_FAILURE);
	}
	if (bmp_compression(src_img) != BI_RGB) {
		fprintf(stderr, "Error: La imagen fuente esta comprimida\n");
		exit(EXIT_FAILURE);
	}

	if (bmp_bit_count(src_img) == 24) {
    	bmp_convert_24_to_32_bpp(src_img);
	}

	dst_img = bmp_copy( src_img, 1 );

	if (config->archivo_entrada_2 != NULL) {
		if ( (src_img2 = bmp_read (config->archivo_entrada_2)) == 0 ) {
	    	fprintf(stderr, "Error abriendo la imagen fuente 2\n");
			exit(EXIT_FAILURE);
		}
		if (bmp_compression(src_img2) != BI_RGB) {
			fprintf(stderr, "Error: La imagen fuente 2 esta comprimida\n");
			exit(EXIT_FAILURE);
		}

		if (bmp_bit_count(src_img2) == 24) {
	    	bmp_convert_24_to_32_bpp(src_img2);
		}
		setear_buffer(&config->src_2, src_img2);
	} else {
		src_img2 = NULL;
	}

	setear_buffer(&config->src, src_img);
	setear_buffer(&config->dst, dst_img);
}
Пример #6
0
void rotsprite_image(Image* bmp, Image* spr,
  int x1, int y1, int x2, int y2,
  int x3, int y3, int x4, int y4)
{
  static ImageBufferPtr buf1, buf2, buf3; // TODO non-thread safe

  if (!buf1) buf1.reset(new ImageBuffer(1));
  if (!buf2) buf2.reset(new ImageBuffer(1));
  if (!buf3) buf3.reset(new ImageBuffer(1));

  int scale = 8;
  base::UniquePtr<Image> bmp_copy(Image::create(bmp->pixelFormat(), bmp->width()*scale, bmp->height()*scale, buf1));
  base::UniquePtr<Image> tmp_copy(Image::create(spr->pixelFormat(), spr->width()*scale, spr->height()*scale, buf2));
  base::UniquePtr<Image> spr_copy(Image::create(spr->pixelFormat(), spr->width()*scale, spr->height()*scale, buf3));

  color_t maskColor = spr->maskColor();

  bmp_copy->setMaskColor(maskColor);
  tmp_copy->setMaskColor(maskColor);
  spr_copy->setMaskColor(maskColor);

  bmp_copy->clear(bmp->maskColor());
  spr_copy->clear(maskColor);
  spr_copy->copy(spr, gfx::Clip(spr->bounds()));

  for (int i=0; i<3; ++i) {
    tmp_copy->clear(maskColor);
    image_scale2x(tmp_copy, spr_copy, spr->width()*(1<<i), spr->height()*(1<<i));
    spr_copy->copy(tmp_copy, gfx::Clip(tmp_copy->bounds()));
  }

  doc::algorithm::parallelogram(bmp_copy, spr_copy,
    x1*scale, y1*scale, x2*scale, y2*scale,
    x3*scale, y3*scale, x4*scale, y4*scale);

  doc::algorithm::scale_image(bmp, bmp_copy,
    0, 0, bmp->width(), bmp->height());
}
Пример #7
0
int main(int argc, char* argv[]){
  int i,j;
  
  // (0) leer parametros
  options opt;
  if (argc == 1) {print_help(argv[0]); return 0;}
  if(read_options(argc, argv, &opt))
  {printf("ERROR reading parameters\n"); return 1;}
  int len1 = strlen(opt.file1);
  int len2 = strlen(opt.file2);
  if( strcmp(&(opt.file1[len1-4]),".bmp") || strcmp(&(opt.file2[len2-4]),".bmp") )
  { printf("ERROR: nombre del archivo\n"); return -1;}
  
  // (0.1) siempre armo el summary
  opt.summary = (int*)malloc(sizeof(int)*256);
  for(i=0;i<256;i++) opt.summary[i]=0;
  
  // (1) leer imagenes
  BMP* bmp1 = bmp_read(opt.file1);
  BMP* bmp2 = bmp_read(opt.file2);
  if( bmp1==0 || bmp1==0 )
  { printf("ERROR: no se puede abrir el archivo\n"); return -1;}
  
  // (2) check tipo de archivo
  if( ((BMPIH*)(bmp1->ih))->biSize != ((BMPIH*)(bmp1->ih))->biSize )
  { printf("ERROR: tipo de archivo diferente\n"); return -1;}
  
  // (3) check tamaño del archivo
  int w1 = ((BMPIH*)(bmp1->ih))->biWidth;
  int h1 = ((BMPIH*)(bmp1->ih))->biHeight;
  int c1 = ((BMPIH*)(bmp1->ih))->biBitCount;
  int w2 = ((BMPIH*)(bmp2->ih))->biWidth;
  int h2 = ((BMPIH*)(bmp2->ih))->biHeight;
  int c2 = ((BMPIH*)(bmp2->ih))->biBitCount;
  if( w1!=w2 || h1!=h2 || c1!=c2 )
  { printf("ERROR: tamaño de archivo diferente\n"); return -1;}
  //printf("%i=%i %i=%i %i=%i\n",w1,w2,h1,h2,c1,c2);
  if(w1%4!=0) { printf("ERROR: padding no soportado\n"); return -1;} // TODO: soportar padding!
  
  // (3) check el bit count TODO: only 24 o 32
  if( c1!=24 && c1!=32 )
    { printf("ERROR: (%i) bitcount distinto de 24 o 32\n", c1); return -1;}
  
  // (4) crear imagenes de diferencias
  BMP *bmpDiffR, *bmpDiffG, *bmpDiffB, *bmpDiffA;
  bmpDiffR = bmp_copy(bmp1,0);
  bmpDiffG = bmp_copy(bmp1,0);
  bmpDiffB = bmp_copy(bmp1,0);
  if(c1 == 32)
    bmpDiffA = bmp_copy(bmp1,0);
  
  // (5) extraer data
  uint8_t *data1,*data2,*dataR,*dataG,*dataB,*dataA;
  data1 = bmp_get_data(bmp1);
  data2 = bmp_get_data(bmp2);
  dataR = bmp_get_data(bmpDiffR);
  dataG = bmp_get_data(bmpDiffG);
  dataB = bmp_get_data(bmpDiffB);
  if(c1 == 32)
    dataA = bmp_get_data(bmpDiffA);
  
  // (6) calcular diferencias
  if(c1 == 32)
  for(j=0;j<h1;j++) {
    for(i=0;i<w1;i++) {
      int pos = (j*w1+i)*4;
      uint8_t R1 = data1[pos+3];
      uint8_t G1 = data1[pos+2];
      uint8_t B1 = data1[pos+1];
      uint8_t A1 = data1[pos+0];
      uint8_t R2 = data2[pos+3];
      uint8_t G2 = data2[pos+2];
      uint8_t B2 = data2[pos+1];
      uint8_t A2 = data2[pos+0];
      
      dataR[pos+3] = cmp(R1,R2,i,j,"R",&opt);
      dataR[pos+2] = dataR[pos+3];
      dataR[pos+1] = dataR[pos+3];
      dataR[pos+0] = 255;
      
      dataG[pos+3] = cmp(G1,G2,i,j,"G",&opt);
      dataG[pos+2] = dataG[pos+3];
      dataG[pos+1] = dataG[pos+3];
      dataG[pos+0] = 255;
      
      dataB[pos+3] = cmp(B1,B2,i,j,"B",&opt);
      dataB[pos+2] = dataB[pos+3];
      dataB[pos+1] = dataB[pos+3];
      dataB[pos+0] = 255;

      dataA[pos+3] = cmp(A1,A2,i,j,"A",&opt);
      dataA[pos+2] = dataA[pos+3];
      dataA[pos+1] = dataA[pos+3];
      dataA[pos+0] = 255;
    }
  }
  if(c1 == 24)
  for(j=0;j<h1;j++) {
    for(i=0;i<w1;i++) {
      int pos = (j*w1+i)*3;
      uint8_t R1 = data1[pos+2];
      uint8_t G1 = data1[pos+1];
      uint8_t B1 = data1[pos+0];
      uint8_t R2 = data2[pos+2];
      uint8_t G2 = data2[pos+1];
      uint8_t B2 = data2[pos+0];
      
      dataR[pos+2] = cmp(R1,R2,i,j,"R",&opt);
      dataR[pos+1] = dataR[pos+2];
      dataR[pos+0] = dataR[pos+2];
      
      dataG[pos+2] = cmp(G1,G2,i,j,"G",&opt);
      dataG[pos+1] = dataG[pos+2];
      dataG[pos+0] = dataG[pos+2];
      
      dataB[pos+2] = cmp(B1,B2,i,j,"B",&opt);
      dataB[pos+1] = dataB[pos+2];
      dataB[pos+0] = dataB[pos+2];
    }
  }
  
  // (7) mostrar summary
  if(opt.summaryop) {
    for(i=1;i<256;i++)
      if(opt.summary[i]!=0)
      printf("%i\t%i\n",i,opt.summary[i]);
  }
  
  // (8) guardar resultados
  if(opt.image) {
    char* strX = "diffX.bmp";
    char* fileSto = malloc(strlen(opt.file1)+5+1);
    strcpy(fileSto,opt.file1);
    strcpy(fileSto+len1-4,strX);
    fileSto[len1]='R';
    bmp_save(fileSto,bmpDiffR);
    fileSto[len1]='G';
    bmp_save(fileSto,bmpDiffG);
    fileSto[len1]='B';
    bmp_save(fileSto,bmpDiffB);
    fileSto[len1]='A';
    if(c1 == 32)
      bmp_save(fileSto,bmpDiffA);
  
    // (8.1) borrar las imagenes
    bmp_delete(bmp1);
    bmp_delete(bmp2);
    bmp_delete(bmpDiffR);
    bmp_delete(bmpDiffG);
    bmp_delete(bmpDiffB);
    if(c1 == 32)
      bmp_delete(bmpDiffA);
  }
  
  // (9) retorno error si encontre una diferencia
  for(i=opt.epsilon;i<256;i++)
    if(opt.summary[i]>0)
      return -1;
  return 0;
}
Пример #8
0
int main(){

  /* ======================================================================= */
  /* === EJ 1 : crear un bmp de 24 bits de 100x100 y dibujar un patron bayer */

  // creo el header de una imagen de 100x100 de 24 bits
  BMPIH* imgh1 = get_BMPIH(100,100);

  // crea una imagen bmp inicializada
  BMP* bmp1 = bmp_create(imgh1,1);

  // obtengo la data y dibujo el patron bayer
  uint8_t* data1 = bmp_get_data(bmp1);
  int i,j;
  for(j=0;j<100;j=j+2) {
    for(i=0;i<100;i=i+2) {
      data1[j*300+3*i+1] = 0xff;
      data1[j*300+3*i+3] = 0xff;
    }
    for(i=0;i<100;i=i+2) {
      data1[j*300+300+3*i+2] = 0xff;
      data1[j*300+300+3*i+4] = 0xff;
    }
  }

  // guardo la imagen
  bmp_save(FILE1, bmp1);

  // borrar bmp
  bmp_delete(bmp1);

  /* ======================================================================= */
  /* === EJ 2 : crear un bmp de 32 bits de 100x100 y fondo blanco en degrade */

  // creo el encavezado de una imagen de 640x480 de 32 bits
  BMPV5H* imgh2 = get_BMPV5H(100,100);

  // crea una imagen bmp no inicializada
  BMP* bmp2 = bmp_create(imgh2,0);

  // obtengo la data y dibujo el degrade
  uint8_t* data2 = bmp_get_data(bmp2);
  for(j=0;j<100;j++) {
    for(i=0;i<100;i++) {
      data2[j*400+i*4+0] = (uint8_t)(((float)(i+j))*(256.0/200.0));
      data2[j*400+i*4+1] = 0xff;
      data2[j*400+i*4+2] = 0xff;
      data2[j*400+i*4+3] = 0xff;
    }
  }

  // guardo la imagen
  bmp_save(FILE2, bmp2);

  // borrar bmp
  bmp_delete(bmp2);

  /* ======================================================================= */
  /* === EJ 3 : crear un bmp con el mapa de bits de bmp1 y el alpha de bmp2  */

  // Abro los dos archivos
  BMP* bmp1n = bmp_read(FILE1);
  BMP* bmp2n = bmp_read(FILE2);

  // copio la imagen con transparecia sin datos
  BMP* bmpNEW = bmp_copy(bmp2n, 0);

  // obtengo datos de new y las combino
  uint8_t* data1n = bmp_get_data(bmp1n);
  uint8_t* data2n = bmp_get_data(bmp2n);
  uint8_t* dataNEW = bmp_get_data(bmpNEW);
  for(j=0;j<100;j++) {
    for(i=0;i<100;i++) {
      dataNEW[j*400+i*4+0] = data2n[j*400+i*4+0];
      dataNEW[j*400+i*4+1] = data1n[j*300+i*3+0];
      dataNEW[j*400+i*4+2] = data1n[j*300+i*3+1];
      dataNEW[j*400+i*4+3] = data1n[j*300+i*3+2];
    }
  }

  // guardo la imagen
  bmp_save(FILE3, bmpNEW);

  // borrar bmp
  bmp_delete(bmp1n);
  bmp_delete(bmp2n);
  bmp_delete(bmpNEW);

  return 0;
}
Пример #9
0
// static int bcount=0;
void wrapbmp_add(WRAPBMP *wrapbmp,BMPREGION *region,K2PDFOPT_SETTINGS *k2settings,
                 MASTERINFO *masterinfo,int colgap,int just_flags)

    {
    WILLUSBITMAP *tmp,_tmp;
    int i,rh,th,bw,new_base,h2,bpp,width0;
// static char filename[256];

#if (WILLUSDEBUGX & 205)
k2printf("@wrapbmp->add %d x %d (w=%d).\n",region->c2-region->c1+1,region->r2-region->r1+1,wrapbmp->bmp.width);
printf("    line_spacing=%d\n",region->bbox.rowheight);
#endif
    /* Figure out if what we're adding ends in a hyphen */
    bmpregion_hyphen_detect(region,k2settings->hyphen_detect,k2settings->src_left_to_right);
    if (wrapbmp_ends_in_hyphen(wrapbmp))
        colgap=0;
    wrapbmp_hyphen_erase(wrapbmp,k2settings);
    wrapbmp->just_flushed_internal=0;  // Reset "just flushed" flag
    if (wrapbmp->bmp.width==0)
        wrapbmp->textrow=region->bbox;
    else
        {
        if (region->bbox.rowheight > wrapbmp->textrow.rowheight)
            wrapbmp->textrow.rowheight = region->bbox.rowheight;
        if (region->bbox.gap > wrapbmp->textrow.gap)
            wrapbmp->textrow.gap = region->bbox.gap;
        if (region->bbox.gapblank > wrapbmp->textrow.gapblank)
            wrapbmp->textrow.gapblank = region->bbox.gapblank;
        }
    wrapbmp->bgcolor=region->bgcolor;
    wrapbmp->just=just_flags;
    if (wrapbmp->mandatory_region_gap<0)
        {
        wrapbmp->mandatory_region_gap=masterinfo->mandatory_region_gap;
        wrapbmp->page_region_gap_in=masterinfo->page_region_gap_in;
        masterinfo->mandatory_region_gap=0;
        masterinfo->page_region_gap_in=-1.;
#if (WILLUSDEBUGX & 0x200)
aprintf(ANSI_RED "mi->mandatory_region_gap change to %d by wrap_add." ANSI_NORMAL "\n",masterinfo->mandatory_region_gap);
#endif
        }
#if (WILLUSDEBUGX & 4)
k2printf("    c1=%d, c2=%d, r1=%d, r2=%d\n",region->c1,region->c2,region->r1,region->r2);
k2printf("    colgap=%d, line_spacing=%d, rowbase=%d, row gap=%d\n",colgap,region->bbox.rowheight,region->bbox.rowbase,region->bbox.gap);
#endif
    bpp=k2settings->dst_color?3:1;
    rh=region->bbox.rowbase-region->r1+1;
    if (rh > wrapbmp->rhmax)
        wrapbmp->rhmax=rh;
    th = rh + (region->r2-region->bbox.rowbase);
    if (th > wrapbmp->thmax)
        wrapbmp->thmax=th;
#if (WILLUSDEBUGX & 4)
{
static int bcount=0;
char filename[256];
sprintf(filename,"out%05d.png",bcount++);
bmpregion_write(region,filename);
}
#endif
    if (wrapbmp->bmp.width==0)
        {
        /* Put appropriate gap in */
/*
        if (k2settings->last_rowbase_internal>=0 && rh < wrapbmp->textrow.rowheight-k2settings->last_rowbase_internal)
            {
            rh = wrapbmp->textrow.rowheight - k2settings->last_rowbase_internal;
            if (rh<2)
                rh=2;
            th = rh + (region->r2-region->bbox.rowbase);
            wrapbmp->height_extended=0;
            }
        else
            wrapbmp->height_extended=(k2settings->last_rowbase_internal>=0);
*/
        wrapbmp->base = rh-1;
        wrapbmp->bmp.height = th;
#if (WILLUSDEBUGX & 4)
k2printf("    bmpheight set to %d (line spacing=%d)\n",wrapbmp->bmp.height,wrapbmp->textrow.rowheight);
#endif
        wrapbmp->bmp.width=region->c2-region->c1+1;
        bmp_alloc(&wrapbmp->bmp);
        bw=bmp_bytewidth(&wrapbmp->bmp);
        memset(bmp_rowptr_from_top(&wrapbmp->bmp,0),255,bw*wrapbmp->bmp.height);
        for (i=region->r1;i<=region->r2;i++)
            {
            unsigned char *d,*s;
            d=bmp_rowptr_from_top(&wrapbmp->bmp,wrapbmp->base+(i-region->bbox.rowbase));
            s=bmp_rowptr_from_top(k2settings->dst_color?region->bmp:region->bmp8,i)+bpp*region->c1;
            memcpy(d,s,bw);
            }
#ifdef WILLUSDEBUG
if (wrapbmp->bmp.height<=wrapbmp->base)
{
k2printf("1. SCREEECH!\n");
k2printf("wrapbmp = %d x %d, base=%d\n",wrapbmp->bmp.width,wrapbmp->bmp.height,wrapbmp->base);
exit(10);
}
#endif
        /* Copy hyphen info from added region */
        wrapbmp->hyphen = region->bbox.hyphen;
        if (wrapbmp_ends_in_hyphen(wrapbmp))
            {
            wrapbmp->hyphen.r1 += (wrapbmp->base-region->bbox.rowbase);
            wrapbmp->hyphen.r2 += (wrapbmp->base-region->bbox.rowbase);
            wrapbmp->hyphen.ch -= region->c1;
            wrapbmp->hyphen.c2 -= region->c1;
            }
        /* Map to source page */
        {
        WRECTMAP _wrmap,*wrmap;

        wrmap=&_wrmap;
        wrmap->srcpageno = region->pageno;
        wrmap->srcwidth = region->bmp8->width;
        wrmap->srcheight = region->bmp8->height;
        wrmap->srcdpiw = wrmap->srcdpih = region->dpi;
        wrmap->srcrot = region->rotdeg;
        wrmap->coords[0].x = region->c1;
        wrmap->coords[0].y = region->r1;
        wrmap->coords[1].x = 0;
        wrmap->coords[1].y = wrapbmp->base+(region->r1-region->bbox.rowbase);
        wrmap->coords[2].x = region->c2-region->c1+1;
        wrmap->coords[2].y = region->r2-region->r1+1;
#if (WILLUSDEBUGX & 0x400)
    printf("@wrapbmp:  (x0,y0) = (%5.1f,%5.1f)\n",region->c1*72./region->dpi,region->r1*72./region->dpi);
printf("      %5.1f x %5.1f\n",(region->c2-region->c1+1)*72./region->dpi,(region->r2-region->r1+1)*72./region->dpi);
printf("      New bitmap = %d x %d\n",wrapbmp->bmp.width,wrapbmp->bmp.height);
#endif
        wrectmaps_add_wrectmap(&wrapbmp->wrectmaps,wrmap);
        }
        return;
        }
    width0=wrapbmp->bmp.width; /* Starting wrapbmp width */
    tmp=&_tmp;
    bmp_init(tmp);
    bmp_copy(tmp,&wrapbmp->bmp);
    tmp->width += colgap+region->c2-region->c1+1;
    if (rh > wrapbmp->base)
        {
        /* wrapbmp->height_extended=1; */
        new_base = rh-1;
        }
    else
        new_base = wrapbmp->base;
    if (region->r2-region->bbox.rowbase > wrapbmp->bmp.height-1-wrapbmp->base)
        h2=region->r2-region->bbox.rowbase;
    else
        h2=wrapbmp->bmp.height-1-wrapbmp->base;
    tmp->height = new_base + h2 + 1;
    bmp_alloc(tmp);
    bw=bmp_bytewidth(tmp);
    memset(bmp_rowptr_from_top(tmp,0),255,bw*tmp->height);
    bw=bmp_bytewidth(&wrapbmp->bmp);
#if (WILLUSDEBUGX & 4)
k2printf("3.  wbh=%d x %d, tmp=%d x %d x %d, new_base=%d, wbbase=%d\n",wrapbmp->bmp.width,wrapbmp->bmp.height,tmp->width,tmp->height,tmp->bpp,new_base,wrapbmp->base);
#endif

    /* Adjust previous mappings to source pages since WRAPBMP rectangle has been re-sized */
    if (new_base!=wrapbmp->base)
        for (i=0;i<wrapbmp->wrectmaps.n;i++)
            {
            wrapbmp->wrectmaps.wrectmap[i].coords[1].y += (new_base-wrapbmp->base);
            if (k2settings->src_left_to_right==0)
                wrapbmp->wrectmaps.wrectmap[i].coords[1].x += tmp->width-1-wrapbmp->bmp.width;
            }
    for (i=0;i<wrapbmp->bmp.height;i++)
        {
        unsigned char *d,*s;
        d=bmp_rowptr_from_top(tmp,i+new_base-wrapbmp->base)
                 + (k2settings->src_left_to_right ? 0 : tmp->width-1-wrapbmp->bmp.width)*bpp;
        s=bmp_rowptr_from_top(&wrapbmp->bmp,i);
        memcpy(d,s,bw);
        }
    bw=bpp*(region->c2-region->c1+1);
    if (region->r1+new_base-region->bbox.rowbase<0 || region->r2+new_base-region->bbox.rowbase>tmp->height-1)
        {
        k2printf(ANSI_YELLOW "INTERNAL ERROR--TMP NOT DIMENSIONED PROPERLY.\n");
        k2printf("(%d-%d), tmp->height=%d\n" ANSI_NORMAL,
            region->r1+new_base-region->bbox.rowbase,
            region->r2+new_base-region->bbox.rowbase,tmp->height);
        exit(10);
        }
    for (i=region->r1;i<=region->r2;i++)
        {
        unsigned char *d,*s;

        d=bmp_rowptr_from_top(tmp,i+new_base-region->bbox.rowbase)
                 + (k2settings->src_left_to_right ? wrapbmp->bmp.width+colgap : 0)*bpp;
        s=bmp_rowptr_from_top(k2settings->dst_color?region->bmp:region->bmp8,i)+bpp*region->c1;
        memcpy(d,s,bw);
        }
    {
    WRECTMAP _wrmap,*wrmap;

    wrmap=&_wrmap;
    wrmap->srcpageno = region->pageno;
    wrmap->srcwidth = region->bmp8->width;
    wrmap->srcheight = region->bmp8->height;
    wrmap->srcdpiw = wrmap->srcdpih = region->dpi;
    wrmap->srcrot = region->rotdeg;
    wrmap->coords[0].x = region->c1;
    wrmap->coords[0].y = region->r1;
    wrmap->coords[1].x = k2settings->src_left_to_right ? wrapbmp->bmp.width+colgap : 0;
    wrmap->coords[1].y = region->r1+new_base-region->bbox.rowbase;
    wrmap->coords[2].x = region->c2-region->c1+1;
    wrmap->coords[2].y = region->r2-region->r1+1;
#if (WILLUSDEBUGX & 0x400)
printf("@wrapbmp:  (x0,y0) = (%5.1f,%5.1f)\n",region->c1*72./region->dpi,region->r1*72./region->dpi);
printf("      org bmp = %d x %d\n",wrapbmp->bmp.width,wrapbmp->bmp.height);
printf("      new_base=%d, r_base=%d\n",new_base,region->bbox.rowbase);
printf("      (x1,y1) = (%g,%g)\n",wrmap->coords[1].x,wrmap->coords[1].y);
printf("      %5.1f x %5.1f\n",(region->c2-region->c1+1)*72./region->dpi,(region->r2-region->r1+1)*72./region->dpi);
printf("      New bitmap = %d x %d\n",tmp->width,tmp->height);
#endif
    wrectmaps_add_wrectmap(&wrapbmp->wrectmaps,wrmap);
    }
    bmp_copy(&wrapbmp->bmp,tmp);
#if (WILLUSDEBUGX & 4)
{
static int rcount=0;
char filename[256];
sprintf(filename,"result%03d.png",rcount++);
bmp_write(tmp,filename,stdout,100);
}
#endif
    bmp_free(tmp);
    /* Copy region's hyphen info */
    wrapbmp->hyphen = region->bbox.hyphen;
    if (wrapbmp_ends_in_hyphen(wrapbmp))
        {
        wrapbmp->hyphen.r1 += (new_base-region->bbox.rowbase);
        wrapbmp->hyphen.r2 += (new_base-region->bbox.rowbase);
        if (k2settings->src_left_to_right)
            {
            wrapbmp->hyphen.ch += width0+colgap-region->c1;
            wrapbmp->hyphen.c2 += width0+colgap-region->c1;
            }
        else
            {
            wrapbmp->hyphen.ch -= region->c1;
            wrapbmp->hyphen.c2 -= region->c1;
            }
        }
    wrapbmp->base=new_base;
    /* Doesn't seem to work?  v2.00 */
    /*
    wrapbmp->textrow.gap = (wrapbmp->bmp.height-1)-new_base;
    wrapbmp->textrow.gapblank = 0;
    */
#ifdef WILLUSDEBUG
if (wrapbmp->bmp.height<=wrapbmp->base)
{
k2printf("2. SCREEECH!\n");
k2printf("wrapbmp = %d x %d, base=%d\n",wrapbmp->bmp.width,wrapbmp->bmp.height,wrapbmp->base);
exit(10);
}
#endif
    }
Пример #10
0
// static int bcount=0;
void wrapbmp_add(WRAPBMP *wrapbmp,BMPREGION *region,K2PDFOPT_SETTINGS *k2settings,
                 int gap,int line_spacing,int rbase,int gio,int just_flags)

    {
    WILLUSBITMAP *tmp,_tmp;
    int i,rh,th,bw,new_base,h2,bpp,width0;
// static char filename[256];

#ifdef WILLUSDEBUG
printf("@wrapbmp->add %d x %d (w=%d).\n",region->c2-region->c1+1,region->r2-region->r1+1,wrapbmp->bmp.width);
#endif
    /* Figure out if what we're adding ends in a hyphen */
    bmpregion_hyphen_detect(region,k2settings->hyphen_detect,k2settings->src_left_to_right);
    if (wrapbmp_ends_in_hyphen(wrapbmp))
        gap=0;
    wrapbmp_hyphen_erase(wrapbmp,k2settings);
    wrapbmp->just_flushed_internal=0;  // Reset "just flushed" flag
    wrapbmp->beginning_gap_internal = -1; // Reset top-of-page or top-of-column gap
    wrapbmp->last_h5050_internal = -1; // Reset last row font size
    if (line_spacing > wrapbmp->line_spacing)
        wrapbmp->line_spacing = line_spacing;
    if (gio > wrapbmp->gap)
        wrapbmp->gap = gio;
    wrapbmp->bgcolor=region->bgcolor;
    wrapbmp->just=just_flags;
/*
printf("    c1=%d, c2=%d, r1=%d, r2=%d\n",region->c1,region->c2,region->r1,region->r2);
printf("    gap=%d, line_spacing=%d, rbase=%d, gio=%d\n",gap,line_spacing,rbase,gio);
*/
    bpp=k2settings->dst_color?3:1;
    rh=rbase-region->r1+1;
    if (rh > wrapbmp->rhmax)
        wrapbmp->rhmax=rh;
    th = rh + (region->r2-rbase);
    if (th > wrapbmp->thmax)
        wrapbmp->thmax=th;
/*
{
WILLUSBITMAP *bmp,_bmp;

bmp=&_bmp;
bmp_init(bmp);
bmp->height=region->r2-region->r1+1;
bmp->width=region->c2-region->c1+1;
bmp->bpp=bpp*8;
if (bpp==1)
for (i=0;i<256;i++)
bmp->red[i]=bmp->blue[i]=bmp->green[i]=i;
bmp_alloc(&wrapbmp->bmp);
bw=bmp_bytewidth(&wrapbmp->bmp);
memset(bmp_rowptr_from_top(bmp,0),255,bw*bmp->height);
for (i=region->r1;i<=region->r2;i++)
{
unsigned char *d,*s;
d=bmp_rowptr_from_top(bmp,i-region->r1);
s=bmp_rowptr_from_top(k2settings->dst_color?region->bmp:region->bmp8,i)+bpp*region->c1;
if (i==rbase)
memset(d,0,bw);
else
memcpy(d,s,bw);
}
sprintf(filename,"out%05d.png",bcount++);
bmp_write(bmp,filename,stdout,100);
bmp_free(bmp);
}
*/
    if (wrapbmp->bmp.width==0)
        {
        /* Put appropriate gap in */
        if (k2settings->last_rowbase_internal>=0 && rh < wrapbmp->line_spacing-k2settings->last_rowbase_internal)
            {
            rh = wrapbmp->line_spacing - k2settings->last_rowbase_internal;
            if (rh<2)
                rh=2;
            th = rh + (region->r2-rbase);
            wrapbmp->height_extended=0;
            }
        else
            wrapbmp->height_extended=(k2settings->last_rowbase_internal>=0);
        wrapbmp->base = rh-1;
        wrapbmp->bmp.height = th;
#ifdef WILLUSDEBUG
printf("@wrapbmp->add:  bmpheight set to %d (wls=%d, lrbi=%d)\n",wrapbmp->bmp.height,wrapbmp->line_spacing,k2settings->last_rowbase_internal);
#endif
        wrapbmp->bmp.width=region->c2-region->c1+1;
        bmp_alloc(&wrapbmp->bmp);
        bw=bmp_bytewidth(&wrapbmp->bmp);
        memset(bmp_rowptr_from_top(&wrapbmp->bmp,0),255,bw*wrapbmp->bmp.height);
        for (i=region->r1;i<=region->r2;i++)
            {
            unsigned char *d,*s;
            d=bmp_rowptr_from_top(&wrapbmp->bmp,wrapbmp->base+(i-rbase));
            s=bmp_rowptr_from_top(k2settings->dst_color?region->bmp:region->bmp8,i)+bpp*region->c1;
            memcpy(d,s,bw);
            }
#ifdef WILLUSDEBUG
if (wrapbmp->bmp.height<=wrapbmp->base)
{
printf("1. SCREEECH!\n");
printf("wrapbmp = %d x %d, base=%d\n",wrapbmp->bmp.width,wrapbmp->bmp.height,wrapbmp->base);
exit(10);
}
#endif
        /* Copy hyphen info from added region */
        wrapbmp->hyphen = region->hyphen;
        if (wrapbmp_ends_in_hyphen(wrapbmp))
            {
            wrapbmp->hyphen.r1 += (wrapbmp->base-rbase);
            wrapbmp->hyphen.r2 += (wrapbmp->base-rbase);
            wrapbmp->hyphen.ch -= region->c1;
            wrapbmp->hyphen.c2 -= region->c1;
            }
        return;
        }
    width0=wrapbmp->bmp.width; /* Starting wrapbmp width */
    tmp=&_tmp;
    bmp_init(tmp);
    bmp_copy(tmp,&wrapbmp->bmp);
    tmp->width += gap+region->c2-region->c1+1;
    if (rh > wrapbmp->base)
        {
        wrapbmp->height_extended=1;
        new_base = rh-1;
        }
    else
        new_base = wrapbmp->base;
    if (region->r2-rbase > wrapbmp->bmp.height-1-wrapbmp->base)
        h2=region->r2-rbase;
    else
        h2=wrapbmp->bmp.height-1-wrapbmp->base;
    tmp->height = new_base + h2 + 1;
    bmp_alloc(tmp);
    bw=bmp_bytewidth(tmp);
    memset(bmp_rowptr_from_top(tmp,0),255,bw*tmp->height);
    bw=bmp_bytewidth(&wrapbmp->bmp);
/*
printf("3.  wbh=%d x %d, tmp=%d x %d x %d, new_base=%d, wbbase=%d\n",wrapbmp->bmp.width,wrapbmp->bmp.height,tmp->width,tmp->height,tmp->bpp,new_base,wrapbmp->base);
*/
    for (i=0;i<wrapbmp->bmp.height;i++)
        {
        unsigned char *d,*s;
        d=bmp_rowptr_from_top(tmp,i+new_base-wrapbmp->base)
                 + (k2settings->src_left_to_right ? 0 : tmp->width-1-wrapbmp->bmp.width)*bpp;
        s=bmp_rowptr_from_top(&wrapbmp->bmp,i);
        memcpy(d,s,bw);
        }
    bw=bpp*(region->c2-region->c1+1);
    if (region->r1+new_base-rbase<0 || region->r2+new_base-rbase>tmp->height-1)
        {
        aprintf(ANSI_YELLOW "INTERNAL ERROR--TMP NOT DIMENSIONED PROPERLY.\n");
        aprintf("(%d-%d), tmp->height=%d\n" ANSI_NORMAL,
            region->r1+new_base-rbase,
            region->r2+new_base-rbase,tmp->height);
        exit(10);
        }
    for (i=region->r1;i<=region->r2;i++)
        {
        unsigned char *d,*s;

        d=bmp_rowptr_from_top(tmp,i+new_base-rbase)
                 + (k2settings->src_left_to_right ? wrapbmp->bmp.width+gap : 0)*bpp;
        s=bmp_rowptr_from_top(k2settings->dst_color?region->bmp:region->bmp8,i)+bpp*region->c1;
        memcpy(d,s,bw);
        }
    bmp_copy(&wrapbmp->bmp,tmp);
    bmp_free(tmp);
    /* Copy region's hyphen info */
    wrapbmp->hyphen = region->hyphen;
    if (wrapbmp_ends_in_hyphen(wrapbmp))
        {
        wrapbmp->hyphen.r1 += (new_base-rbase);
        wrapbmp->hyphen.r2 += (new_base-rbase);
        if (k2settings->src_left_to_right)
            {
            wrapbmp->hyphen.ch += width0+gap-region->c1;
            wrapbmp->hyphen.c2 += width0+gap-region->c1;
            }
        else
            {
            wrapbmp->hyphen.ch -= region->c1;
            wrapbmp->hyphen.c2 -= region->c1;
            }
        }
    wrapbmp->base=new_base;
#ifdef WILLUSDEBUG
if (wrapbmp->bmp.height<=wrapbmp->base)
{
printf("2. SCREEECH!\n");
printf("wrapbmp = %d x %d, base=%d\n",wrapbmp->bmp.width,wrapbmp->bmp.height,wrapbmp->base);
exit(10);
}
#endif
    }
Пример #11
0
void bmp_adjust_contrast(WILLUSBITMAP *src,WILLUSBITMAP *srcgrey,
                         K2PDFOPT_SETTINGS *k2settings,int *white)

    {
    int i,j,tries,wc,tc,hist[256];
    double contrast,rat0;
    WILLUSBITMAP *dst,_dst;

    if (k2settings->debug && k2settings->verbose)
        k2printf("\nAt adjust_contrast.\n");
    if ((*white) <= 0)
        (*white)=192;
    /* If contrast_max negative, use it as fixed contrast adjustment. */
    if (k2settings->contrast_max < 0.)
        {
        bmp_contrast_adjust(srcgrey,srcgrey,-k2settings->contrast_max);
        if (k2settings->dst_color && fabs(k2settings->contrast_max+1.0)>1e-4)
            bmp_contrast_adjust(src,src,-k2settings->contrast_max);
        return;
        }
    dst=&_dst;
    bmp_init(dst);
    wc=0; /* Avoid compiler warning */
    tc=srcgrey->width*srcgrey->height;
    rat0=0.5; /* Avoid compiler warning */
    for (contrast=1.0,tries=0;contrast<k2settings->contrast_max+.01;tries++)
        {
        if (fabs(contrast-1.0)>1e-4)
            bmp_contrast_adjust(dst,srcgrey,contrast);
        else
            bmp_copy(dst,srcgrey);
        /*Get bitmap histogram */
        for (i=0;i<256;i++)
            hist[i]=0;
        for (j=0;j<dst->height;j++)
            {
            unsigned char *p;
            p=bmp_rowptr_from_top(dst,j);
            for (i=0;i<dst->width;i++,p++)
                hist[p[0]]++;
            }
        if (tries==0)
            {
            int h1;
            for (h1=0,j=(*white);j<256;j++)
                h1+=hist[j];
            rat0=(double)h1/tc;
            if (k2settings->debug && k2settings->verbose)
                k2printf("    rat0 = rat[%d-255]=%.4f\n",(*white),rat0);
            }
        
        /* Find white ratio */
        /*
        for (wc=hist[254],j=253;j>=252;j--)
            if (hist[j]>wc1)
                wc1=hist[j];
        */
        for (wc=0,j=252;j<=255;j++)
            wc += hist[j];
        /*
        if ((double)wc/tc >= rat0*0.7 && (double)hist[255]/wc > 0.995)
            break;
        */
        if (k2settings->debug && k2settings->verbose)
            k2printf("    %2d. Contrast=%7.2f, rat[252-255]/rat0=%.4f\n",
                        tries+1,contrast,(double)wc/tc/rat0);
        if ((double)wc/tc >= rat0*0.94)
            break;
        contrast *= 1.05;
        }
    if (k2settings->debug)
        k2printf("Contrast=%7.2f, rat[252-255]/rat0=%.4f\n",
                       contrast,(double)wc/tc/rat0);
/*
bmp_write(dst,"outc.png",stdout,100);
wfile_written_info("outc.png",stdout);
exit(10);
*/
    bmp_copy(srcgrey,dst);
    /* Maybe don't adjust the contrast for the color bitmap? */
    if (k2settings->dst_color && fabs(contrast-1.0)>1e-4)
        bmp_contrast_adjust(src,src,contrast);
    bmp_free(dst);
    }
Пример #12
0
/*
** bmp must be grayscale! (cbmp might be color, might be grayscale, can be null)
** Handles cbmp either 8-bit or 24-bit in v2.10.
*/
void bmp_detect_vertical_lines(WILLUSBITMAP *bmp,WILLUSBITMAP *cbmp,
                               double dpi,/* double minwidth_in, */
                               double maxwidth_in,double minheight_in,double anglemax_deg,
                               int white_thresh,int erase_vertical_lines,int debug,int verbose)

    {
    int tc,iangle,irow,icol;
    int rowstep,na,angle_sign,ccthresh;
    int halfwidth,bytewidth;
    int bs1,nrsteps;
    double anglestep;
    WILLUSBITMAP *tmp,_tmp;
    unsigned char *p0;
    unsigned char *t0;

    if (debug)
        k2printf("At bmp_detect_vertical_lines...\n");
    if (!bmp_is_grayscale(bmp))
        {
        k2printf("Internal error.  bmp_detect_vertical_lines passed a non-grayscale bitmap.\n");
        exit(10);
        }
    tmp=&_tmp;
    bmp_init(tmp);
    bmp_copy(tmp,bmp);
    p0=bmp_rowptr_from_top(bmp,0);
    t0=bmp_rowptr_from_top(tmp,0);
    bytewidth=bmp_bytewidth(bmp);
    /*
    pixmin = (int)(minwidth_in*dpi+.5);
    if (pixmin<1)
        pixmin=1;
    halfwidth=pixmin/4;
    if (halfwidth<1)
        halfwidth=1; 
    */
    halfwidth=1;
    anglestep=atan2((double)halfwidth/dpi,minheight_in);
    na=(int)((anglemax_deg*PI/180.)/anglestep+.5);
    if (na<1)
        na=1;
    rowstep=(int)(dpi/40.+.5);
    if (rowstep<2)
        rowstep=2;
    nrsteps=bmp->height/rowstep;
    bs1=bytewidth*rowstep;
    ccthresh=(int)(minheight_in*dpi/rowstep+.5);
    if (ccthresh<2)
        ccthresh=2;
    if (debug && verbose)
        k2printf("    na = %d, rowstep = %d, ccthresh = %d, white_thresh = %d, nrsteps=%d\n",na,rowstep,ccthresh,white_thresh,nrsteps);
/*
bmp_write(bmp,"out.png",stdout,97);
wfile_written_info("out.png",stdout);
*/
    for (tc=0;tc<100;tc++)
        {
        int ccmax,ic0max,ir0max;
        double tanthmax;

        ccmax=-1;
        ic0max=ir0max=0;
        tanthmax=0.;
        for (iangle=0;iangle<=na;iangle++)
            {
            for (angle_sign=1;angle_sign>=-1;angle_sign-=2)
                {
                double th,tanth,tanthx;
                int ic1,ic2;

                if (iangle==0 && angle_sign==-1)
                    continue;
                th=(PI/180.)*iangle*angle_sign*fabs(anglemax_deg)/na;
                tanth=tan(th);
                tanthx=tanth*rowstep;
                if (angle_sign==1)
                    {
                    ic1=-(int)(bmp->height*tanth+1.);
                    ic2=bmp->width-1;
                    }
                else
                    {
                    ic1=(int)(-bmp->height*tanth+1.);
                    ic2=bmp->width-1+(int)(-bmp->height*tanth+1.);
                    }
// k2printf("iangle=%2d, angle_sign=%2d, ic1=%4d, ic2=%4d\n",iangle,angle_sign,ic1,ic2);
                for (icol=ic1;icol<=ic2;icol++)
                    {
                    unsigned char *p,*t;
                    int cc,ic0,ir0;
                    p=p0;
                    t=t0;
                    if (icol<0 || icol>bmp->width-1)
                        for (irow=0;irow<nrsteps;irow++,p+=bs1,t+=bs1)
                            {
                            int ic;
                            ic=icol+irow*tanthx;
                            if (ic>=0 && ic<bmp->width)
                                break;
                            }
                    else
                        irow=0;
                    for (ir0=ic0=cc=0;irow<nrsteps;irow++,p+=bs1,t+=bs1)
                        {
                        int ic;
                        ic=icol+irow*tanthx;
                        if (ic<0 || ic>=bmp->width)
                            break;
                        if ((p[ic]<white_thresh || p[ic+bytewidth]<white_thresh)
                            && (t[ic]<white_thresh || t[ic+bytewidth]<white_thresh))
                            {
                            if (cc==0)
                                {
                                ic0=ic;
                                ir0=irow*rowstep;
                                }
                            cc++;
                            if (cc>ccmax)
                                {
                                ccmax=cc;
                                tanthmax=tanth;
                                ic0max=ic0;
                                ir0max=ir0;
                                }
                            }
                        else
                            cc=0;
                        }
                    }
                }
            }
        if (ccmax<ccthresh)
            break;
        if (debug)
            k2printf("    Vert line detected:  ccmax=%d (pix=%d), tanthmax=%g, ic0max=%d, ir0max=%d\n",ccmax,ccmax*rowstep,tanthmax,ic0max,ir0max);
        if (!vert_line_erase(bmp,cbmp,tmp,ir0max,ic0max,tanthmax,minheight_in,
                             /*minwidth_in,*/ maxwidth_in,white_thresh,dpi,erase_vertical_lines))
            break;
        }
/*
bmp_write(tmp,"outt.png",stdout,95);
wfile_written_info("outt.png",stdout);
bmp_write(bmp,"out2.png",stdout,95);
wfile_written_info("out2.png",stdout);
exit(10);
*/
    /* v2.20--fix memory leak here */
    bmp_free(tmp);
    }
Пример #13
0
void masterinfo_publish(MASTERINFO *masterinfo,K2PDFOPT_SETTINGS *k2settings,int flushall)

    {
#ifdef HAVE_MUPDF_LIB
    static WTEXTCHARS *wtcs=NULL;
    static WTEXTCHARS _wtcs;
    /* static int pageno=0; */
#endif
    WILLUSBITMAP _bmp,*bmp;
    double bmpdpi;
    int output_page_count,size_reduction;
#ifdef HAVE_OCR_LIB
    OCRWORDS *ocrwords,_ocrwords;
#else
    void *ocrwords;
#endif

/*
aprintf(ANSI_GREEN "\n   @masterinfo_publish(flushall=%d)....\n\n" ANSI_NORMAL,flushall);
*/
#ifdef HAVE_MUPDF_LIB
    if (wtcs==NULL)
        {
        wtcs=&_wtcs;
        wtextchars_init(wtcs);
        }
#endif
#ifdef HAVE_OCR_LIB
    if (k2settings->dst_ocr)
        {
        ocrwords=&_ocrwords;
        ocrwords_init(ocrwords);
        }
    else
#endif
        ocrwords=NULL;
    bmp=&_bmp;
    bmp_init(bmp);
    output_page_count=0;
    while (masterinfo_get_next_output_page(masterinfo,k2settings,flushall,bmp,
                                           &bmpdpi,&size_reduction,ocrwords)>0)
        {
/*
aprintf(ANSI_GREEN "\n   SRC PAGE %d\n\n" ANSI_NORMAL,masterinfo->pageinfo.srcpage);
*/
        output_page_count++;
        if (masterinfo->preview_bitmap!=NULL)
            {
            if (ocrwords!=NULL)
                ocrwords_free(ocrwords); /* Don't really need this, but just for insurance */
            if (!k2settings->show_marked_source
                        && abs(k2settings->preview_page)==masterinfo->published_pages)
                {
/*
printf("At preview page:  bmp = %d x %d x %d, preview(dst) = %d x %d x %d\n",
bmp->width,bmp->height,bmp->bpp,
masterinfo->preview_bitmap->width,masterinfo->preview_bitmap->height,masterinfo->preview_bitmap->bpp);
*/              bmp_copy(masterinfo->preview_bitmap,bmp);
                masterinfo->preview_captured=1;
                break;
                }
            continue;
            }

        /* v2.16, outline / bookmark check done in separate function. */
        k2publish_outline_check(masterinfo,k2settings,0);
/*
printf("use_toc=%d, outline=%p, spc=%d, srcpage=%d\n",k2settings->use_toc,masterinfo->outline,masterinfo->outline_srcpage_completed,masterinfo->pageinfo.srcpage);
*/

        /*
        ** Nothing to do inside loop if using crop boxes -- they all
        ** get written after all pages have been processed.
        */
        if (k2settings->use_crop_boxes)
            continue;
#ifdef HAVE_OCR_LIB
        if (k2settings->dst_ocr)
            {
            int flags_extra;

            flags_extra=0;
            if (k2settings->dst_ocr=='m')
                {
                flags_extra=0x20;
                /* Don't re-sort--messes up the copy/paste flow */
                /*
                if (masterinfo->ocrfilename[0]=='\0')
                    ocrwords_sort_by_pageno(ocrwords);
                */
/*
** This section no longer needed in v2.20.  The text in the ocrword boxes
** has already been determined by k2ocr_ocrwords_get_from_ocrlayer() in k2ocr.c
*/
/*
                for (i=0;i<ocrwords->n;i++)
                    {
                    static char *funcname="masterinfo_publish";

                    if (ocrwords->word[i].pageno != pageno)
                        {
                        wtextchars_clear(wtcs);
                        wtextchars_fill_from_page(wtcs,masterinfo->srcfilename,
                                                  ocrwords->word[i].pageno,"");
                        wtextchars_rotate_clockwise(wtcs,360-(int)ocrwords->word[i].rot0_deg);
                        pageno=ocrwords->word[i].pageno;
                        }
                    willus_mem_free((double **)&ocrwords->word[i].text,funcname);
                    wtextchars_text_inside(wtcs,&ocrwords->word[i].text,
                                           ocrwords->word[i].x0,
                                           ocrwords->word[i].y0,
                                           ocrwords->word[i].x0+ocrwords->word[i].w0,
                                           ocrwords->word[i].y0+ocrwords->word[i].h0);
#if (WILLUSDEBUGX & 0x400)
printf("MuPDF Word (%5.1f,%5.1f) - (%5.1f,%5.1f) = '%s'\n",
ocrwords->word[i].x0,
ocrwords->word[i].y0,
ocrwords->word[i].x0+ocrwords->word[i].w0,
ocrwords->word[i].y0+ocrwords->word[i].h0,
ocrwords->word[i].text);
#endif
                    if (ocrwords->word[i].text==NULL || ocrwords->word[i].text[0]=='\0')
                        {
                        ocrwords_remove_words(ocrwords,i,i);
                        i--;
                        }
                    }
*/
                
                }
            if (masterinfo->ocrfilename[0]!='\0')
                ocrwords_to_textfile(ocrwords,masterinfo->ocrfilename,
                                     masterinfo->published_pages>1);

#if (WILLUSDEBUGX & 0x400)
printf("Calling pdffile_add_bitmap_with_ocrwords.\n");
#endif
#if (WILLUSDEBUGX & 0x10000)
if (ocrwords!=NULL)
{
int k;
printf("flags_extra= %d\n",flags_extra);
printf("PAGE OF WORDS\n");
for (k=0;k<ocrwords->n;k++)
printf("%3d. '%s'\n",k,ocrwords->word[k].text);
}
#endif
            pdffile_add_bitmap_with_ocrwords(&masterinfo->outfile,bmp,bmpdpi,
                                             k2settings->jpeg_quality,size_reduction,
                                             ocrwords,k2settings->dst_ocr_visibility_flags
                                                        | flags_extra);
#if (WILLUSDEBUGX & 0x400)
printf("Back from pdffile_add_bitmap_with_ocrwords.\n");
#endif
/*
{
static int count=1;
char filename[MAXFILENAMELEN];
sprintf(filename,"page%04d.png",count++);
bmp_write(bmp,filename,stdout,100);
}
*/
            masterinfo->wordcount += ocrwords->n;
            ocrwords_free(ocrwords);
            }
        else
#endif
            pdffile_add_bitmap(&masterinfo->outfile,bmp,bmpdpi,
                               k2settings->jpeg_quality,size_reduction);
        }
    /*
    ** v2.16 bug fix:  If no destination output generated, we still have to call outline_check().
    */
    if (output_page_count==0)
        k2publish_outline_check(masterinfo,k2settings,1);
    bmp_free(bmp);
    }