Пример #1
0
int FastZoom(FZOOM_DATA *data)
{
  FZOOM_DATA fzdata ;
  MFDB       std_src, std_dst ;
  MFDB       *pstd_src, *pstd_dst ;
  int        use_std_vdi = NeedStdVDI(data->src->fd_nplanes) ;

  if ( use_std_vdi )
  {
    if ( data->std_src )
    {
      std_src.fd_addr = NULL ;
      pstd_src        = data->std_src ;
    }
    else
    {
      memcpy( &std_src, data->src, sizeof(MFDB) ) ;
      std_src.fd_addr  = img_alloc( std_src.fd_w, std_src.fd_h, std_src.fd_nplanes ) ;
      if ( std_src.fd_addr == NULL ) return( -3 ) ;
      std_src.fd_stand = 1 ;
      pstd_src         = &std_src ;
    }
    if ( data->std_dst )
    {
      std_dst.fd_addr = NULL ;
      pstd_dst        = data->std_dst ;
    }
    else
    {
      memcpy( &std_dst, data->dst, sizeof(MFDB) ) ;
      std_dst.fd_addr  = img_alloc( std_dst.fd_w, std_dst.fd_h, std_dst.fd_nplanes ) ;
      if ( std_dst.fd_addr == NULL )
      {
        if ( std_src.fd_addr ) free( std_src.fd_addr ) ;
        return( -3 ) ;
      }
      std_dst.fd_stand = 1 ;
      pstd_dst         = &std_dst ;
    }
    vr_trnfm( handle, data->src, pstd_src ) ;
    StdVDI2ClassicAtari( pstd_src, data->src ) ;
    memcpy( &fzdata, data, sizeof(FZOOM_DATA) ) ;
    fzdata.std_src = pstd_src ;
    fzdata.std_dst = pstd_dst ;
  }
  else memcpy( &fzdata, data, sizeof(FZOOM_DATA) ) ;

  fast_zoom( &fzdata ) ;

  if ( use_std_vdi )
  {
    ClassicAtari2StdVDI( fzdata.dst, pstd_dst ) ;
    vr_trnfm( handle, pstd_dst, fzdata.dst ) ;
    vr_trnfm( handle, pstd_src, data->src ) ;
    if ( std_dst.fd_addr ) free( std_dst.fd_addr ) ;
    if ( std_src.fd_addr ) free( std_src.fd_addr ) ;
  }

  return( 0 ) ;
}
Пример #2
0
/* jpeg_load_img:
 * Read a JPEG file into an image. */
