示例#1
0
void simply_res_clear(SimplyRes *self) {
  while (self->images) {
    destroy_image(self, (SimplyImage*) self->images);
  }

  while (self->fonts) {
    destroy_font(self, (SimplyFont*) self->fonts);
  }
}
示例#2
0
文件: chipmunk.c 项目: rlofc/cage
/* Cleanup
 * -------
 *
 * Clean up is simple enough. Just destroy the tile
 * image and free the state structure memory.
 */
static void destroy_sample(void* data)
{
    struct state* state = data;
    cleanup_walls(state);
    cleanup_tiles(state);
    destroy_image(state->tile_img);
    cpBodyFree(state->mouse_body);
    cpSpaceFree(state->space);
    free(data);
}
示例#3
0
文件: res.c 项目: harnold/ducks
void res_destroy_images(void)
{
    const struct image_info *info;

    for (info = image_infos; info->image != NULL; info++) {
        if (info->image->data != NULL) {
            destroy_image(info->image);
            info->image->data = NULL;
        }
    }
}
示例#4
0
文件: wizard.c 项目: dmalves/cage
/* Destroying a wizard means destroying each and every
 * created resource in the **create\_wizard** function.
 * If we fail to do so, we will introduce a memory leak
 * to the game.
 */
static void destroy_wizard(struct wizard* wizard)
{
    if (wizard != NULL) {
        destroy_animation(wizard->walk_right);
        destroy_animation(wizard->spell);
        destroy_animation(wizard->stand);
        destroy_image(wizard->sprite->image);
        destroy_sprite(wizard->sprite);
        free(wizard);
    }
}
示例#5
0
文件: menu.c 项目: lin826/Slapjack
void Loser()
{
    loseTimes++;
    int count=1;
    Image *loser;
    int ran,i;
    srand( time(NULL) );
    ran=rand()%2;
    while(count<=6)
    {

        clearScreen();
        switch(count)
        {

        case 1:
            loser= read_image("Loser1.pixel","Loser1.color");
            break;
        case 2:
            loser= read_image("Loser2.pixel","Loser2.color");
            break;
        case 3:
            loser= read_image("Loser3.pixel","Loser3.color");
            break;
        case 4:
            loser= read_image("Loser4.pixel","Loser4.color");
            break;
        case 5:
            loser= read_image("Loser5.pixel","Loser5.color");
            break;
        case 6:
            loser= read_image("Loser6.pixel","Loser6.color");
        default:
            break;


        }
        count++;
        show_image(loser,120,35);
        drawCmdWindow();  /* update window immediately */


        for(i=0; i<1; i++)
        {
            playAudio(&audioLose[ran]);
            //Sleep(100);
        }

        Sleep(300);
    }
    destroy_image(loser);
    showTable();
}
示例#6
0
文件: menu.c 项目: lin826/Slapjack
void Loser2(int x,int y)  //small lose send location
{
    int count=1;
    Image *loser;
    int ran,i;
    srand( time(NULL) );
    ran=rand()%2;
    while(count<=6)
    {

        clearScreen();
        switch(count)
        {

        case 1:
            loser= read_image("Loser21.pixel","Loser21.color");
            break;
        case 2:
            loser= read_image("Loser22.pixel","Loser22.color");
            break;
        case 3:
            loser= read_image("Loser23.pixel","Loser23.color");
            break;
        case 4:
            loser= read_image("Loser24.pixel","Loser24.color");
            break;
        case 5:
            loser= read_image("Loser25.pixel","Loser25.color");
            break;
        case 6:
            loser= read_image("Loser26.pixel","Loser26.color");
        default:
            break;


        }
        count++;
        show_image(loser,x,y);
        drawCmdWindow();  /* update window immediately */


        for(i=0; i<1; i++)
        {
            playAudio(&audioLose[ran]);
            //Sleep(300);
        }

        Sleep(300);
    }
    destroy_image(loser);

}
示例#7
0
static int encode(const char *infile) {
    int     ok;
    image_t     image;
    const char  *outfile;

    if(use_verbose) {
        printf("encoding %s.. ", infile);
    }

    if(get_image(infile, &image) < 0) {
        fprintf(stderr, "failed reading %s\n", infile);
        return -EINVAL;
    }

    if(valid_size(image.w) == 0 || valid_size(image.h) == 0) {
        fprintf(stderr, "image dimensions for %s are not valid, see manual\n", infile);
        destroy_image(&image);
        return -EINVAL;
    }

    outfile = figure_outfilename(infile, "kmg");

    if(outfile == NULL) {
        fprintf(stderr, "memory allocation failed for %s\n", infile);
        return -ENOMEM;
    }

    /* Convert the input image to a 16-bit image according to parameters */
    convert_to_16(&image);

    /* Save it */
    ok = save(outfile, &image);

    destroy_image(&image);

    printf("\n");
    return ok;
}
示例#8
0
bool Images::load_texture( ClutterTexture * texture, gpointer data, gsize size, const char * content_type )
{
    TPImage * image = decode_image( data, size, content_type );

    if ( ! image )
    {
        return false;
    }

    load_texture( texture, image, 0, 0, image->width, image->height );

    destroy_image( image );

    return true;
}
示例#9
0
bool Images::load_texture( ClutterTexture * texture, const char * filename )
{
    TPImage * image = decode_image( filename );

    if ( ! image )
    {
        return false;
    }

    load_texture( texture, image, 0, 0, image->width, image->height );

    destroy_image( image );

    return true;
}
示例#10
0
文件: xdata.cpp 项目: toppk/xevil
void Xvars::gen_pix_from_trans(int dpyNum,Drawable dest,Drawable src,
                               const Size& srcSize,TransformType transform,
                               int depth) {
  // Get source image into client memory.
  XImage* srcImage = 
    XGetImage(dpy[dpyNum],src,0,0,srcSize.width,srcSize.height,
              AllPlanes,ZPixmap);
  if (!srcImage) {
    std::cerr << "Could not get image in Xvars::gen_pix_from_trans." << std::endl;
    return;
  }

  // Size of destination image.
  Size destSize = Transform2D::apply(transform,srcSize);

  // Allocate memory for the image.
  char* destData = new_bytes_for_image(destSize,depth,srcImage->bitmap_pad);

  // Create XImage for the transformed data.
  XImage* destImage =
    XCreateImage(dpy[dpyNum],visual[dpyNum],depth,ZPixmap,0,
                 destData,destSize.width,destSize.height,
                 srcImage->bitmap_pad,0);
  assert(destImage);
  assert(destData == destImage->data);
  

  // Traverse coordinates of src, compute corresponding position on 
  // dest and copy the pixel.
  Pos srcPos; 
  for (srcPos.y = 0; srcPos.y < srcSize.height; srcPos.y++) {
    for (srcPos.x = 0; srcPos.x < srcSize.width; srcPos.x++) {
      Pos destPos = Transform2D::apply(transform,srcPos,srcSize);
      unsigned long pix = XGetPixel(srcImage,srcPos.x,srcPos.y);
      XPutPixel(destImage,destPos.x,destPos.y,pix);
    }
  }

  put_image(dpyNum,dest,destImage,destSize);

  // Make sure to use new/delete for freeing the memory we allocated.
  destroy_image(destImage);

  XDestroyImage(srcImage);
}
示例#11
0
文件: menu.c 项目: lin826/Slapjack
void Winner2(int x,int y)
{
    int count=1;
    Image *winner;
    int ran,i;
    srand( time(NULL) );
    ran=rand()%2;
    int time=7;
    while(time--)
    {
        clearScreen();
        switch(count)
        {
        case 1:
            winner= read_image("Winner21.pixel","Winner21.color");
            break;
        case 2:
            winner= read_image("Winner22.pixel","Winner22.color");
            break;
        case 3:
            winner= read_image("Winner23.pixel","Winner23.color");
            break;
        default:
            break;
        }

        count=(count+1)%4;
        show_image(winner,x,y);
        drawCmdWindow();  /* update window immediately */

        for(i=0; i<1; i++)
        {
            playAudio(&audioWin[ran]);
            //Sleep(300);
        }

        Sleep(200);
    }
    destroy_image(winner);
}
示例#12
0
/* Free the given sprite, and decrement the reference count on its image.
 */
