Example #1
0
/**
 * Copy from a source image into a destination image of the specified
 * format and check the result.
 *
 * If \a strict_layout_qualifiers is false, uniform layout qualifiers
 * will be omitted where allowed by the spec.  If \a
 * strict_access_qualifiers is false, the "readonly" and "writeonly"
 * qualifiers will be omitted.  If \a strict_binding is false, the
 * image will be bound as READ_WRITE, otherwise only the required
 * access type will be used.
 */
static bool
run_test(const struct image_format_info *format,
         bool strict_layout_qualifiers,
         bool strict_access_qualifiers,
         bool strict_binding)
{
        const struct grid_info grid =
                grid_info(GL_FRAGMENT_SHADER,
                          image_base_internal_format(format), W, H);
        const struct image_info img =
                image_info(GL_TEXTURE_2D, format->format, W, H);
        GLuint prog = generate_program(
                grid, GL_FRAGMENT_SHADER,
                concat(image_hunk(img, ""),
                       test_hunk(strict_layout_qualifiers,
                                 strict_access_qualifiers),
                       hunk("SRC_IMAGE_Q uniform IMAGE_BARE_T src_img;\n"
                            "DST_IMAGE_Q uniform IMAGE_BARE_T dst_img;\n"
                            "\n"
                            "GRID_T op(ivec2 idx, GRID_T x) {\n"
                            "        imageStore(dst_img, IMAGE_ADDR(idx),"
                            "                   imageLoad(src_img, IMAGE_ADDR(idx)));\n"
                            "        return x;\n"
                            "}\n"), NULL));
        bool ret = prog && init_fb(grid) &&
                init_image(img, 0, strict_binding) &&
                init_image(img, 1, strict_binding) &&
                set_uniform_int(prog, "src_img", 0) &&
                set_uniform_int(prog, "dst_img", 1) &&
                draw_grid(grid, prog) &&
                check(grid, img);

        glDeleteProgram(prog);
        return ret;
}
Example #2
0
static bool
run_test(const struct image_target_info *target,
         const struct image_extent size)
{
        const struct grid_info grid = {
                GL_FRAGMENT_SHADER_BIT,
                get_image_format(GL_RGBA32F),
                image_optimal_extent(size)
        };
        const struct image_info img = {
                target, grid.format, size,
                image_format_epsilon(grid.format)
        };
        GLuint prog = generate_program(
                grid, GL_FRAGMENT_SHADER,
                concat(image_hunk(img, ""),
                       hunk("readonly uniform IMAGE_T src_img;\n"
                            "writeonly uniform IMAGE_T dst_img;\n"
                            "\n"
                            "GRID_T op(ivec2 idx, GRID_T x) {\n"
                            "        imageStore(dst_img, IMAGE_ADDR(idx),"
                            "                imageLoad(src_img, IMAGE_ADDR(idx)));\n"
                            "        return x;\n"
                            "}\n"), NULL));
        bool ret = prog && init_fb(grid) &&
                init_image(img, 0) &&
                init_image(img, 1) &&
                set_uniform_int(prog, "src_img", 0) &&
                set_uniform_int(prog, "dst_img", 1)  &&
                draw_grid(grid, prog) &&
                check(img);

        glDeleteProgram(prog);
        return ret;
}
Example #3
0
int		main(int ac, char **av, char *envp[])
{
  t_vm	*vm;
  func	*instruct;

  if (ac == 1)
    return (my_printf("Usage: ./corewar[option] [option]champ.cor ...\n"));
  srand(time(NULL));
  if ((vm = create_struct_vm(ac, av)) != NULL)
    {
      instruct = get_ptr_func();
      if (envp[0] != NULL)
	{
	  if ((vm->image = init_image()) == NULL)
	    return (my_printf(
		   "Corewar: error: initialization pictures failed.\n"));
	  if ((vm->sound = init_sound()) == NULL)
	    return (my_printf(
		   "Corewar: error: initialization sounds failed.\n"));
	}
      vm->no_graph = rendering(vm);
      battle_ground(vm, instruct);
      if (vm->winner != NULL)
	return (my_printf("Le joueur %s(%d) a gagné.\n", vm->winner->prog_name,
			  vm->winner->data[ID]));
    }
  return (EXIT_SUCCESS);
}
Example #4
0
int		main(int argc, char **argv)
{
	t_img	*img;

	if (check_error(argc, argv[1]))
	{
		ft_putendl("Usage : ./fractol [Arg1]");
		ft_putendl("Arg1 being \"Julia\" or \"Mandelbrot\" or \"Ship\"");
		return (1);
	}
	if (!(img = init_image()))
		ft_mlx_error();
	if (argv[1][0] == 'm' || argv[1][0] == 'M')
		img->type = 'm';
	else if (argv[1][0] == 's' || argv[1][0] == 'S')
		img->type = 's';
	else if (argv[1][0] == 'j' || argv[1][0] == 'J')
		img->type = 'j';
	mlx_hook(img->win_ptr, 2, 1L << 8, grab_key, img);
	mlx_expose_hook(img->win_ptr, grab_expose, img);
	mlx_hook(img->win_ptr, MOTION_NOTIFY, POINTER_MOTION, motion_notify, img);
	mlx_mouse_hook(img->win_ptr, mouse_hook, img);
	mlx_loop(img->mlx_ptr);
	return (0);
}
Example #5
0
static bool
run_test(const struct image_op_info *op,
         unsigned w, unsigned h,
         bool (*check)(const struct grid_info grid,
                       const struct image_info img,
                       unsigned w, unsigned h),
         const char *body)
{
        const struct grid_info grid =
                grid_info(GL_FRAGMENT_SHADER, GL_R32UI, W, H);
        const struct image_info img = image_info_for_grid(grid);
        GLuint prog = generate_program(
                grid, GL_FRAGMENT_SHADER,
                concat(image_hunk(img, ""),
                       hunk("uniform IMAGE_T img;\n"),
                       hunk(op->hunk),
                       hunk(body), NULL));
        bool ret = prog &&
                init_fb(grid) &&
                init_image(img) &&
                set_uniform_int(prog, "img", 0) &&
                draw_grid(set_grid_size(grid, w, h), prog) &&
                check(grid, img, w, h);

        glDeleteProgram(prog);
        return ret;
}
Example #6
0
int main() {

  /* Provides a user interface for the fill algorithm. */

  char filename[BUFSIZ] ;
  int x, y, old_color, new_color ;

  printf( "Enter image file name. " ) ;
  scanf( "%s", filename ) ;
  if( init_image( filename ) == - 1 ) {
    printf( "Error initializing the image.\n" ) ;
    exit( 1 ) ;
  }

  while( TRUE ) {
    display_image() ;
    printf( "Enter the point at which the fill should start ( x, y ) : " ) ;
    scanf( "%d, %d", &x, &y ) ;
    if( ( x == -1 ) && ( y == -1 ) ) break ;

    old_color = read_pixel( x, y ) ;
    
    do {
      printf( "Pixel color is %d. Enter the new color: ", old_color ) ;
      scanf( "%d", &new_color ) ;
    
    } while( old_color == new_color || new_color < 0 || new_color > 9 ) ;
   
    fill( x, y, old_color, new_color ) ;
  }

  printf( "All done.\n" ) ;
  return 0 ;
}
Example #7
0
int pcx_load_image(const char *path, struct image *image)
{
    FILE *file;
    uint8_t *data = NULL;

    if (!(file = fopen(path, "rb"))) {
        error_errno("Opening file '%s' failed", path);
        goto failure;
    }

    uint8_t header[PCX_HEADER_SIZE];

    if (fread(header, PCX_HEADER_SIZE, 1, file) != 1) {
        error_errno("Reading PCX header from file '%s' failed", path);
        goto failure;
    }

    int width = read_le16(header + PCX_X2) - read_le16(header + PCX_X1) + 1;
    int height = read_le16(header + PCX_Y2) - read_le16(header + PCX_Y1) + 1;
    int size = width * height;

    data = xmalloc(size);

    uint8_t *p = data;
    int pixel, count;

    for (int i = 0; i < size; ) {
        if ((pixel = fgetc(file)) == EOF) {
            error_errno("Reading image data from file '%s' failed", path);
            goto failure;
        }
        if (pixel < 192) {
            *p++ = (uint8_t) pixel;
            i++;
        } else {
            count = pixel - 192;
            if ((pixel = fgetc(file)) == EOF) {
                error_errno("Reading image data from file '%s' failed", path);
                goto failure;
            }
            while (count-- > 0) {
                *p++ = (uint8_t) pixel;
                i++;
            }
        }
    }

    fclose(file);

    init_image(image, width, height, data);
    return 0;

failure:

    if (file)
        fclose(file);
    if (data)
        xfree(data);
    return -1;
}
Example #8
0
static bool
run_test(const struct image_qualifier_info *qual,
         const struct image_stage_info *stage_w,
         const struct image_stage_info *stage_r,
         unsigned l)
{
        const struct grid_info grid = {
                stage_w->bit | stage_r->bit,
                get_image_format(GL_RGBA32UI),
                { l, l, 1, 1 }
        };
        const struct image_info img = image_info_for_grid(grid);
        GLuint prog = generate_program(
                grid,
                /*
                 * Write (11, 22, 33, 44) to some location on the
                 * image from the write stage.
                 */
                stage_w->stage,
                concat(qualifier_hunk(qual),
                       image_hunk(img, ""),
                       hunk("IMAGE_Q uniform IMAGE_T img;\n"
                            "\n"
                            "GRID_T op(ivec2 idx, GRID_T x) {\n"
                            "       imageStore(img, idx, DATA_T(11, 22, 33, 44));"
                            "       return x;"
                            "}\n"), NULL),
                /*
                 * The same location will read back the expected value
                 * if image access is coherent, as the shader inputs
                 * of the read stage are dependent on the outputs of
                 * the write stage and consequently they are
                 * guaranteed to be executed sequentially.
                 */
                stage_r->stage,
                concat(qualifier_hunk(qual),
                       image_hunk(img, ""),
                       hunk("IMAGE_Q uniform IMAGE_T img;\n"
                            "\n"
                            "GRID_T op(ivec2 idx, GRID_T x) {\n"
                            "       DATA_T v = imageLoad(img, idx);"
                            "       if (v == DATA_T(11, 22, 33, 44))"
                            "             return GRID_T(33, 33, 33, 33);"
                            "       else"
                            "             return GRID_T(77, 77, 77, 77);"
                            "}\n"), NULL));
        bool ret = prog &&
                init_fb(grid) &&
                init_image(img) &&
                set_uniform_int(prog, "img", 0) &&
                draw_grid(grid, prog) &&
                (check(grid, img) || qual->control_test);

        glDeleteProgram(prog);
        return ret;
}
int main()
{
  printf("starting test\n");
  FILE* input = fopen("screenshot.bin", "rb");
  if(input == NULL)
  {
    printf("Couldn't find file\n");
    exit(1);
  }
  
  encoder_context* context = create_context();
  init_encoder(context, 1366, 768);
  init_codec(context);
  init_image(context);
  
  struct stat stat_info;
  int result = stat("screenshot.bin", &stat_info);
  if(result)
  {
    fatal("Could not fstat");
  }
  
  char* buffer = malloc(stat_info.st_size);
  fread(buffer, stat_info.st_size, 1, input);
  
  /*
  memset(buffer, 0xF, stat_info.st_size);
  
  int a;
  for(a = 0; a < stat_info.st_size; a++)
  {
    if(a % 4 == 0)
    {
      buffer[a] = 0x0;
    }
  }*/
  
  convert_frame(context, buffer);
  FILE* output = fopen("mem.bin", "wb");
  fwrite(context->raw->planes[2], 100000, 1, output);
  fflush(output);
  printf("Size is %d\n", context->raw->stride[3]);

  int i;
  for(i = 0; i < 100; i++)
  {
  convert_frame(context, buffer);
  
  encode_next_frame(context);
  }
  encode_finish(context);
  
  printf("Finished test\n");
}
Example #10
0
static void init_camera(int i)
{
    struct camera *c = get_camera(i);

    if (c->state == 0 && c->image)
    {
        /* The camera needs an offscreen render target.  Initialize it. */

        GLenum T = get_image_target(c->image);
        GLuint O = get_image_buffer(c->image);

        int w = get_image_w(c->image);
        int h = get_image_h(c->image);

        if (GL_has_framebuffer_object)
        {
            init_image(c->image);

            glGenFramebuffersEXT(1, &c->frame);
            glGenTextures       (1, &c->depth);

            /* Initialize the depth render target. */

            glBindTexture(T, c->depth);
            glTexImage2D(T, 0, GL_DEPTH_COMPONENT24, w, h, 0,
                         GL_DEPTH_COMPONENT, GL_INT, NULL);

            glTexParameteri(T, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            glTexParameteri(T, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            glTexParameteri(T, GL_TEXTURE_WRAP_S, GL_CLAMP);
            glTexParameteri(T, GL_TEXTURE_WRAP_T, GL_CLAMP);

            glTexParameteri(T, GL_DEPTH_TEXTURE_MODE_ARB,
                               GL_INTENSITY);
            glTexParameteri(T, GL_TEXTURE_COMPARE_MODE_ARB,
                               GL_COMPARE_R_TO_TEXTURE_ARB);

            /* Attach the framebuffer render targets. */

            opengl_push_framebuffer(c->frame);
            {
                glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
                                          GL_COLOR_ATTACHMENT0_EXT, T, O, 0);
                glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
                                          GL_DEPTH_ATTACHMENT_EXT, T,
                                          c->depth, 0);
            }
            opengl_pop_framebuffer();
        }
    }

    c->state = 1;
}
Example #11
0
Rbmp::Rbmp(const char* bmpname):bmppath(bmpname),pBmpBuf(NULL),pColorTable(NULL)
{
	//二进制读方式打开指定的图像文件
	fp = fopen(bmppath.c_str(),"rb");
	if(init_image())
		cout << "init bmp image is OK!" << endl;
	else
	{
		cout << "init bmp image is fair!" << endl;
		return;
	}
	cout << "create a Rbmp ....\n" << endl;
}
static void init(struct image_renderer *r, CAMERA camera) {
    struct state *state = (struct state *) r;

    // Historically it's in with annotation
    CONFIG_SECTION *sect = config_getSection("annotation");
    if (!sect)
        return;

    init_image(sect, &state->thumbnail, "thumbnail");

    // If thumbnail is defined then enable it
    state->enabled = state->thumbnail.enabled;
}
Example #13
0
/* The main host program controlling and representing the whole
   application */