int jpeg_load_img(img I) {
    struct jpeg_decompress_struct *cinfo = I->us;
    struct my_error_mgr *jerr;
    JSAMPARRAY buffer;
    img_alloc(I);
    jerr = (struct my_error_mgr*)cinfo->err;
    if (setjmp(jerr->jb)) {
        /* Oops, something went wrong. */
        I->err = IE_IMGFORMAT;
        jpeg_destroy_decompress(cinfo);
        return 0;
    }

    cinfo->out_color_space = JCS_RGB;
    cinfo->out_color_components = cinfo->output_components = 3;

    /* Start decompression. */
    buffer = cinfo->mem->alloc_sarray((j_common_ptr)cinfo, JPOOL_IMAGE, cinfo->output_width * cinfo->output_components, 1);

    while (cinfo->output_scanline < cinfo->output_height) {
        pel *p, *end;
        unsigned char *q;
        jpeg_read_scanlines(cinfo, buffer, 1);

        /* Now we have a buffer in RGB format. */
        for (p = I->data[cinfo->output_scanline - 1], end = p + I->width, q = (unsigned char*)buffer[0]; p < end; ++p, q += 3)
            *p = PEL(*q, *(q + 1), *(q + 2));
    }

    jpeg_finish_decompress(cinfo);
    jpeg_destroy_decompress(cinfo);

    return 1;
}
Пример #3
0
IMAGE *img_creat(char *name, int nr, int nc)
{
  int i, j;
  IMAGE *newptr;

  newptr = img_alloc();
  newptr->data = (int *) malloc ((unsigned) (nr * nc * sizeof(int)));
  newptr->name = img_basename(name);
  newptr->rows = nr;
  newptr->cols = nc;
  for (i = 0; i < nr; i++) {
    for (j = 0; j < nc; j++) {
      img_setpixel(newptr, i, j, 0);
    }
  }
  return (newptr);
}
Пример #4
0
int mac_load(char *name, MFDB *out, GEM_WINDOW *wprog)
{
  FILE   *stream ;
  size_t taille ;
  void   *in ;

  perf_start( PERF_DISK, &PerfInfo ) ;
  stream = fopen(name, "rb") ;
  if (stream == NULL) return(-1) ;
  
  fseek(stream, 0x280, SEEK_SET) ;
  out->fd_nplanes = 1 ;
  out->fd_w       = 576 ; 
  out->fd_h       = 720 ;
  out->fd_stand   = 0 ;
  out->fd_wdwidth = out->fd_w/16 ;
  out->fd_addr    = img_alloc(576, 720, 1) ;
  if (out->fd_addr == NULL)
  {
    fclose(stream) ;
    return(-3) ;
  }

  taille = file_size(name)-sizeof(MACPAINT_HEADER) ;
  in     = malloc(taille) ;
  if (in == NULL)
  {
    fclose(stream) ;
    free(out->fd_addr) ;
    return(-3) ;
  }
  fread(in, taille, 1, stream) ;
  fclose(stream) ;
  perf_stop( PERF_DISK, &PerfInfo ) ;

  perf_start( PERF_COMPRESS, &PerfInfo ) ;
  packbits_dcmps(in, out->fd_addr, out->fd_w, out->fd_h, out->fd_nplanes) ;
  perf_stop( PERF_COMPRESS, &PerfInfo ) ;

  free(in) ;

  return(0) ;
}
Пример #5
0
/* make_backing_image:
 * Create the img structure which represents our back-buffer. */