static void
destroy_sprite (ModeInfo *mi, sprite *sp)
{
  slideshow_state *ss = &sss[MI_SCREEN(mi)];
  Bool freed_p = False;
  image *img;
  int i;

  if (!sp) abort();
  if (sp->state != DEAD) abort();
  img = sp->img;
  if (!img) abort();
  if (!img->loaded_p) abort();
  if (!img->used_p) abort();
  if (img->refcount <= 0) abort();

  for (i = 0; i < ss->nsprites; i++)		/* unlink it from the list */
    if (ss->sprites[i] == sp)
      {
        int j;
        for (j = i; j < ss->nsprites-1; j++)	/* pull remainder forward */
          ss->sprites[j] = ss->sprites[j+1];
        ss->sprites[j] = 0;
        ss->nsprites--;
        freed_p = True;
        break;
      }

  if (!freed_p) abort();
  free (sp);
  sp = 0;

  img->refcount--;
  if (img->refcount < 0) abort();
  if (img->refcount == 0)
    destroy_image (mi, img);
}
示例#13
0
int do_fork()
{
  int pid,i;

  pid=fork();
  if (pid<0)
    perror("sorry, could not fork");
  if (pid==0)
    {
      destroy_image();
      x_screen_open(1);
      init_timers();
      conv_chunk(qlscreen.qm_lo,qlscreen.qm_hi);
      redraw_screen(0,0,qlscreen.xres,qlscreen.yres);
      XFlush(display);
      fork_files();
    }

  /* resetting the state of the keyboard seems the best */
  gKeyDown=0;
  for (i=0;i<8;i++) keyrow[i]=0;
  
  return pid;
}
示例#14
0
static int
initialize (struct filter *f, struct initdata *i)
{
  struct subdata *s = (struct subdata *) f->data;
  int x;
  int val = 0;
  pixel_t **lines1, **lines2 = NULL;
  double size;
  int width, height;
  int threed = 0;
  struct filter *f1 = f;

  inhermisc (f, i);
  if (datalost (f, i))
    s->recal = 1;
  while (f1)
    {
      if (f1->action == &threed_filter)
	threed = 1;
      f1 = f1->next;
    }
  f->imageversion = i->image->version;
  if (f->childimage != NULL)
    destroy_image (f->childimage);
  s->image = f->image = i->image;
  s->image->flags |= PROTECTBUFFERS;
  s->currlines = f->image->currlines;
  s->forpversion = f->image->palette->version;
  s->forversion = f->fractalc->version;
  if (f->image->width * f->image->pixelwidth <
      f->image->height * f->image->pixelheight)
    size = f->image->width * f->image->pixelwidth / 2;
  else
    size = f->image->height * f->image->pixelheight / 2;
  width = (int) (size / f->image->pixelwidth);
  height = (int) (size / f->image->pixelheight);
  /*fractalc_resize_to(f->fractalc,size,size); */
  lines1 = (pixel_t **) malloc (sizeof (*lines1) * height);
  if (f->image->nimages == 2)
    lines2 = (pixel_t **) malloc (sizeof (*lines2) * height);
  if (lines1 == NULL)
    return 0;
  if (f->image->nimages == 2 && lines2 == NULL)
    {
      free (lines1);
      return 0;
    }
  for (x = 0; x < height; x++)
    {
      lines1[x] =
	i->image->currlines[x + (threed ? f->image->height / 3 : 0)];
      if (f->image->nimages == 2)
	lines2[x] =
	  i->image->oldlines[x + (threed ? f->image->height / 3 : 0)];
    }
  if (f->image->nimages == 2)
    for (x = 0; x < f->image->height; x++)
      {
	memcpy (f->image->oldlines[x], f->image->currlines[x],
		f->image->width * f->image->bytesperpixel);
      }
  f->childimage = i->image =
    create_image_lines (width, height, f->image->nimages, lines1, lines2,
			i->image->palette, myflip, FREELINES,
			f->image->pixelwidth, f->image->pixelheight);
  if (i->image == NULL)
    {
      free (lines1);
      free (lines2);
      return 0;
    }
  f->childimage->data = s;
  x = f->previous->action->initialize (f->previous, i);
  if (!x)
    return 0;
  if (s->second != NULL)
    {
      i->image = f->image;
      val = s->second->action->initialize (s->second, i);
      if (!val)
	return 0;
    }
  return (x | val);

}
示例#15
0
文件: xdata.cpp 项目: toppk/xevil
Boolean Xvars::load_pixmap(Drawable* pixmap,Drawable* mask,
                           int dpyNum,char** xpmBits,Boolean fullSize) {
  // Just load XPM as is.
  if (fullSize) {
    XpmAttributes attr;
    attr.valuemask = XpmCloseness;
    attr.closeness = XPM_CLOSENESS;
    attr.alloc_close_colors = True;

    int val = 
      XpmCreatePixmapFromData(dpy[dpyNum],root[dpyNum],
                              xpmBits,
                              pixmap,mask,
                              &attr);
    XpmFreeAttributes(&attr);

    Boolean ret = (val == XpmSuccess);
    if (!*pixmap || (mask && !*mask)) {
      ret = False;
    }

    return ret; 
  }


  //// Load image and mask into memory, reduce them and put them up to the
  //// display server as a new pixmap and mask

  XImage* srcImage;
  XImage* srcMask;
  Size srcSize;

  // Load in src image from supplied data.
  XpmAttributes attr;
  attr.valuemask = XpmReturnPixels | XpmCloseness;
  attr.closeness = XPM_CLOSENESS;
  attr.alloc_close_colors = True;

  // Perhaps should use XpmReturnAllocPixels, neither gives the transparent 
  // value.
  int val = 
    XpmCreateImageFromData(dpy[dpyNum],
                           xpmBits,
                           &srcImage,(mask ? &srcMask : (XImage**)NULL),
                           &attr);
  srcSize.width = attr.width;
  srcSize.height = attr.height;
  if (val != XpmSuccess) {
    XpmFreeAttributes(&attr);
    return False;
  }
  // Must be even size.
  assert((srcSize.width % 2 == 0) && 
         (srcSize.height % 2 == 0));
  int depth = srcImage->depth;
  int bitmap_pad = srcImage->bitmap_pad;

  // Size of reduced, destination image.
  Size destSize;
  destSize.set(srcSize.width / 2,srcSize.height / 2);
  
  // Create image for dest data.
  char* destData = 
    new_bytes_for_image(destSize,depth,bitmap_pad);
  XImage *destImage = 
    XCreateImage(dpy[dpyNum],visual[dpyNum],depth,ZPixmap,0,
                 destData,destSize.width,destSize.height,
                 bitmap_pad,0);
  assert(destImage);

  // Create dest mask if needed.
  XImage *destMask;
  if (mask) {
    assert(srcMask->depth == 1);
    char* destMaskData = 
      new_bytes_for_image(destSize,1,bitmap_pad);
    destMask = 
      XCreateImage(dpy[dpyNum],visual[dpyNum],1,ZPixmap,0,
                   destMaskData,destSize.width,destSize.height,
                   bitmap_pad,0);
    assert(destMask);
  }
    
  // Do the pixel reduction.
  //  unstretch_image(dpyNum,destImage,srcImage,attr.pixels,attr.npixels);
  unstretch_image(dpyNum,destImage,srcImage,
                  attr.pixels,attr.npixels);
  if (mask) {
    unstretch_image(dpyNum,destMask,srcMask,NULL,0);
  }

  // Kill src image and mask.
  XpmFreeAttributes(&attr);
  XDestroyImage(srcImage);  
  if (mask) {
    XDestroyImage(srcMask);
  }
      
  // Create dest pixmap and mask
  *pixmap = XCreatePixmap(dpy[dpyNum],root[dpyNum],
                          destSize.width,destSize.height,
                          depth);
  if (!*pixmap) {
    // Should do more cleanup.
    return False;
  }
  if (mask) {
    *mask = XCreatePixmap(dpy[dpyNum],root[dpyNum],
                          destSize.width,destSize.height,
                          1);
    if (!*mask) {
      // Should do more cleanup.
      return False;
    }
  }

  // Put dest image and mask up to the display server.
  put_image(dpyNum,*pixmap,destImage,destSize);
  if (mask) {
    put_image(dpyNum,*mask,destMask,destSize);
  }

  // Kill dest image and mask
  destroy_image(destImage);
  if (mask) {
    destroy_image(destMask);
  }
  return True;
}
示例#16
0
void calculate_difference_images(Image *source_image1, Image *source_image2, int n, Image *dest_image) {
	for (int i = 0; i < n; i++) {
		int h = source_image1[i].height;
		if (source_image2[i].height < h)
			h = source_image2[i].height;
		int w = source_image1[i].width;
		if (source_image2[i].width < w)
			w = source_image2[i].width;
		dest_image[i] = source_image1[i]; // Copy fields.
		dest_image[i].pixels = (unsigned int *)malloc(h * source_image1[i].extended_width * 4);
		Image *source1;
		int source1_is_cloned = 0;
		Image cloned_image1;
		if (source_image1[i].is_half_float) {
			dest_image[i].is_half_float = 0;
			dest_image[i].bits_per_component = 8;
			clone_image(&source_image1[i], &cloned_image1);
			convert_image_from_half_float(&cloned_image1, dynamic_range_min, dynamic_range_max,
				dynamic_range_gamma);
			convert_image_to_or_from_cairo_format(&cloned_image1);
			source1 = &cloned_image1;
			source1_is_cloned = 1;
		}
		else
			source1 = &source_image1[i];
		Image *source2;
		int source2_is_cloned = 0;
		Image cloned_image2;
		if (source_image2[i].is_half_float) {
			clone_image(&source_image2[i], &cloned_image2);
			convert_image_from_half_float(&cloned_image2, dynamic_range_min, dynamic_range_max,
				dynamic_range_gamma);
			convert_image_to_or_from_cairo_format(&cloned_image2);
			source2 = &cloned_image2;
			source2_is_cloned = 1;
		}
		else
			source2 = &source_image2[i];
		bool have_alpha = source1->alpha_bits > 0 && source2->alpha_bits > 0;
		for (int y = 0; y < h; y++)
			for (int x = 0; x < w; x++) {
				uint32_t pixel1 = source1->pixels[y * source1->extended_width + x];
				uint32_t pixel2 = source2->pixels[y * source2->extended_width + x];
				int difference = 0;
				bool add_rgb_diff = true;
				if (have_alpha) {
					int a1 = pixel_get_a(pixel1);
					int a2 = pixel_get_a(pixel2);
					if ((a1 | a2) == 0)
						add_rgb_diff = false;
					else
						difference += abs(a1 - a2);
				}
				else
					add_rgb_diff = true;
				if (add_rgb_diff)
					difference += abs(pixel_get_r(pixel1) - pixel_get_r(pixel2)) +
						abs(pixel_get_g(pixel1) - pixel_get_g(pixel2)) +
						abs(pixel_get_b(pixel1) - pixel_get_b(pixel2));
				if (difference > 255)
					difference = 255;
				dest_image[i].pixels[y * dest_image[i].extended_width + x] =
					pack_rgb_alpha_0xff(difference, difference, difference);
			}
		if (source1_is_cloned)
			destroy_image(source1);
		if (source2_is_cloned)
			destroy_image(source2);
	}
}
示例#17
0
文件: filter.c 项目: Azizou/XaoS
void destroyinheredimage(struct filter *f)
{
    if (f->flags & ALLOCEDIMAGE)
	destroy_image(f->childimage), f->flags &=
	    ~(ALLOCEDIMAGE | SHAREDDATA), f->childimage = NULL;
}
示例#18
0
文件: collisions.c 项目: dmalves/cage
/* Cleanup
 * -------
 *
 * Clean up is simple enough. Just destroy the star
 * image and free the state structure memory.
 */