int main(int argc, char* argv[]) {
  int image[HEIGHT][WIDTH];
  unsigned char output[HEIGHT][WIDTH];

  // Initialize with some values
  init_image(WIDTH, HEIGHT, image);

  // Draw 70 horizontal lines and map operation on 8 PEs:
#pragma omp parallel for num_threads(8)
  for(int proc = 0; proc < 70; proc++)
    // Each iteration is on a different PE in parallel:
#pragma smecy map(PE, proc & 7)			\
              arg(2, in, [1][LINE_SIZE])	\
              arg(3, out, [1][LINE_SIZE])
    // Invert an horizontal line:
    invert_vector(LINE_SIZE,
		  &image[HEIGHT - 20 - proc][WIDTH/2 + 2*proc],
		  &image[HEIGHT - 20 - proc][WIDTH/2 + 2*proc]);

  /* Here we guess we have 5 hardware accelerators and we launch
     operations on them: */
#pragma omp parallel for num_threads(5)
  for(int proc = 0; proc < 5; proc++) {
    /* This is need to express the fact that our accelerator only accept
       continuous data but we want apply them on non contiguous data in
       the array */
    int input_line[LINE_SIZE];
    int output_line[LINE_SIZE];
    /* We need to remap data in the good shape. The compiler should use
       the remapping information to generate DMA transfer for example and
       remove input_line array */
    SMECY_remap_int2D_to_int1D(HEIGHT, WIDTH, HEIGHT/3, 30 + 20*proc,
			       LINE_SIZE, 1, image,
			       LINE_SIZE, input_line);
    // Each iteration is on a different PE in parallel:
#pragma smecy map(PE, proc) arg(2, in, [LINE_SIZE]) arg(3, out, [LINE_SIZE])
    invert_vector(LINE_SIZE, input_line, output_line);
    SMECY_remap_int1D_to_int2D(LINE_SIZE, output_line,
			       HEIGHT, WIDTH, HEIGHT/3, 30 + 20*proc,
			       LINE_SIZE, 1, image);
  }

  // Convert int image to char image:
  normalize_to_char(WIDTH, HEIGHT, image, output);

  write_pgm_image("remapping_example-output.pgm", WIDTH, HEIGHT, output);

  return EXIT_SUCCESS;
}
Example #14
0
Substim *NewImage(Stimulus *st, Substim *sst)
{
    Locator *pos = &st->pos;/*j*/
  
    FreeStimulus(sst);
    if(sst->ptr == NULL)
      sst->ptr = (OneStim *) (malloc(sizeof(OneStim)));
    if(verbose)
      printf("New Image addr %d\n",sst->ptr);
//    sst->uimage = NULL;
    init_image(st,sst);
    st->type = STIM_IMAGE;
    sst->type = STIM_IMAGE;
    return(sst);
}
Example #15
0
static bool
run_test(const struct image_qualifier_info *qual)
{
        const struct grid_info grid =
                grid_info(GL_FRAGMENT_SHADER, GL_R32UI, W, H);
        const struct image_info img =
                image_info(GL_TEXTURE_1D, GL_R32UI, W, H);
        GLuint prog = generate_program(
                grid,
                /**
                 * Write to consecutive locations of an image using a
                 * the value read from a fixed location of a different
                 * image uniform which aliases the first image.  If
                 * the implementation incorrectly coalesces repeated
                 * loads from the fixed location the results of the
                 * test will be altered.
                 */
                GL_FRAGMENT_SHADER,
                concat(qualifier_hunk(qual),
                       image_hunk(img, ""),
                       hunk("IMAGE_Q IMAGE_UNIFORM_T src_img;\n"
                            "IMAGE_Q IMAGE_UNIFORM_T dst_img;\n"
                            "\n"
                            "GRID_T op(ivec2 idx, GRID_T x) {\n"
                            "        int i;\n"
                            "\n"
                            "        for (i = 0; i < N / 2; ++i) {\n"
                            "                imageStore(dst_img, 2 * i,"
                            "                           imageLoad(src_img, W) + 1u);\n"
                            "                imageStore(dst_img, 2 * i + 1,"
                            "                           imageLoad(src_img, W) - 1u);\n"
                            "        }\n"
                            "\n"
                            "        return x;\n"
                            "}\n"), NULL));
        bool ret = prog &&
                init_fb(grid) &&
                init_image(img) &&
                set_uniform_int(prog, "src_img", 0) &&
                set_uniform_int(prog, "dst_img", 0) &&
                draw_grid(set_grid_size(grid, 1, 1), prog) &&
                (check(img) || qual->control_test);

        glDeleteProgram(prog);
        return ret;
}
Example #16
0
void
refresh_image(ModeInfo * mi)
{
#ifdef HAVE_XPM
	imagestruct *ip;

	if (ims == NULL)
		return;
	ip = &ims[MI_SCREEN(mi)];
	if (ip->icons == NULL)
		return;
	if (ip->graphics_format >= IS_XPM) {
		/* This is needed when another program changes the colormap. */
		free_image(MI_DISPLAY(mi), ip);
		init_image(mi);
		return;
	}
#endif
	drawImages(mi);
}
Example #17
0
/**
 * Test skeleton: Init image to \a init_value, run the provided shader
 * \a op and check that the resulting image pixels equal \a
 * check_value.
 */