void make_backing_image() {
    img I;
    I = img_new_blank(width, height);
    img_alloc(I);
/*    wry += height - backing_image->height;
    if (wry < BORDER || wry > height - BORDER)
        wry = height - BORDER;*/
    if (backing_image) {
        int w2, h2;
        struct imgrect *ir;

        /* Copy old contents of backing image to ll corner of new one. */
        w2 = backing_image->width;
        if (w2 > width) w2 = width;
        h2 = backing_image->height;
        if (h2 > height) h2 = height;

        img_simple_blt(I, 0, height - h2, backing_image, 0, backing_image->height - h2, w2, h2);

        /* Move all of the image rectangles. */
        for (ir = imgrects; ir < imgrects + nimgrects; ++ir) {
            if (ir->filename) {
                ir->y += height - backing_image->height;

                /* Possible it has scrolled off the window. */
                if (ir->x > width || ir->y + ir->h < 0) {
                    unlink(ir->filename);
                    xfree(ir->filename);
                    memset(ir, 0, sizeof *ir);
                }
            }
        }

        /* Adjust placement of new images. */
        if (wrx >= w2) wrx = w2;
        
        img_delete(backing_image);
    }
    backing_image = I;
    wrx = BORDER;
    wry = height - BORDER;
    rowheight = 2 * BORDER;
}
Пример #6
0
IMAGE *img_open(char *filename)
{
  IMAGE *newptr;
  FILE *pgm;
  char line[512], intbuf[100], ch;
  int type, nc, nr, maxval, i, j, k, found;

  newptr = img_alloc();
  if ((pgm = fopen(filename, "r")) == NULL) {
    printf("IMGOPEN: Couldn't open '%s'\n", filename);
    return(NULL);
  }

  newptr->name = img_basename(filename);

  /*** Scan pnm type information, expecting P5 ***/
  fgets(line, 511, pgm);
  sscanf(line, "P%d", &type);
  if (type != 5 && type != 2) {
    printf("IMGOPEN: Only handles pgm files (type P5 or P2)\n");
    fclose(pgm);
    return(NULL);
  }

  /*** Get dimensions of pgm ***/
  fgets(line, 511, pgm);
  sscanf(line, "%d %d", &nc, &nr);
  newptr->rows = nr;
  newptr->cols = nc;

  /*** Get maxval ***/
  fgets(line, 511, pgm);
  sscanf(line, "%d", &maxval);
  if (maxval > 255) {
    printf("IMGOPEN: Only handles pgm files of 8 bits or less\n");
    fclose(pgm);
    return(NULL);
  }

  newptr->data = (int *) malloc ((unsigned) (nr * nc * sizeof(int)));
  if (newptr->data == NULL) {
    printf("IMGOPEN: Couldn't allocate space for image data\n");
    fclose(pgm);
    return(NULL);
  }

  if (type == 5) {

    for (i = 0; i < nr; i++) {
      for (j = 0; j < nc; j++) {
        img_setpixel(newptr, i, j, fgetc(pgm));
      }
    }

  } else if (type == 2) {

    for (i = 0; i < nr; i++) {
      for (j = 0; j < nc; j++) {

        k = 0;  found = 0;
        while (!found) {
          ch = (char) fgetc(pgm);
          if (ch >= '0' && ch <= '9') {
            intbuf[k] = ch;  k++;
  	  } else {
            if (k != 0) {
              intbuf[k] = '\0';
              found = 1;
	    }
	  }
	}
        img_setpixel(newptr, i, j, atoi(intbuf));

      }
    }

  } else {
    printf("IMGOPEN: Fatal impossible error\n");
    fclose(pgm);
    return (NULL);
  }

  fclose(pgm);
  return (newptr);
}
Пример #7
0
int_m bmp_read(const char *file_name, image_buffer *result)
{
	FILE *file = fopen(file_name, "rb");

	if (file == NULL)
	{
		fprintf(stderr, "error opening file: %s\n", file_name);
		return 0;
	}

	bitmap_header bmp;
	if (fread(&bmp, 1, sizeof(bmp), file) != sizeof(bmp))
	{
		fprintf(stderr, "%s\n", "error reading header of bitmap.");
		fclose(file);
		return 0;
	}

	if (bmp.fileheader.filetype[0] != 'B' ||
		bmp.fileheader.filetype[1] != 'M' ||
		bmp.headersize != sizeof(bitmap_header) - sizeof(file_header) ||
		bmp.planes != 1 ||
		bmp.bitsperpixel != 24 ||
		bmp.compression != 0)
	{
		fprintf(stderr, "%s\n", "error reading bitmap. invalid header.");
		fclose(file);
		return 0;
	}

	if (!img_alloc(bmp.width, bmp.height, result))
	{
		fprintf(stderr, "%s\n", "error reading bitmap, cannot allocate image.");
		fclose(file);
		return 0;
	}

	uint_m buffer_size = 3 * result->width * result->height;
	if (fread(result->pixels, 1, buffer_size, file) != buffer_size)
	{
		fprintf(stderr, "%s\n", "error reading bitmap, cannot read full buffer.");
		img_dealloc(result);
		fclose(file);
		return 0;
	}

	uint_m scanline_length = result->width * 3;

	for (uint32_t i = 0; i < result->height; ++i)
	{
		uint8_t *scanline = (uint8_t *)&result->pixels[i * result->width];
		for (uint32_t j = 0; j < scanline_length;)
		{
			uint8_t temp = scanline[j];
			scanline[j] = scanline[j + 2];
			scanline[j + 2] = temp;
			j += 3;
		}
	}

	fclose(file);
	return 1;
}
Пример #8
0
int png_load_img(img I) {
    unsigned char **p, **q;
    png_structp png_ptr;
    png_infop info_ptr;
    png_uint_32 width, height;
    int i, j, bit_depth, color_type, interlace_type;
    png_bytepp row_pointers;

    img_alloc(I);

    png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
        NULL, png_catch_error, NULL);

    if (png_ptr == NULL) {
        I->err = IE_HDRFORMAT;
        return 0;
    }
    
    if (setjmp(png_jmpbuf(png_ptr))) {
       png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
       I->err = IE_HDRFORMAT;
       return 0;
    }

    info_ptr = png_create_info_struct(png_ptr);

    if (info_ptr == NULL) {
        png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
        I->err = IE_HDRFORMAT;
        return 0;
    }

    rewind(I->fp);
    png_init_io(png_ptr, I->fp);

    png_read_info(png_ptr, info_ptr);

    /* Get image specific data */
    png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
        &interlace_type, NULL, NULL);

    /* Convert greyscale images to 8-bit RGB */
    if (color_type == PNG_COLOR_TYPE_GRAY ||
        color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
        if (bit_depth < 8) {
            png_set_expand_gray_1_2_4_to_8(png_ptr);
        }
        png_set_gray_to_rgb(png_ptr);
    }

    /* Change paletted images to RGB */
    if (color_type == PNG_COLOR_TYPE_PALETTE)
        png_set_expand(png_ptr);

    if (bit_depth < 8)
        png_set_expand(png_ptr);

    if (bit_depth == 16)
        png_set_strip_16(png_ptr);

    /* The gdk img widget appears to expect 8-bit RGB followed by a
     * filler byte. */
    png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);

    /* Update the info structure after the transforms */
    png_read_update_info(png_ptr, info_ptr);