static void destroy_sample(void* data)
{
    struct state* state = data;
    destroy_image(state->star_img);
    free(data);
}
示例#19
0
static coded_image *
CodedImageSource_get_frame_from_python( PyObject *self, int frame, int quality ) {
    PyGILState_STATE gstate;
    gstate = PyGILState_Ensure();

    PyObject *result_obj = PyObject_CallMethod( (PyObject *) self, "get_frame", "i", frame );

    PyGILState_Release( gstate );

    if( !result_obj ) {
        PyErr_Print();
        return NULL;
    }

    Py_ssize_t plane_count = PySequence_Length( result_obj );

    if( plane_count == -1 ) {
        PyErr_Print();
        return NULL;
    }

    coded_image *image = g_new0( coded_image, 1 );
    image->free_func = (GFreeFunc) destroy_image;

    for( Py_ssize_t plane = 0; plane < plane_count && plane < CODED_IMAGE_MAX_PLANES; plane++ ) {
        PyObject *plane_obj = PySequence_GetItem( result_obj, plane );

        if( !plane_obj ) {
            PyErr_Print();
            Py_CLEAR(result_obj);
            destroy_image( image );

            return NULL;
        }

        PyObject *data_obj = PyObject_GetAttrString( plane_obj, "data" );

        if( data_obj == Py_None ) {
            Py_CLEAR(data_obj);
            Py_CLEAR(plane_obj);
            continue;
        }

        PyObject *stride_obj = PyObject_GetAttrString( plane_obj, "stride" );
        PyObject *line_count_obj = PyObject_GetAttrString( plane_obj, "line_count" );
        Py_CLEAR(plane_obj);

        if( !data_obj || !stride_obj || !line_count_obj ) {
            PyErr_Print();
            Py_CLEAR(data_obj);
            Py_CLEAR(stride_obj);
            Py_CLEAR(line_count_obj);
            Py_CLEAR(result_obj);
            destroy_image( image );

            return NULL;
        }

        image->stride[plane] = PyLong_AsLong( stride_obj );
        Py_CLEAR(stride_obj);

        image->line_count[plane] = PyLong_AsLong( line_count_obj );
        Py_CLEAR(line_count_obj);

        if( PyErr_Occurred() ) {
            PyErr_Print();
            Py_CLEAR(data_obj);
            Py_CLEAR(result_obj);
            destroy_image( image );

            return NULL;
        }

        Py_buffer buffer;

        if( PyObject_GetBuffer( data_obj, &buffer, PyBUF_SIMPLE ) == -1 ) {
            PyErr_Print();
            Py_CLEAR(data_obj);
            Py_CLEAR(result_obj);
            destroy_image( image );

            return NULL;
        }

        if( buffer.len != image->stride[plane] * image->line_count[plane] ) {
            Py_CLEAR(data_obj);
            Py_CLEAR(result_obj);
            PyBuffer_Release( &buffer );
            destroy_image( image );

            g_warning(
                "Error in plane %zd: expected %zd bytes, got %zd bytes.",
                plane,
                (Py_ssize_t) image->stride[plane] * image->line_count[plane],
                buffer.len );
            return NULL;
        }

        image->data[plane] = g_memdup( buffer.buf, buffer.len );

        PyBuffer_Release( &buffer );
        Py_CLEAR(data_obj);
    }

    return image;
}
示例#20
0
int create_texture(LPTEXTURE *t, const char *path, uint16 *width, uint16 *height, int numMips, BOOL * colorkey, D3DPOOL pool)
{
#ifdef TEXTURE_PNG
	HRESULT hr;
	texture_image_t image;

	Change_Ext( path, image.path, ".PNG" );
	if( ! File_Exists( (char*) image.path ) )
	{
		DebugPrintf("Could not find texture file: %s\n",path);
		return TRUE;
	}

	// at this point i have mips turned off for the commit
	// cause it appears that mip levels after 0 are not present
	// i think we need to copy each successive mipmap in at a time
	numMips = 1;

	// load the image
	if(load_image( &image, numMips )!=0)
	{
		DebugPrintf("couldn't load image\n");
		return S_FALSE;
	}

	// create d3d texture
	hr = lpD3DDevice->CreateTexture( image.w, image.h, numMips, 0, D3DFMT_A8R8G8B8, pool, texture, NULL );
	if (FAILED(hr))
	{
		DebugPrintf("couldn't create texture\n");
		return hr;
	}

	// copy data into the texture
	{
		int y, x;
		int size = 4;
		int pitch = size*image.w;
		D3DLOCKED_RECT lrect;
		BYTE* pBits;
		LPTEXTURE _texture = *texture;
		_texture->LockRect(0,&lrect,NULL,D3DLOCK_DISCARD);
		pBits = (BYTE*)lrect.pBits;
		for (y = 0; y < image.h; y++)
		{
			for (x = 0; x < image.w; x++)
			{
				// move to the correct offset in the table
				// y is the row and pitch is the size of a row
				// (x*size) is the length of each pixel data (column)
				DWORD index = (y*pitch)+(x*size);
				// d3d has it's own pitch value cause it stores data at the end of the row
				DWORD index_p = (y*lrect.Pitch)+(x*size);
				// D3DFMT_A8R8G8B8 data will be accessible backwards: bgra
				// image.data is packed in rgba
				pBits[index_p]   = (BYTE)gamma_table[image.data[index+2]]; // blue
				pBits[index_p+1] = (BYTE)gamma_table[image.data[index+1]]; // green
				pBits[index_p+2] = (BYTE)gamma_table[image.data[index]];   // red
				// colour key
				if( image.colorkey && (pBits[index_p] + pBits[index_p+1] + pBits[index_p+2]) == 0 )
					pBits[index_p+3] = 0; // alpha - pixel will not be coppied do to alpha=0 ignore
				// do not colour key
				else
					pBits[index_p+3] = (BYTE)gamma_table[image.data[index+3]]; // alpha

			}
		}
		_texture->UnlockRect(0);
	}

	// return the values
	*width  = (uint16) image.w;
	*height = (uint16) image.h;
	(*colorkey) = (BOOL) image.colorkey;

	// info
	DebugPrintf( "Created texture: file=%s, width=%d, height=%d, colorkey=%s\n", 
		image.path, image.w, image.h, (image.colorkey ? "true" : "false") );

	//
	destroy_image( &image );

	//
	return S_OK;

#else

	LPDIRECT3DTEXTURE9 * texture = (LPDIRECT3DTEXTURE9*)t;
	D3DXIMAGE_INFO imageInfo;

	// if the file doesn't exist
	char real_file[256];
	if( ! File_Exists( (char*) path ) )
	{
		// try to find a png version
		Change_Ext( path, real_file, ".PNG" );
		path = &real_file[0];
	}
	if( ! File_Exists( (char*) path ) )
	{
		// try to find a png version
		Change_Ext( path, real_file, ".BMP" );
		path = &real_file[0];
		DebugPrintf("Could not find PNG version of: %s\n",path);
	}
	if( ! File_Exists( (char*) path ) )
	{
		DebugPrintf("Could not find texture file: %s\n",path);
		return S_FALSE;
	}

	HRESULT LastError = D3DXCreateTextureFromFileEx(lpD3DDevice, 
				path, 
				0,//*width, 
				0,//*height, 
				numMips, 
				0,
				// most likely will end up as the format the file is in
				D3DFMT_A8R8G8B8, // all texure data will be accessible in LockRect()'s pBits backwards: bgra
				pool,
				D3DX_DEFAULT,
				D3DX_DEFAULT,
				(*colorkey) ? OPAQUE_BLACK : 0, // colour key
				&imageInfo,
				NULL,
				texture);

	if (FAILED(LastError))
	{
		DebugPrintf("couldn't create texture\n");
	}
	
	// return the values
	*width  = (uint16) imageInfo.Width;
	*height = (uint16) imageInfo.Height;

	// image has no alpha layer
	// only way image would have an alpha layer
	// is the updated textures we created
	// which will have exactly this format!
	if( imageInfo.Format != D3DFMT_A8R8G8B8 )
		(*colorkey) = FALSE;

	// debugging info
	DebugPrintf("Created texture from %s\n",path);
	DebugPrintf("Texture Details: width=%d, height=%d, depth=%d, mips=%d, image_format=%s, file_format=%s\n",
					imageInfo.Width, imageInfo.Height, imageInfo.Depth, imageInfo.MipLevels, 
					d3d_format(imageInfo.Format), d3d_image_file_formats[imageInfo.ImageFileFormat] );

	/*
	// saves the texture in it's loaded format to a file
	{
		static int count = 0;
		sprintf(buf, ".\\Dumps\\%s.png", fileName);
		D3DXSaveTextureToFile(buf, D3DXIFF_PNG, (*texture), 0);
		count++;
	}
	*/

	//
	// gamma correction
	//
	{
		unsigned int y, x;
		int size = 4;
		D3DLOCKED_RECT lrect;
		BYTE* pBits;
		LPDIRECT3DTEXTURE9 _texture = *texture;
		_texture->LockRect(0,&lrect,NULL,D3DLOCK_DISCARD);
		pBits = (BYTE*)lrect.pBits;
		for (y = 0; y < imageInfo.Height; y++)
		{
			for (x = 0; x < imageInfo.Width; x++)
			{
				// move to the correct off set in the table
				// pitch is the width of a row
				// (x*size) is the length of each pixel data
				DWORD index = (x*size)+(y*lrect.Pitch);
				// D3DFMT_A8R8G8B8 data will be accessible backwards: bgra
				pBits[index]   = (BYTE)gamma_table[pBits[index]];	// Blue
				pBits[index+1] = (BYTE)gamma_table[pBits[index+1]];// Green
				pBits[index+2] = (BYTE)gamma_table[pBits[index+2]];// Red
				// i did not see any alpha values changed for gamma in d3d6 version
				//pBits[index+3] = (BYTE)gamma_table[pBits[index+3]];// Alpha
			}
		}
		_texture->UnlockRect(0);
	}

	return LastError;

#endif
}
示例#21
0
文件: menu.c 项目: lin826/Slapjack
void start()
{
    int count=1;
    int ok=0;
    Image *start;
    int time=20;//29
    while(time--)
    {

        clearScreen();
        switch(count)
        {
        case 1:
            start= read_image("start1.pixel","start1.color");
            break;
        case 2:
            start= read_image("start2.pixel","start2.color");
            break;
        case 3:
            start= read_image("start3.pixel","start3.color");
            break;
        case 4:
            start= read_image("start4.pixel","start4.color");
            break;
        case 5:
            start= read_image("start5.pixel","start5.color");
            break;
        case 6:
            start= read_image("start6.pixel","start6.color");
            break;
        case 7:
            start= read_image("start7.pixel","start7.color");
            break;
        case 8:
            start= read_image("start8.pixel","start8.color");
            break;
        case 9:
            start= read_image("start9.pixel","start9.color");
            break;
        case 10:
            start= read_image("start10.pixel","start10.color");
            break;
        case 11:
            start= read_image("start11.pixel","start11.color");
            break;
        case 12:
            start= read_image("start12.pixel","start12.color");
            break;
        case 13:
            start= read_image("start13.pixel","start13.color");
            break;
        case 14:
            start= read_image("start14.pixel","start14.color");
            break;
        case 15:
            start= read_image("start15.pixel","start15.color");
            break;
        case 16:
            start= read_image("start16.pixel","start16.color");
            break;
        default:
            break;


        }

        if(count==16)
        {
            ok=1;
        }
        if(ok)
        {
            // count=(count+1)%16+10;
            if(count==15)
            {
                count=16;
            }
            else
            {
                count=15;
            }

        }
        else
        {
            count++;
        }
        show_image(start,125,35);
        drawCmdWindow();
        int i=0;
        for(i=0; i<1; i++)
        {
            playAudio(&audio[0]);
            //Sleep(500);
        }

        Sleep(500);
    }
    destroy_image(start);

}
示例#22
0
文件: menu.c 项目: lin826/Slapjack
void gameover()
{
    int count=2;
    Image *gameover;

    int ran,i;
    srand( time(NULL) );
    ran=rand()%6;

    while(count<=11)
    {

        clearScreen();
        switch(count)
        {

        case 2:
            gameover= read_image("gameover2.pixel","gameover2.color");
            break;
        case 3:
            gameover= read_image("gameover3.pixel","gameover3.color");
            break;
        case 4:
            gameover= read_image("gameover4.pixel","gameover4.color");
            break;
        case 5:
            gameover= read_image("gameover5.pixel","gameover5.color");
            break;
        case 6:
            gameover= read_image("gameover6.pixel","gameover6.color");
            break;
        case 7:
            gameover= read_image("gameover7.pixel","gameover7.color");
            break;
        case 8:
            gameover= read_image("gameover8.pixel","gameover8.color");
            break;
        case 9:
            gameover= read_image("gameover9.pixel","gameover9.color");
            break;
        case 10:
            gameover= read_image("gameover10.pixel","gameover10.color");
            break;
        case 11:
            gameover= read_image("gameover11.pixel","gameover11.color");
            break;
        default:
            break;


        }
        count++;
        show_image(gameover,120,35);
        drawCmdWindow();


        if(count%4==0)
        {
            for(i=0; i<2; i++)
            {
                playAudio(&audioOver[ran]);
                //Sleep(300);
            }
        }
        Sleep(300);
    }
    destroy_image(gameover);

}