static bool
run_test(uint32_t init_value, uint32_t check_value,
         const char *op)
{
        const struct grid_info grid =
                grid_info(GL_FRAGMENT_SHADER, GL_R32UI, W, H);
        const struct image_info img = image_info_for_grid(grid);
        GLuint prog = generate_program(
                grid, GL_FRAGMENT_SHADER,
                concat(image_hunk(img, ""),
                       hunk("uniform IMAGE_T img;\n"),
                       hunk(op), NULL));
        bool ret = prog &&
                init_fb(grid) &&
                init_image(img, init_value) &&
                set_uniform_int(prog, "img", 0) &&
                draw_grid(grid, prog) &&
                check(img, check_value);

        glDeleteProgram(prog);
        return ret;
}
Example #18
0
/**
 * @brief dessine un losange au centre de l'image
 * 
 * @param height hauteur de l'image
 * @param width largeur de l'image
 * @param diagonal longueur de la diagonal du losange
 * @return image
 */
Image diamond(int height, int width, int diagonal) {
	Image i = init_image(height, width);

	if(diagonal != 0) { //si diagonal = 0, on ne dessine rien
		int centre_x = width/2;
		int centre_y = height/2;

		for(int j = 0; j < centre_y + 1; ++j) {   //calcul de la première moitié du losange par la formule
			int bord = j - centre_y + diagonal/2;
			for (int k = centre_x-bord; k <= centre_x + bord; ++k) {
				i.content[j][k] = 1.0;
			}
		}

		for(int j = centre_y; j < height; ++j) { //calcul de la deuxième moitié par symétrie
			for(int k = 0; k < width; ++k) {
				i.content[j][k] = i.content[height-1-j][k];
			}
		}
	}

	return i;
}
Example #19
0
/**
 * If \a layered is false, bind an individual layer of a texture to an
 * image unit, read its contents and write back a different value to
 * the same location.  If \a layered is true or the texture has a
 * single layer, the whole texture will be read and written back.
 *
 * For textures with a single layer, the arguments \a layered and \a
 * layer which are passed to the same arguments of
 * glBindImageTexture() should have no effect as required by the spec.
 */