/*    png_set_rows(png_ptr, info_ptr, row_pointers)*/

    /* Allocate space before reading the image */
    row_pointers = png_malloc(png_ptr, height * sizeof(png_bytep));
    for (i = 0; i < height; i++) {
        row_pointers[i] = png_malloc(png_ptr, png_get_rowbytes(png_ptr, info_ptr));
    }

    /* Read in the image and copy it to the gdk img structure */
    png_read_image(png_ptr, row_pointers);

    p = (unsigned char **)I->data;
    q = (unsigned char **)row_pointers;

    for (i = 0; i < height; i++) {
        for (j = 0; j < png_get_rowbytes(png_ptr, info_ptr); j++) {
           p[i][j] = q[i][j];
        }
    }

    png_read_end(png_ptr, info_ptr);

    /* Clean up */
    png_free(png_ptr, row_pointers);
    png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);

    return 1;
}
Пример #9
0
/* gif_load_img:
 * Load GIF image.
 */
int gif_load_img(img I) {
    GifFileType *g = I->us;
    struct SavedImage *si;
    int ret = 0;
    unsigned char *p, *end;
    GifColorType *pal;
    pel *q;

    if (DGifSlurp(g) == GIF_ERROR) {
        I->err = IE_IMGFORMAT;
        return 0;
    }

    /* Now allocate memory and copy the image into it. */
    img_alloc(I);

    /* Retrieve only the first image. */
    if (g->ImageCount < 1) {
        I->err = IE_IMGFORMAT;
        goto fail;
    }

    si = g->SavedImages;
    if (si->ImageDesc.Width != I->width || si->ImageDesc.Height != I->height) {
        I->err = IE_IMGFORMAT;
        goto fail;
    }

    if (si->ImageDesc.ColorMap)
        pal = si->ImageDesc.ColorMap->Colors;
    else
        pal = g->SColorMap->Colors;

    if (si->ImageDesc.Interlace) {
        int i;
        unsigned char *gifsrc = si->RasterBits;

        /* Deal with deranged interlaced GIF file. */
#define COPYROW(src, dest)      for (p = (src), q = (dest); p < (src) + I->width; ++p, ++q) \
                                    *q = PELA(pal[*p].Red, pal[*p].Green, pal[*p].Blue, *p == g->SBackGroundColor ? 255 : 0);

        /* Pass 1: every 8th row, starting at row 0. */
        for (i = 0; i < I->height; i += 8) {
            COPYROW(gifsrc, I->data[i]);
            gifsrc += I->width;
        }

        /* Pass 2: every 8th row, starting at row 4. */
        for (i = 4; i < I->height; i += 8) {
            COPYROW(gifsrc, I->data[i]);
            gifsrc += I->width;
        }

        /* Pass 3: every 4th row, starting at row 2. */
        for (i = 2; i < I->height; i += 4) {
            COPYROW(gifsrc, I->data[i]);
            gifsrc += I->width;
        }

        /* Pass 4: every 2nd row, starting at row 1. */
        for (i = 1; i < I->height; i += 2) {
            COPYROW(gifsrc, I->data[i]);
            gifsrc += I->width;
        }
    } else
        for (p = (unsigned char*)si->RasterBits, end = p + I->width * I->height, q = I->flat; p < end; ++p, ++q)
            *q = PELA(pal[*p].Red, pal[*p].Green, pal[*p].Blue, *p == g->SBackGroundColor ? 255 : 0);

    ret = 1;
fail:

    DGifCloseFile(g);

    return ret;
}
Пример #10
0
void clip_put(GEM_WINDOW *gwnd, int x1, int y1, int x2, int y2)
{
  VXIMAGE *vimage ;
  int     xy[8] ;
  int     temp ;
  int     larg ;
  int     w, h ;

  if ( !GWIsWindowValid( gwnd ) ) return ;
  vimage = (VXIMAGE *) gwnd->Extension ;

  if (x2 < x1)
  {
    temp = x1 ;
    x1   = x2 ;
    x2   = temp ;
  }
  if (y2 < y1)
  {
    temp = y1 ;
    y1   = y2 ;
    y2   = temp ;
  }

  FreeClipboard() ;

  w = 1+x2-x1 ; h = 1+y2-y1 ;
  if (w % 16) larg = (16+w) & 0xFFF0 ;
  else        larg = w ;
  if (larg < MINIW) larg = MINIW ;
  if (h < MINIH)       h = MINIH ;
  clipboard.img.fd_addr = img_alloc(larg, h, nb_plane) ;
  if (clipboard.img.fd_addr == NULL)
  {
    form_error(8) ;
    return ;
  }

  clipboard.img.fd_w       = larg ;
  clipboard.img.fd_h       = h ;
  clipboard.img.fd_wdwidth = larg/16 ;
  clipboard.img.fd_nplanes = nb_plane ;
  clipboard.img.fd_stand   = 0 ;
  clipboard.gwindow        = gwnd ;
  clipboard.x              = x1 ;
  clipboard.y              = y1 ;
  clipboard.w              = 1+x2-x1 ;
  clipboard.h              = 1+y2-y1 ;

  img_raz(&clipboard.img) ;
  xy[0] = x1 ;    xy[1] = y1 ;
  xy[2] = x2 ;    xy[3] = y2 ;
  xy[4] = 0 ;     xy[5] = 0 ;
  xy[6] = x2-x1 ; xy[7] = y2-y1 ;
  vro_cpyfm(handle, S_ONLY, xy, &vimage->raster, &clipboard.img) ;

  if ( config.clip_gem == 1 )
  {
    char name[PATH_MAX] ;

    mouse_busy() ;
    if ( clbd_getpath( name ) == 0 )
    {
      INFO_IMAGE info ;
      IMG_MODULE *img_module ;

      memcpy( &info, &vimage->inf_img, sizeof(INFO_IMAGE) ) ;
      info.largeur  = clipboard.img.fd_w ;
      info.hauteur  = clipboard.img.fd_h ;
      info.compress = 1 ;
      strcat( name, "SCRAP." ) ;
      if ( Truecolor ) info.lformat = IID_TIFF ;
      else             info.lformat = IID_IMG ;
      img_module = DImgGetModuleFromIID( info.lformat ) ;
      if ( img_module )
      {
        strcat( name, img_module->Capabilities.file_extension ) ;
        save_picture( name, &clipboard.img, &info, NULL ) ;
      }
    }
    mouse_restore() ;
  }
}
Пример #11
0
int init_rtmemory(void)
{
  int err = 0 ;

  if ( RTZoomSrc.fd_addr != NULL )    free( RTZoomSrc.fd_addr ) ;
  if ( RTZoomDst.fd_addr != NULL )    free( RTZoomDst.fd_addr ) ;
  if ( RTZoomSrcStd.fd_addr != NULL ) free( RTZoomSrcStd.fd_addr ) ;
  if ( RTZoomDstStd.fd_addr != NULL ) free( RTZoomDstStd.fd_addr ) ;

  memset( &RTZoomSrc, 0, sizeof(MFDB) ) ;
  RTZoomSrc.fd_w = config.rt_width / config.rt_zoomlevel ;
  if ( RTZoomSrc.fd_w % 16 ) RTZoomSrc.fd_w = ( RTZoomSrc.fd_w + 16 ) & 0xFFF0 ;
  RTZoomSrc.fd_wdwidth = RTZoomSrc.fd_w / 16 ;
  if ( RTZoomSrc.fd_w % 16 ) RTZoomSrc.fd_wdwidth++ ;
  RTZoomSrc.fd_h = config.rt_height / config.rt_zoomlevel ;
  RTZoomSrc.fd_nplanes = nb_plane ;
  RTZoomSrc.fd_addr    = img_alloc( RTZoomSrc.fd_w, RTZoomSrc.fd_h, RTZoomSrc.fd_nplanes ) ;
  if ( RTZoomSrc.fd_addr == NULL ) err = -3 ;
  else                             img_raz( &RTZoomSrc ) ;

  if ( !err )
  {
    memset( &RTZoomDst, 0, sizeof(MFDB) ) ;
    RTZoomDst.fd_w = RTZoomSrc.fd_w * config.rt_zoomlevel ;
    RTZoomDst.fd_wdwidth = RTZoomDst.fd_w / 16 ;
    if ( RTZoomDst.fd_w %16 ) RTZoomDst.fd_wdwidth++ ;
    RTZoomDst.fd_h = config.rt_height ; 
    RTZoomDst.fd_nplanes = nb_plane ;
    RTZoomDst.fd_addr = img_alloc( RTZoomDst.fd_w, RTZoomDst.fd_h, RTZoomDst.fd_nplanes ) ;
    if ( RTZoomDst.fd_addr == NULL )
    {
      err = -3 ;
      free( RTZoomSrc.fd_addr ) ;
      memset( &RTZoomSrc, 0, sizeof(MFDB) ) ;
    }
    else
      img_raz( &RTZoomDst ) ;
  }

  StdVDINeeded = (char)FZNeedStdFormat ;
  if ( !err && StdVDINeeded )
  {
    /* Il va y avoir des allocations suppl‚mentaires */
    memcpy( &RTZoomSrcStd, &RTZoomSrc, sizeof(MFDB) ) ;
    RTZoomSrcStd.fd_stand = 1 ;
    RTZoomSrcStd.fd_addr  = img_alloc( RTZoomSrcStd.fd_w, RTZoomSrcStd.fd_h, RTZoomSrcStd.fd_nplanes ) ;
    if ( RTZoomSrcStd.fd_addr == NULL )
    {
      err = -3 ;
      free( RTZoomSrc.fd_addr ) ;
      memset( &RTZoomSrc, 0, sizeof(MFDB) ) ;
      free( RTZoomDst.fd_addr ) ;
      memset( &RTZoomDst, 0, sizeof(MFDB) ) ;
    }
    else
      img_raz( &RTZoomSrcStd ) ;

    if ( !err )
    {
      memcpy( &RTZoomDstStd, &RTZoomDst, sizeof(MFDB) ) ;
      RTZoomDstStd.fd_stand = 1 ;
      RTZoomDstStd.fd_addr  = img_alloc( RTZoomDstStd.fd_w, RTZoomDstStd.fd_h, RTZoomDstStd.fd_nplanes ) ;
      if ( RTZoomDstStd.fd_addr == NULL )
      {
        err = -3 ;
        free( RTZoomSrcStd.fd_addr ) ;
        memset( &RTZoomSrcStd, 0, sizeof(MFDB) ) ;
        free( RTZoomSrc.fd_addr ) ;
        memset( &RTZoomSrc, 0, sizeof(MFDB) ) ;
        free( RTZoomDst.fd_addr ) ;
        memset( &RTZoomDst, 0, sizeof(MFDB) ) ;
      }
      else
        img_raz( &RTZoomDstStd ) ;
    }
  }
  
  return( err ) ;
}