static bool
run_test(const struct image_target_info *target,
         bool layered, unsigned layer)
{
        const struct image_info real_img = image_info(
                target->target, GL_RGBA32F, W, H);
        const unsigned slices = (layered ? 1 : image_num_layers(real_img));
        /*
         * "Slice" of the image that will be bound to the pipeline.
         */
        const struct image_info slice_img = image_info(
                (layered ? target->target : image_layer_target(target)),
                GL_RGBA32F, W, H / slices);
        /*
         * Grid with as many elements as the slice.
         */
        const struct grid_info grid = grid_info(
                GL_FRAGMENT_SHADER, GL_RGBA32F, W, H / slices);
        GLuint prog = generate_program(
                grid, GL_FRAGMENT_SHADER,
                concat(image_hunk(slice_img, ""),
                       hunk("IMAGE_UNIFORM_T img;\n"
                            "\n"
                            "GRID_T op(ivec2 idx, GRID_T x) {\n"
                            "        GRID_T v = imageLoad(img, IMAGE_ADDR(idx));\n"
                            "        imageStore(img, IMAGE_ADDR(idx), DATA_T(33));\n"
                            "        return v;\n"
                            "}\n"), NULL));
        bool ret = prog && init_fb(grid) &&
                init_image(real_img, layered, layer) &&
                set_uniform_int(prog, "img", 0) &&
                draw_grid(grid, prog) &&
                check(grid, real_img, (slices == 1 ? 0 : layer));

        glDeleteProgram(prog);
        return ret;
}
Example #20
0
static int decode_frame(AVCodecContext *avctx,
                        void *data, int *got_frame, AVPacket *avpkt)
{
    TiffContext *const s = avctx->priv_data;
    AVFrame *const p = data;
    ThreadFrame frame = { .f = data };
    unsigned off;
    int le, ret, plane, planes;
    int i, j, entries, stride;
    unsigned soff, ssize;
    uint8_t *dst;
    GetByteContext stripsizes;
    GetByteContext stripdata;

    bytestream2_init(&s->gb, avpkt->data, avpkt->size);

    // parse image header
    if ((ret = ff_tdecode_header(&s->gb, &le, &off))) {
        av_log(avctx, AV_LOG_ERROR, "Invalid TIFF header\n");
        return ret;
    } else if (off >= UINT_MAX - 14 || avpkt->size < off + 14) {
        av_log(avctx, AV_LOG_ERROR, "IFD offset is greater than image size\n");
        return AVERROR_INVALIDDATA;
    }
    s->le          = le;
    // TIFF_BPP is not a required tag and defaults to 1
    s->bppcount    = s->bpp = 1;
    s->photometric = TIFF_PHOTOMETRIC_NONE;
    s->compr       = TIFF_RAW;
    s->fill_order  = 0;
    free_geotags(s);

    // Reset these offsets so we can tell if they were set this frame
    s->stripsizesoff = s->strippos = 0;
    /* parse image file directory */
    bytestream2_seek(&s->gb, off, SEEK_SET);
    entries = ff_tget_short(&s->gb, le);
    if (bytestream2_get_bytes_left(&s->gb) < entries * 12)
        return AVERROR_INVALIDDATA;
    for (i = 0; i < entries; i++) {
        if ((ret = tiff_decode_tag(s, p)) < 0)
            return ret;
    }

    for (i = 0; i<s->geotag_count; i++) {
        const char *keyname = get_geokey_name(s->geotags[i].key);
        if (!keyname) {
            av_log(avctx, AV_LOG_WARNING, "Unknown or unsupported GeoTIFF key %d\n", s->geotags[i].key);
            continue;
        }
        if (get_geokey_type(s->geotags[i].key) != s->geotags[i].type) {
            av_log(avctx, AV_LOG_WARNING, "Type of GeoTIFF key %d is wrong\n", s->geotags[i].key);
            continue;
        }
        ret = av_dict_set(avpriv_frame_get_metadatap(p), keyname, s->geotags[i].val, 0);
        if (ret<0) {
            av_log(avctx, AV_LOG_ERROR, "Writing metadata with key '%s' failed\n", keyname);
            return ret;
        }
    }

    if (!s->strippos && !s->stripoff) {
        av_log(avctx, AV_LOG_ERROR, "Image data is missing\n");
        return AVERROR_INVALIDDATA;
    }
    /* now we have the data and may start decoding */
    if ((ret = init_image(s, &frame)) < 0)
        return ret;

    if (s->strips == 1 && !s->stripsize) {
        av_log(avctx, AV_LOG_WARNING, "Image data size missing\n");
        s->stripsize = avpkt->size - s->stripoff;
    }

    if (s->stripsizesoff) {
        if (s->stripsizesoff >= (unsigned)avpkt->size)
            return AVERROR_INVALIDDATA;
        bytestream2_init(&stripsizes, avpkt->data + s->stripsizesoff,
                         avpkt->size - s->stripsizesoff);
    }
    if (s->strippos) {
        if (s->strippos >= (unsigned)avpkt->size)
            return AVERROR_INVALIDDATA;
        bytestream2_init(&stripdata, avpkt->data + s->strippos,
                         avpkt->size - s->strippos);
    }

    if (s->rps <= 0) {
        av_log(avctx, AV_LOG_ERROR, "rps %d invalid\n", s->rps);
        return AVERROR_INVALIDDATA;
    }

    planes = s->planar ? s->bppcount : 1;
    for (plane = 0; plane < planes; plane++) {
        stride = p->linesize[plane];
        dst    = p->data[plane];
    for (i = 0; i < s->height; i += s->rps) {
        if (s->stripsizesoff)
            ssize = ff_tget(&stripsizes, s->sstype, le);
        else
            ssize = s->stripsize;

        if (s->strippos)
            soff = ff_tget(&stripdata, s->sot, le);
        else
            soff = s->stripoff;

        if (soff > avpkt->size || ssize > avpkt->size - soff) {
            av_log(avctx, AV_LOG_ERROR, "Invalid strip size/offset\n");
            return AVERROR_INVALIDDATA;
        }
        if ((ret = tiff_unpack_strip(s, p, dst, stride, avpkt->data + soff, ssize, i,
                                     FFMIN(s->rps, s->height - i))) < 0) {
            if (avctx->err_recognition & AV_EF_EXPLODE)
                return ret;
            break;
        }
        dst += s->rps * stride;
    }
    if (s->predictor == 2) {
        if (s->photometric == TIFF_PHOTOMETRIC_YCBCR) {
            av_log(s->avctx, AV_LOG_ERROR, "predictor == 2 with YUV is unsupported");
            return AVERROR_PATCHWELCOME;
        }
        dst   = p->data[plane];
        soff  = s->bpp >> 3;
        if (s->planar)
            soff  = FFMAX(soff / s->bppcount, 1);
        ssize = s->width * soff;
        if (s->avctx->pix_fmt == AV_PIX_FMT_RGB48LE ||
            s->avctx->pix_fmt == AV_PIX_FMT_RGBA64LE ||
            s->avctx->pix_fmt == AV_PIX_FMT_GBRP16LE ||
            s->avctx->pix_fmt == AV_PIX_FMT_GBRAP16LE) {
            for (i = 0; i < s->height; i++) {
                for (j = soff; j < ssize; j += 2)
                    AV_WL16(dst + j, AV_RL16(dst + j) + AV_RL16(dst + j - soff));
                dst += stride;
            }
        } else if (s->avctx->pix_fmt == AV_PIX_FMT_RGB48BE ||
                   s->avctx->pix_fmt == AV_PIX_FMT_RGBA64BE ||
                   s->avctx->pix_fmt == AV_PIX_FMT_GBRP16BE ||
                   s->avctx->pix_fmt == AV_PIX_FMT_GBRAP16BE) {
            for (i = 0; i < s->height; i++) {
                for (j = soff; j < ssize; j += 2)
                    AV_WB16(dst + j, AV_RB16(dst + j) + AV_RB16(dst + j - soff));
                dst += stride;
            }
        } else {
            for (i = 0; i < s->height; i++) {
                for (j = soff; j < ssize; j++)
                    dst[j] += dst[j - soff];
                dst += stride;
            }
        }
    }

    if (s->photometric == TIFF_PHOTOMETRIC_WHITE_IS_ZERO) {
        dst = p->data[plane];
        for (i = 0; i < s->height; i++) {
            for (j = 0; j < p->linesize[plane]; j++)
                dst[j] = (s->avctx->pix_fmt == AV_PIX_FMT_PAL8 ? (1<<s->bpp) - 1 : 255) - dst[j];
            dst += stride;
        }
    }
    }

    if (s->planar && s->bppcount > 2) {
        FFSWAP(uint8_t*, p->data[0],     p->data[2]);
        FFSWAP(int,      p->linesize[0], p->linesize[2]);
        FFSWAP(uint8_t*, p->data[0],     p->data[1]);
        FFSWAP(int,      p->linesize[0], p->linesize[1]);
    }
Example #21
0
int main(int argc, char *argv[])
{
   char buf[256];
   PALETTE pal;
   BITMAP *image;
   BITMAP *page[2];
   BITMAP *vimage;
   IMAGE images[MAX_IMAGES];
   int num_images = 4;
   int page_num = 1;
   int done = FALSE;
   int i;

   if (allegro_init() != 0)
      return 1;
   install_keyboard(); 
   install_timer();

   /* see comments in exflip.c */
#ifdef ALLEGRO_VRAM_SINGLE_SURFACE
   if (set_gfx_mode(GFX_AUTODETECT, 1024, 768, 0, 2 * 768 + 200) != 0) {
#else
   if (set_gfx_mode(GFX_AUTODETECT, 1024, 768, 0, 0) != 0) {
#endif
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error setting graphics mode\n%s\n", allegro_error);
      return 1;
   }

   /* read in the source graphic */
   replace_filename(buf, argv[0], "mysha.pcx", sizeof(buf));
   image = load_bitmap(buf, pal);
   if (!image) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error reading %s!\n", buf);
      return 1;
   }

   set_palette(pal);

   /* initialise the images to random positions */
   for (i=0; i<MAX_IMAGES; i++)
      init_image(images+i);

   /* create two video memory bitmaps for page flipping */
   page[0] = create_video_bitmap(SCREEN_W, SCREEN_H);
   page[1] = create_video_bitmap(SCREEN_W, SCREEN_H);

   /* create a video memory bitmap to store our picture */
   vimage = create_video_bitmap(image->w, image->h);

   if ((!page[0]) || (!page[1]) || (!vimage)) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Not enough video memory (need two 1024x768 pages "
		      "and a 320x200 image)\n");
      return 1;
   }

   /* copy the picture into offscreen video memory */
   blit(image, vimage, 0, 0, 0, 0, image->w, image->h);

   while (!done) {
      acquire_bitmap(page[page_num]);

      /* clear the screen */
      clear_bitmap(page[page_num]);

      /* draw onto it */
      for (i=0; i<num_images; i++)
	 blit(vimage, page[page_num], 0, 0, images[i].x, images[i].y,
	      vimage->w, vimage->h);

      textprintf_ex(page[page_num], font, 0, 0, 255, -1,
		    "Images: %d (arrow keys to change)", num_images);

      /* tell the user which functions are being done in hardware */
      if (gfx_capabilities & GFX_HW_FILL)
	 textout_ex(page[page_num], font, "Clear: hardware accelerated",
		    0, 16, 255, -1);
      else
	 textout_ex(page[page_num], font, "Clear: software (urgh, this "
		    "is not good!)", 0, 16, 255, -1);

      if (gfx_capabilities & GFX_HW_VRAM_BLIT)
	 textout_ex(page[page_num], font, "Blit: hardware accelerated",
		    0, 32, 255, -1);
      else
	 textout_ex(page[page_num], font, "Blit: software (urgh, this program "
		    "will run too sloooooowly without hardware acceleration!)",
		    0, 32, 255, -1);

      release_bitmap(page[page_num]);

      /* page flip */
      show_video_bitmap(page[page_num]);
      page_num = 1-page_num;

      /* deal with keyboard input */
      while (keypressed()) {
	 switch (readkey()>>8) {

	    case KEY_UP:
	    case KEY_RIGHT:
	       if (num_images < MAX_IMAGES)
		  num_images++;
	       break;

	    case KEY_DOWN:
	    case KEY_LEFT:
	       if (num_images > 0)
		  num_images--;
	       break;

	    case KEY_ESC:
	       done = TRUE;
	       break;
	 }
      }

      /* bounce the images around the screen */
      for (i=0; i<num_images; i++)
	 update_image(images+i);
   }

   destroy_bitmap(image);
   destroy_bitmap(vimage);
   destroy_bitmap(page[0]);
   destroy_bitmap(page[1]);

   return 0;
}

END_OF_MAIN()
Example #22
0
void init_display(  )
{
	XClassHint       classHint;
	XTextProperty    name;
	XGCValues        gcv;
	unsigned long    gcm;
	int              dummy=0;
	char           * progname = PROGNAME;
	
	Pixel            back_pix;
	Pixel            fore_pix;

	display = XOpenDisplay( args_XDisplayName );
	
	if( display == NULL )
	{
		fprintf(stderr, "Can't open display\n" );
		free_and_exit( ERROR );
	}
	
	screen  = DefaultScreen(display);
	Root    = RootWindow(display, screen);
	d_depth = DefaultDepth(display, screen);
	x_fd    = XConnectionNumber(display);

	
	init_image ( );
	
	/* Create a window to hold the stuff */
	mysizehints.flags = USSize | USPosition;
	mysizehints.x = 0;
	mysizehints.y = 0;
	

	back_pix = WhitePixel( display, screen);
	fore_pix = BlackPixel( display, screen);

	XWMGeometry(display, screen, NULL, NULL, 1, &mysizehints, \
	            &mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy);
	
	mysizehints.width = 64;
	mysizehints.height = 64;
		
	win = XCreateSimpleWindow(display, Root, mysizehints.x, mysizehints.y, \
	                          mysizehints.width, mysizehints.height, 1, fore_pix, back_pix);
	
	iconwin = XCreateSimpleWindow(display, win, mysizehints.x, mysizehints.y, \
	                              mysizehints.width, mysizehints.height, 1, fore_pix, back_pix);

	/* Activate hints */
	XSetWMNormalHints(display, win, &mysizehints);
	classHint.res_name = progname;
	classHint.res_class = progname;
	XSetClassHint(display, win, &classHint);

	XSelectInput(display, win, ButtonPressMask | ButtonReleaseMask | ExposureMask | StructureNotifyMask );
	XSelectInput(display, iconwin, ButtonPressMask | ButtonReleaseMask | ExposureMask | StructureNotifyMask );

	if (XStringListToTextProperty(&progname, 1, &name) == 0)
		PRINTQ(stderr, "%s: can't allocate window name\n", PROGNAME);
	

	XSetWMName(display, win, &name);
	
	/* Create GC for drawing */
	
	gcm = GCForeground | GCBackground | GCGraphicsExposures;
	gcv.foreground = fore_pix;
	gcv.background = back_pix;
	gcv.graphics_exposures = 0;
	NormalGC = XCreateGC(display, Root, gcm, &gcv);

	/* ONLYSHAPE ON */
	
	pixmask = XCreateBitmapFromData(display, win, wmlaptop_mask_bits, wmlaptop_mask_width, wmlaptop_mask_height);

	XShapeCombineMask(display, win, ShapeBounding, 0, 0, pixmask, ShapeSet);
	XShapeCombineMask(display, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet);
	
	/* ONLYSHAPE OFF */

	mywmhints.initial_state = WithdrawnState;
	mywmhints.icon_window = iconwin;
	mywmhints.icon_x = mysizehints.x;
	mywmhints.icon_y = mysizehints.y;
	mywmhints.window_group = win;
	mywmhints.flags = StateHint | IconWindowHint | IconPositionHint | WindowGroupHint;

	XSetWMHints(display, win, &mywmhints);
	
	XMapWindow(display, win);
	
	
}
int sample_main(int argc, char *argv[]) {
    VkResult U_ASSERT_ONLY res;
    struct sample_info info = {};
    char sample_title[] = "Separate Image Sampler";
    const bool depthPresent = true;

    process_command_line_args(info, argc, argv);
    init_global_layer_properties(info);
    init_instance_extension_names(info);
    init_device_extension_names(info);
    init_instance(info, sample_title);
    init_enumerate_device(info);
    init_window_size(info, 500, 500);
    init_connection(info);
    init_window(info);
    init_swapchain_extension(info);
    init_device(info);
    init_command_pool(info);
    init_command_buffer(info);
    execute_begin_command_buffer(info);
    init_device_queue(info);
    init_swap_chain(info);
    init_depth_buffer(info);
    init_uniform_buffer(info);
    init_renderpass(info, depthPresent);
    init_shaders(info, vertShaderText, fragShaderText);
    init_framebuffers(info, depthPresent);
    init_vertex_buffer(info, g_vb_texture_Data, sizeof(g_vb_texture_Data), sizeof(g_vb_texture_Data[0]), true);

    /* VULKAN_KEY_START */

    // Sample from a green texture to easily see that we've pulled correct texel
    // value

    // Create our separate image
    struct texture_object texObj;
    const char *textureName = "green.ppm";
    init_image(info, texObj, textureName);

    info.textures.push_back(texObj);

    info.texture_data.image_info.sampler = 0;
    info.texture_data.image_info.imageView = info.textures[0].view;
    info.texture_data.image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;

    // Create our separate sampler
    VkSampler separateSampler = {};
    init_sampler(info, separateSampler);

    VkDescriptorImageInfo samplerInfo = {};
    samplerInfo.sampler = separateSampler;

    // Set up one descriptor set
    static const unsigned descriptor_set_count = 1;
    static const unsigned resource_count = 3;
    static const unsigned resource_type_count = 3;

    // Create binding and layout for the following, matching contents of shader
    //   binding 0 = uniform buffer (MVP)
    //   binding 1 = texture2D
    //   binding 2 = sampler

    VkDescriptorSetLayoutBinding resource_binding[resource_count] = {};
    resource_binding[0].binding = 0;
    resource_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
    resource_binding[0].descriptorCount = 1;
    resource_binding[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
    resource_binding[0].pImmutableSamplers = NULL;
    resource_binding[1].binding = 1;
    resource_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
    resource_binding[1].descriptorCount = 1;
    resource_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
    resource_binding[1].pImmutableSamplers = NULL;
    resource_binding[2].binding = 2;
    resource_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
    resource_binding[2].descriptorCount = 1;
    resource_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
    resource_binding[2].pImmutableSamplers = NULL;

    VkDescriptorSetLayoutCreateInfo resource_layout_info[1] = {};
    resource_layout_info[0].sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
    resource_layout_info[0].pNext = NULL;
    resource_layout_info[0].bindingCount = resource_count;
    resource_layout_info[0].pBindings = resource_binding;

    VkDescriptorSetLayout descriptor_layouts[1] = {};
    res = vkCreateDescriptorSetLayout(info.device, resource_layout_info, NULL, &descriptor_layouts[0]);

    assert(res == VK_SUCCESS);

    // Create pipeline layout
    VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo[1] = {};
    pipelineLayoutCreateInfo[0].sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
    pipelineLayoutCreateInfo[0].pNext = NULL;
    pipelineLayoutCreateInfo[0].pushConstantRangeCount = 0;
    pipelineLayoutCreateInfo[0].pPushConstantRanges = NULL;
    pipelineLayoutCreateInfo[0].setLayoutCount = descriptor_set_count;
    pipelineLayoutCreateInfo[0].pSetLayouts = descriptor_layouts;
    res = vkCreatePipelineLayout(info.device, pipelineLayoutCreateInfo, NULL, &info.pipeline_layout);
    assert(res == VK_SUCCESS);

    // Create a single pool to contain data for our descriptor set
    VkDescriptorPoolSize pool_sizes[resource_type_count] = {};
    pool_sizes[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
    pool_sizes[0].descriptorCount = 1;
    pool_sizes[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
    pool_sizes[1].descriptorCount = 1;
    pool_sizes[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
    pool_sizes[2].descriptorCount = 1;

    VkDescriptorPoolCreateInfo pool_info[1] = {};
    pool_info[0].sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
    pool_info[0].pNext = NULL;
    pool_info[0].maxSets = descriptor_set_count;
    pool_info[0].poolSizeCount = resource_type_count;
    pool_info[0].pPoolSizes = pool_sizes;

    VkDescriptorPool descriptor_pool[1] = {};
    res = vkCreateDescriptorPool(info.device, pool_info, NULL, descriptor_pool);
    assert(res == VK_SUCCESS);

    VkDescriptorSetAllocateInfo alloc_info[1];
    alloc_info[0].sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
    alloc_info[0].pNext = NULL;
    alloc_info[0].descriptorPool = descriptor_pool[0];
    alloc_info[0].descriptorSetCount = descriptor_set_count;
    alloc_info[0].pSetLayouts = descriptor_layouts;

    // Populate descriptor sets
    VkDescriptorSet descriptor_sets[descriptor_set_count] = {};
    res = vkAllocateDescriptorSets(info.device, alloc_info, descriptor_sets);
    assert(res == VK_SUCCESS);

    VkWriteDescriptorSet descriptor_writes[resource_count];

    // Populate with info about our uniform buffer for MVP
    descriptor_writes[0] = {};
    descriptor_writes[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
    descriptor_writes[0].pNext = NULL;
    descriptor_writes[0].dstSet = descriptor_sets[0];
    descriptor_writes[0].descriptorCount = 1;
    descriptor_writes[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
    descriptor_writes[0].pBufferInfo = &info.uniform_data.buffer_info;  // populated by init_uniform_buffer()
    descriptor_writes[0].dstArrayElement = 0;
    descriptor_writes[0].dstBinding = 0;

    // Populate with info about our image
    descriptor_writes[1] = {};
    descriptor_writes[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
    descriptor_writes[1].pNext = NULL;
    descriptor_writes[1].dstSet = descriptor_sets[0];
    descriptor_writes[1].descriptorCount = 1;
    descriptor_writes[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
    descriptor_writes[1].pImageInfo = &info.texture_data.image_info;  // populated by init_texture()
    descriptor_writes[1].dstArrayElement = 0;
    descriptor_writes[1].dstBinding = 1;

    // Populate with info about our sampler
    descriptor_writes[2] = {};
    descriptor_writes[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
    descriptor_writes[2].pNext = NULL;
    descriptor_writes[2].dstSet = descriptor_sets[0];
    descriptor_writes[2].descriptorCount = 1;
    descriptor_writes[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
    descriptor_writes[2].pImageInfo = &samplerInfo;
    descriptor_writes[2].dstArrayElement = 0;
    descriptor_writes[2].dstBinding = 2;

    vkUpdateDescriptorSets(info.device, resource_count, descriptor_writes, 0, NULL);

    /* VULKAN_KEY_END */

    init_pipeline_cache(info);
    init_pipeline(info, depthPresent);
    init_presentable_image(info);

    VkClearValue clear_values[2];
    init_clear_color_and_depth(info, clear_values);

    VkRenderPassBeginInfo rp_begin;
    init_render_pass_begin_info(info, rp_begin);
    rp_begin.clearValueCount = 2;
    rp_begin.pClearValues = clear_values;

    vkCmdBeginRenderPass(info.cmd, &rp_begin, VK_SUBPASS_CONTENTS_INLINE);

    vkCmdBindPipeline(info.cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, info.pipeline);
    vkCmdBindDescriptorSets(info.cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, info.pipeline_layout, 0, NUM_DESCRIPTOR_SETS,
                            descriptor_sets, 0, NULL);

    const VkDeviceSize offsets[1] = {0};
    vkCmdBindVertexBuffers(info.cmd, 0, 1, &info.vertex_buffer.buf, offsets);

    init_viewports(info);
    init_scissors(info);

    vkCmdDraw(info.cmd, 12 * 3, 1, 0, 0);
    vkCmdEndRenderPass(info.cmd);
    res = vkEndCommandBuffer(info.cmd);
    assert(res == VK_SUCCESS);

    VkFence drawFence = {};
    init_fence(info, drawFence);
    VkPipelineStageFlags pipe_stage_flags = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
    VkSubmitInfo submit_info = {};
    init_submit_info(info, submit_info, pipe_stage_flags);

    /* Queue the command buffer for execution */
    res = vkQueueSubmit(info.graphics_queue, 1, &submit_info, drawFence);
    assert(res == VK_SUCCESS);

    /* Now present the image in the window */
    VkPresentInfoKHR present = {};
    init_present_info(info, present);

    /* Make sure command buffer is finished before presenting */
    do {
        res = vkWaitForFences(info.device, 1, &drawFence, VK_TRUE, FENCE_TIMEOUT);
    } while (res == VK_TIMEOUT);
    assert(res == VK_SUCCESS);
    res = vkQueuePresentKHR(info.present_queue, &present);
    assert(res == VK_SUCCESS);

    wait_seconds(1);
    if (info.save_images) write_ppm(info, "separate_image_sampler");

    vkDestroyFence(info.device, drawFence, NULL);
    vkDestroySemaphore(info.device, info.imageAcquiredSemaphore, NULL);
    destroy_pipeline(info);
    destroy_pipeline_cache(info);

    vkDestroySampler(info.device, separateSampler, NULL);
    vkDestroyImageView(info.device, info.textures[0].view, NULL);
    vkDestroyImage(info.device, info.textures[0].image, NULL);
    vkFreeMemory(info.device, info.textures[0].mem, NULL);

    // instead of destroy_descriptor_pool(info);
    vkDestroyDescriptorPool(info.device, descriptor_pool[0], NULL);

    destroy_vertex_buffer(info);
    destroy_framebuffers(info);
    destroy_shaders(info);
    destroy_renderpass(info);

    // instead of destroy_descriptor_and_pipeline_layouts(info);
    for (int i = 0; i < descriptor_set_count; i++) vkDestroyDescriptorSetLayout(info.device, descriptor_layouts[i], NULL);
    vkDestroyPipelineLayout(info.device, info.pipeline_layout, NULL);

    destroy_uniform_buffer(info);
    destroy_depth_buffer(info);
    destroy_swap_chain(info);
    destroy_command_buffer(info);
    destroy_command_pool(info);
    destroy_device(info);
    destroy_window(info);
    destroy_instance(info);
    return 0;
}
Example #24
0
void init_exit_menu(exit_menu_t *state, gl_t *gl_state)
{
    // Initialize program launcher images OpenGL state
    int image_width = gl_state->screen_width/3.84;
    int image_height = gl_state->screen_height/3.846;

    float half_height = (image_height/(float)gl_state->screen_height);
    float half_width = (image_width/(float)gl_state->screen_width);

    float dx = (2.0f-(3.0*2.0f*half_width))/4.0f;

    float lower_left_y = -half_height;
    float lower_left_x = -1.0f + dx;
    state->mandelbrot_state = malloc(sizeof(image_t));

    #ifdef RASPI
    init_image(state->mandelbrot_state,
               gl_state,
               "SPH/images/mandelbrot.png",
               "SPH/images/mandelbrot-selected.png",
               lower_left_x, lower_left_y,
               image_width, image_height);
    #else
    init_image(state->mandelbrot_state,
               gl_state,
               "images/mandelbrot.png",
               "images/mandelbrot-selected.png",
               lower_left_x, lower_left_y,
               image_width, image_height);
    #endif

    lower_left_x += 2.0f*half_width + dx;
    state->terminal_state = malloc(sizeof(image_t));
    #ifdef RASPI
    init_image(state->terminal_state,
               gl_state,
               "SPH/images/terminal.png",
               "SPH/images/terminal-selected.png",
               lower_left_x, lower_left_y,
               image_width, image_height);
    #else
    init_image(state->terminal_state,
               gl_state,
               "images/terminal.png",
               "images/terminal-selected.png",
               lower_left_x, lower_left_y,
               image_width, image_height);
    #endif

    lower_left_x += 2.0f*half_width + dx;
    state->sph_state = malloc(sizeof(image_t));
    #ifdef RASPI
    init_image(state->sph_state,
               gl_state,
               "SPH/images/sph.png",
               "SPH/images/sph-selected.png",
               lower_left_x, lower_left_y,
               image_width, image_height);
    #else
    init_image(state->sph_state,
               gl_state,
               "images/sph.png",
               "images/sph-selected.png",
               lower_left_x, lower_left_y,
               image_width, image_height);
    #endif

    // Initialize cursor
    state->cursor_state = malloc(sizeof(cursor_t));
    int cursor_width = gl_state->screen_width/16.0;
    int cursor_height = gl_state->screen_height/7.5;

    #ifdef RASPI
    init_cursor(state->cursor_state, gl_state, "SPH/images/cursor.png", cursor_width, cursor_height);
    #else
    init_cursor(state->cursor_state, gl_state, "images/cursor.png", cursor_width, cursor_height); 
    #endif

    // Initialize cursor
    state->rectangle_state = malloc(sizeof(rectangle_t));
    init_rectangle(state->rectangle_state);
}
Example #25
0
/**
 * @brief Prend un nom de fichier, lit l'image du fichier et la retourne.
 * 
 * @param filename nom du fichier source
 * @return l'image contenue dans le fichier
 */
Image read_from_file(char* filename) {
	FILE* input = NULL;
	input = fopen(filename, "r");
	int erreur = 0;
	Image image;

	if (input == NULL) {
		fprintf(stderr, "Erreur: impossible de lire le fichier %s\n", filename);
	} else {
		int width = 0;
		int height = 0;

		int j = fscanf(input, " %d", &width); 
		if (j != 1 || width > MAX_IMAGE_WIDTH || width < 0) { //vérification de la validité des dimensions
			fprintf(stderr, "Erreur: largeur invalide");
			while(!feof(input) && !ferror(input) && getc(input) != '\n');
			erreur = 1;
		}

		int k = fscanf(input, " %d", &height);
		if (k != 1 || height > MAX_IMAGE_HEIGHT || height < 0) {
			fprintf(stderr, "Erreur: hauteur invalide");
			while(!feof(input) && !ferror(input) && getc(input) != '\n');
			erreur = 1;
		}

		if(erreur == 0) {
			while(!feof(input) && !ferror(input) && getc(input) != '\n');
			image = init_image(height, width);
			for(int a = 0; a < height && erreur == 0; ++a) {
				
				char temp[2*width+2];
				fgets(temp, 2*width+2, input);
				for(int b = 0; b < 2*width; b = b+2) {
					char c = '*';
					double d = 0.0;
					if (!feof(input) && !ferror(input) && erreur == 0) {
						c = temp[b];
						if((c == '+' || c == '.' || c == '*')) {
							if (c == '+') {
								d = 1.0;
							} else if (c == '.') {
								d = 0.0;
							} else {
								d = 42.0;
							}
							image.content[a][b/2] = d;
							
						} else {
							erreur = 1;
						}

					}
				}

				if(temp[2*width] != '\n') {
					fprintf(stderr, "Erreur: contenu en désaccord avec les dimensions \n");
					erreur = 1;
					while(!feof(input) && !ferror(input) && getc(input) != '\n');
				}
			}
		}

		if(erreur != 0) {
			image.width = 0;
			image.height = 0;
		}
		
		fclose(input);
	}	
	return image;
}
Example #26
0
File: gfx.c Project: harnold/ducks
int gfx_init(int mode)
{
    struct vbe_info info;
    struct vbe_mode_info mode_info;

    if (gfx_check_vbe_info(&info) != 0)
        return -1;

    if (gfx_check_vbe_mode_info(&info, mode, &mode_info) != 0)
        return -1;

    vga_get_mode(&gfx_saved_vga_mode);
    gfx_mode_info.mode = gfx_saved_vga_mode;

    if (vbe_set_mode(mode, VBE_LINEAR_FRAMEBUFFER | VBE_CLEAR_DISPLAY_MEMORY) != 0) {
        error("Setting VBE mode %Xh failed", mode);
        goto failure;
    }

    gfx_mode_info.mode = mode;
    gfx_mode_info.x_resolution = mode_info.x_resolution;
    gfx_mode_info.y_resolution = mode_info.y_resolution;
    gfx_mode_info.page_size = mode_info.bytes_per_scanline * mode_info.y_resolution;

    if (mode_info.phys_base_ptr <= 0xFFFFF) {
        error("Unsupported hardware configuration: Framebuffer in real-mode memory "
              "(physical base address = %Xh)", mode_info.phys_base_ptr);
        goto failure;
    }

    if (dpmi_map_physical_address(mode_info.phys_base_ptr,
                                  2 * gfx_mode_info.page_size,
                                  &gfx_framebuffer_address) != 0) {
        error("Mapping graphics card framebuffer to memory failed");
        goto failure;
    }

    if (vbe_set_display_start(0, 0, VBE_WAIT_FOR_RETRACE) != 0) {
        error("Setting display start failed");
        goto failure;
    }

    init_image(&gfx_buffer_1,
               gfx_mode_info.x_resolution,
               gfx_mode_info.y_resolution,
               (uint8_t *) gfx_framebuffer_address);

    init_image(&gfx_buffer_2,
               gfx_mode_info.x_resolution,
               gfx_mode_info.y_resolution,
               gfx_buffer_1.data + gfx_mode_info.page_size);

    gfx_front_buffer = &gfx_buffer_1;
    gfx_back_buffer = &gfx_buffer_2;

    gfx_check_refresh_rate();
    gfx_reset_clip_rect();

    return 0;

failure:

    gfx_exit();
    return -1;
}
Example #27
0
void decompress(FILE *fp, FILE *fout) {
	int row_stride;
	struct jpeg_error_mgr jerr;
	struct jpeg_decompress_struct jpg;
	JSAMPARRAY buffer;
	Image image;

	jpg.err = jpeg_std_error(&jerr);
	jpeg_create_decompress(&jpg);
	jpeg_stdio_src(&jpg, fp);
	jpeg_read_header(&jpg, TRUE);
	jpeg_start_decompress(&jpg);

	if ( jpg.data_precision != 8 ) {
		fprintf(stderr,
			"Image has %d bits color channels, we only support 8-bit.\n",
			jpg.data_precision);
		exit(1);
	}

	row_stride = jpg.output_width * jpg.output_components;

	buffer = (*jpg.mem->alloc_sarray)((j_common_ptr) &jpg, JPOOL_IMAGE, row_stride, 1);

	aspect_ratio(jpg.output_width, jpg.output_height);

	malloc_image(&image);
	clear(&image);

	if ( verbose ) print_info(&jpg);

	init_image(&image, &jpg);

	while ( jpg.output_scanline < jpg.output_height ) {
		jpeg_read_scanlines(&jpg, buffer, 1);
		process_scanline(&jpg, buffer[0], &image);
		if ( verbose ) print_progress(&jpg);
	}

	if ( verbose ) {
		fprintf(stderr, "\n");
		fflush(stderr);
	}

	normalize(&image);

	if ( clearscr ) {
		fprintf(fout, "%c[2J", 27); // ansi code for clear
		fprintf(fout, "%c[0;0H", 27); // move to upper left
	}

	if ( html && !html_rawoutput ) print_html_start(html_fontsize, fout);
	if ( use_border ) print_border(image.width);

	(!usecolors? print_image : print_image_colors) (&image, (int) strlen(ascii_palette) - 1, fout);

	if ( use_border ) print_border(image.width);
	if ( html && !html_rawoutput ) print_html_end(fout);

	free_image(&image);

	jpeg_finish_decompress(&jpg);
	jpeg_destroy_decompress(&jpg);
}
Example #28
0
/*
 * R2D::Window#show
 */
static VALUE r2d_show(VALUE self) {
  
  // SDL Inits /////////////////////////////////////////////////////////////////
  
  SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
  TTF_Init();
  
  // Create SDL window and configure ///////////////////////////////////////////
  
  char* win_title = RSTRING_PTR(rb_iv_get(self, "@title"));
  int win_width   = NUM2INT(rb_iv_get(self, "@width"));
  int win_height  = NUM2INT(rb_iv_get(self, "@height"));
  int fps_cap     = NUM2INT(rb_iv_get(self, "@fps_cap"));
  bool vsync      = RTEST(rb_iv_get(self, "@vsync"));
  
  SDL_Window *window = SDL_CreateWindow(
    win_title,                                       // title
    SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,  // window position
    win_width, win_height,                           // window size
    SDL_WINDOW_OPENGL                                // flags
  );
  
  // Check if windows was successfully created
  if (!window) {
    printf("R2D Error: Could not create window: %s\n", SDL_GetError());
    return 1;
  }
  
  // Enable VSync
  if (vsync) {
    if (!SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1")) {
      printf("R2D Warning: VSync cannot be enabled!");
    }
  }
  
  // OpenGL Inits //////////////////////////////////////////////////////////////
  
  SDL_GLContext glcontext = SDL_GL_CreateContext(window);
  initGL(win_width, win_height);
  
  // Create SDL Renderer for Accelerated 2D ////////////////////////////////////
  
  SDL_Renderer *renderer = SDL_CreateRenderer(
    window, -1, SDL_RENDERER_ACCELERATED
  );
  
  // Setting up variables
  int cursor_x, cursor_y;  // Cursor positions
  const Uint8 *key_state;
  Uint32 frames = 0;       // Total frames since start
  Uint32 start_ms = SDL_GetTicks();  // Elapsed time since start
  Uint32 begin_ms = start_ms;  // TIme at beginning of loop
  Uint32 end_ms;    // Time at end of loop
  Uint32 total_ms;  // Total elapsed time
  Uint32 loop_ms;   // Elapsed time of loop
  int delay_ms;     // Amount of delay to achieve desired frame rate
  double fps;       // The actual frame rate
  
  // Main Event Loop ///////////////////////////////////////////////////////////
  
  bool quit = false;
  while (!quit) {
    
    // Set FPS /////////////////////////////////////////////////////////////////
    
    frames++;
    end_ms = SDL_GetTicks();
    
    total_ms = end_ms - start_ms;
    fps = frames / (total_ms / 1000.0);
    
    loop_ms = end_ms - begin_ms;
    delay_ms = (1000 / fps_cap) - loop_ms;
    
    if (delay_ms < 0) { delay_ms = 0; }
    
    // loop_ms + delay_ms => should equal (1000 / fps_cap)
    
    // Store FPS info
    rb_iv_set(self, "@frames", INT2NUM(frames));
    rb_iv_set(self, "@total_ms", INT2NUM(total_ms));
    rb_iv_set(self, "@loop_ms", INT2NUM(loop_ms));
    rb_iv_set(self, "@fps", DBL2NUM(fps));
    
    SDL_Delay(delay_ms);
    begin_ms = SDL_GetTicks();
    
    // Handle Input ////////////////////////////////////////////////////////////
    
    SDL_Event e;
    while (SDL_PollEvent(&e)) {
      switch(e.type) {
        case SDL_KEYDOWN:
          rb_funcall(self, rb_intern("on_key_callback"), 1,
            rb_str_new2(SDL_GetScancodeName(e.key.keysym.scancode))
          );
          break;
        case SDL_QUIT:
          quit = true;
          break;
      }
    }
    
    int num_keys;
    key_state = SDL_GetKeyboardState(&num_keys);
    
    for (int i = 0; i < num_keys; i++) {
      if (key_state[i] == 1) {
        rb_funcall(self, rb_intern("keys_down_callback"), 1,
          rb_str_new2(SDL_GetScancodeName(i))
        );
      }
    }
    
    // Store the cursor position
    SDL_GetMouseState(&cursor_x, &cursor_y);
    rb_iv_set(self, "@cursor_x", INT2NUM(cursor_x));
    rb_iv_set(self, "@cursor_y", INT2NUM(cursor_y));
    
    // Update Application State ////////////////////////////////////////////////
    
    // Call update proc, `window.update`
    rb_funcall(self, rb_intern("update_callback"), 0);
    
    // Draw Objects ////////////////////////////////////////////////////////////
    
    glClear(GL_COLOR_BUFFER_BIT);
    
    // Read window objects
    VALUE objects = rb_iv_get(self, "@objects");
    int num_objects = NUM2INT(rb_funcall(objects, rb_intern("count"), 0));
    
    // Switch on each object type
    for (int i = 0; i < num_objects; ++i) {
      
      VALUE el = rb_ary_entry(objects, i);
      int type_id = NUM2INT(rb_iv_get(el, "@type_id"));
      
      // Switch on the object's type_id
      switch(type_id) {
        
        case TRIANGLE: {
          VALUE c1 = rb_iv_get(el, "@c1");
          VALUE c2 = rb_iv_get(el, "@c2");
          VALUE c3 = rb_iv_get(el, "@c3");
          
          draw_triangle(
            NUM2DBL(rb_iv_get(el, "@x1")),
            NUM2DBL(rb_iv_get(el, "@y1")),
            NUM2DBL(rb_iv_get(c1, "@r")),
            NUM2DBL(rb_iv_get(c1, "@g")),
            NUM2DBL(rb_iv_get(c1, "@b")),
            NUM2DBL(rb_iv_get(c1, "@a")),
            
            NUM2DBL(rb_iv_get(el, "@x2")),
            NUM2DBL(rb_iv_get(el, "@y2")),
            NUM2DBL(rb_iv_get(c2, "@r")),
            NUM2DBL(rb_iv_get(c2, "@g")),
            NUM2DBL(rb_iv_get(c2, "@b")),
            NUM2DBL(rb_iv_get(c2, "@a")),
            
            NUM2DBL(rb_iv_get(el, "@x3")),
            NUM2DBL(rb_iv_get(el, "@y3")),
            NUM2DBL(rb_iv_get(c3, "@r")),
            NUM2DBL(rb_iv_get(c3, "@g")),
            NUM2DBL(rb_iv_get(c3, "@b")),
            NUM2DBL(rb_iv_get(c3, "@a"))
          );
        }
        break;
        
        case QUAD: {
          VALUE c1 = rb_iv_get(el, "@c1");
          VALUE c2 = rb_iv_get(el, "@c2");
          VALUE c3 = rb_iv_get(el, "@c3");
          VALUE c4 = rb_iv_get(el, "@c4");
          
          draw_triangle(
            NUM2DBL(rb_iv_get(el, "@x1")),
            NUM2DBL(rb_iv_get(el, "@y1")),
            NUM2DBL(rb_iv_get(c1, "@r")),
            NUM2DBL(rb_iv_get(c1, "@g")),
            NUM2DBL(rb_iv_get(c1, "@b")),
            NUM2DBL(rb_iv_get(c1, "@a")),
            
            NUM2DBL(rb_iv_get(el, "@x2")),
            NUM2DBL(rb_iv_get(el, "@y2")),
            NUM2DBL(rb_iv_get(c2, "@r")),
            NUM2DBL(rb_iv_get(c2, "@g")),
            NUM2DBL(rb_iv_get(c2, "@b")),
            NUM2DBL(rb_iv_get(c2, "@a")),
            
            NUM2DBL(rb_iv_get(el, "@x3")),
            NUM2DBL(rb_iv_get(el, "@y3")),
            NUM2DBL(rb_iv_get(c3, "@r")),
            NUM2DBL(rb_iv_get(c3, "@g")),
            NUM2DBL(rb_iv_get(c3, "@b")),
            NUM2DBL(rb_iv_get(c3, "@a"))
          );
          
          draw_triangle(
            NUM2DBL(rb_iv_get(el, "@x3")),
            NUM2DBL(rb_iv_get(el, "@y3")),
            NUM2DBL(rb_iv_get(c3, "@r")),
            NUM2DBL(rb_iv_get(c3, "@g")),
            NUM2DBL(rb_iv_get(c3, "@b")),
            NUM2DBL(rb_iv_get(c3, "@a")),
            
            NUM2DBL(rb_iv_get(el, "@x4")),
            NUM2DBL(rb_iv_get(el, "@y4")),
            NUM2DBL(rb_iv_get(c4, "@r")),
            NUM2DBL(rb_iv_get(c4, "@g")),
            NUM2DBL(rb_iv_get(c4, "@b")),
            NUM2DBL(rb_iv_get(c4, "@a")),
            
            NUM2DBL(rb_iv_get(el, "@x1")),
            NUM2DBL(rb_iv_get(el, "@y1")),
            NUM2DBL(rb_iv_get(c1, "@r")),
            NUM2DBL(rb_iv_get(c1, "@g")),
            NUM2DBL(rb_iv_get(c1, "@b")),
            NUM2DBL(rb_iv_get(c1, "@a"))
          );
        }
        break;
        
        case IMAGE: {
          if (rb_iv_get(el, "@data") == Qnil) {
            VALUE data = init_image(
              renderer,
              RSTRING_PTR(rb_iv_get(el, "@path"))
            );
            rb_iv_set(el, "@data", data);
          }
          
          draw_image(
            el,
            NUM2DBL(rb_iv_get(el, "@x")),
            NUM2DBL(rb_iv_get(el, "@y"))
          );
        }
        break;
        
        case TEXT: {
          if (rb_iv_get(el, "@data") == Qnil) {
            VALUE data = init_text(
              renderer,
              RSTRING_PTR(rb_iv_get(el, "@font")),
              RSTRING_PTR(rb_iv_get(el, "@text")),
              NUM2DBL(rb_iv_get(el, "@size"))
            );
            rb_iv_set(el, "@data", data);
          }
          
          // // TODO: Set color of text
          // VALUE c = rb_iv_get(el, "@c");
          // NUM2DBL(rb_iv_get(c, "@r")),
          // NUM2DBL(rb_iv_get(c, "@g")),
          // NUM2DBL(rb_iv_get(c, "@b")),
          
          draw_text(
            el,
            RSTRING_PTR(rb_iv_get(el, "@text")),
            NUM2DBL(rb_iv_get(el, "@x")),
            NUM2DBL(rb_iv_get(el, "@y"))
          );
        }
        break;
      }
    }
    
    // Draw frame
    SDL_GL_SwapWindow(window);
  }
  
  // Clean up
  IMG_Quit();
  Mix_Quit();
  SDL_GL_DeleteContext(glcontext);
  SDL_DestroyRenderer(renderer);
  SDL_DestroyWindow(window);
  SDL_Quit();
  
  return 0;
}
Example #29
0
int
main(int argc, char **argv)
{
	init_image();
	int n;

	n = 0;
	OPCODE(VM_LIT16);
	OPCODE(0xFFFF);
	OPCODE(VM_DUP);
	OPCODE(VM_NOP);
	OPCODE(VM_LIT32);
	OPCODE(0xFFFE);
	OPCODE(0xFFFD);
	OPCODE(VM_DROP);
	OPCODE(VM_LIT16);
	OPCODE(0x1209);
	OPCODE(VM_SWAP);
	OPCODE(VM_DEBUG_NOP);
	OPCODE(VM_PUSH);
	OPCODE(VM_POP);
	OPCODE(VM_LIT16);
	OPCODE(2);
	OPCODE(VM_NOP);
	OPCODE(VM_LOOP);
	OPCODE(17);
	OPCODE(VM_LIT16);
	OPCODE(24);
	OPCODE(VM_PUSH);
	OPCODE(VM_DEBUG_NOP);
	OPCODE(VM_JUMP);
	OPCODE(0x100);
	OPCODE(VM_LIT16);
	OPCODE(0x1103);
	OPCODE(VM_LIT16);
	OPCODE(0x1100);
	OPCODE(VM_GT_JUMP);
	OPCODE(0x200);
	OPCODE(VM_HALT);

	n = 0x100;
	OPCODE(VM_DEBUG_NOP);
	OPCODE(VM_LIT16);
	OPCODE(0x0529);
	OPCODE(VM_RETURN);

	n = 0x200;
	OPCODE(VM_LIT16);
	OPCODE(0x0817);
	OPCODE(VM_LIT16);
	OPCODE(0x0818);
	OPCODE(VM_GT_JUMP);
	OPCODE(0x200);
	OPCODE(VM_LIT16);
	OPCODE(0x0817);
	OPCODE(VM_LIT16);
	OPCODE(0x0818);
	OPCODE(VM_LT_JUMP);
	OPCODE(0x300);
	OPCODE(VM_HALT);

	n = 0x300;
	OPCODE(VM_LIT16);
	OPCODE(0x0817);
	OPCODE(VM_LIT16);
	OPCODE(0x0816);
	OPCODE(VM_LT_JUMP);
	OPCODE(0x300);
	OPCODE(VM_LIT16);
	OPCODE(0x0817);

	OPCODE(VM_LIT16);
	OPCODE(VM_LIT16);

	OPCODE(VM_LIT16);
	OPCODE(0x0500);

	OPCODE(VM_STORE);

	OPCODE(VM_LIT16);
	OPCODE(0x1234);

	OPCODE(VM_LIT16);
	OPCODE(0x0501);

	OPCODE(VM_STORE);

	OPCODE(VM_JUMP);
	OPCODE(0x500);

	OPCODE(VM_HALT);

	n = 0x502;
	OPCODE(VM_LIT16);
	OPCODE(4);
	OPCODE(VM_LIT32);
	OPCODE(0xFFFC);
	OPCODE(5);
	OPCODE(VM_ADD);
	OPCODE(VM_LIT32);
	OPCODE(0xFFFC);
	OPCODE(5);
	OPCODE(VM_SUB);

	OPCODE(VM_CALL_FLAG | 0x600);
	OPCODE(VM_LIT16);
	OPCODE(0x1111);
	OPCODE(VM_LIT14_FLAG | 0x777);
	OPCODE(VM_DUP);
	OPCODE(VM_DUP);
	/*
	OPCODE(VM_ADD13_FLAG | 0x1111);
	OPCODE(VM_SWAP);
	OPCODE(VM_SHL12_FLAG | 0x0004);
	*/
	OPCODE(VM_LIT14_FLAG | 0x3FFF);
	OPCODE(VM_HALT);

	n = 0x600;
	OPCODE(VM_LIT16);
	OPCODE(0x2222);
	OPCODE(VM_ZERO_EXIT);
	OPCODE(VM_LIT16);
	OPCODE(0x3333);
	OPCODE(VM_LIT16);
	OPCODE(0x1);
	OPCODE(VM_ZERO_EXIT);
	OPCODE(VM_LIT16);
	OPCODE(0x4444);
	OPCODE(VM_RETURN);

	run_image();
}