Exemplo n.º 1
0
int main(int argc, char **argv)
{
    Images images;
    flif_options options = FLIF_DEFAULT_OPTIONS;
#ifdef HAS_ENCODER
    int mode = -1; // 0 = encode, 1 = decode, 2 = transcode
#else
    int mode = 1;
#endif
    bool showhelp = false;
    if (strcmp(argv[0],"cflif") == 0) mode = 0;
    if (strcmp(argv[0],"dflif") == 0) mode = 1;
    if (strcmp(argv[0],"deflif") == 0) mode = 1;
    if (strcmp(argv[0],"decflif") == 0) mode = 1;
    static struct option optlist[] = {
        {"help", 0, NULL, 'h'},
        {"decode", 0, NULL, 'd'},
        {"verbose", 0, NULL, 'v'},
        {"no-crc", 0, NULL, 'c'},
        {"no-metadata", 0, NULL, 'm'},
        {"no-color-profile", 0, NULL, 'p'},
        {"quality", 1, NULL, 'q'},
        {"scale", 1, NULL, 's'},
        {"resize", 1, NULL, 'r'},
        {"fit", 1, NULL, 'f'},
        {"identify", 0, NULL, 'i'},
        {"version", 0, NULL, 'V'},
        {"overwrite", 0, NULL, 'o'},
        {"breakpoints", 0, NULL, 'b'},
        {"keep-palette", 0, NULL, 'k'},
#ifdef HAS_ENCODER
        {"encode", 0, NULL, 'e'},
        {"transcode", 0, NULL, 't'},
        {"interlace", 0, NULL, 'I'},
        {"no-interlace", 0, NULL, 'N'},
        {"frame-delay", 1, NULL, 'F'},
        {"keep-invisible-rgb", 0, NULL, 'K'},
        {"max-palette-size", 1, NULL, 'P'},
        {"force-color-buckets", 0, NULL, 'A'},
        {"no-color-buckets", 0, NULL, 'B'},
        {"no-ycocg", 0, NULL, 'Y'},
        {"no-channel-compact", 0, NULL, 'C'},
        {"max-frame-lookback", 1, NULL, 'L'},
        {"no-frame-shape", 0, NULL, 'S'},
        {"maniac-repeats", 1, NULL, 'R'},
        {"maniac-divisor", 1, NULL, 'D'},
        {"maniac-min-size", 1, NULL, 'M'},
        {"maniac-threshold", 1, NULL, 'T'},
        {"chance-cutoff", 1, NULL, 'X'},
        {"chance-alpha", 1, NULL, 'Z'},
        {"lossy", 1, NULL, 'Q'},
        {"adaptive", 0, NULL, 'U'},
        {"guess", 1, NULL, 'G'},
        {"invisible-guess", 1, NULL, 'H'},
        {"effort", 1, NULL, 'E'},
        {"chroma-subsample", 0, NULL, 'J'},
        {"no-subtract-green", 0, NULL, 'W'},
#endif
        {0, 0, 0, 0}
    };
    int i,c;
#ifdef HAS_ENCODER
    while ((c = getopt_long (argc, argv, "hdvcmiVq:s:r:f:obketINnF:KP:ABYWCL:SR:D:M:T:X:Z:Q:UG:H:E:J", optlist, &i)) != -1) {
#else
    while ((c = getopt_long (argc, argv, "hdvcmiVq:s:r:f:obk", optlist, &i)) != -1) {
#endif
        switch (c) {
        case 'd': mode=1; break;
        case 'v': increase_verbosity(); break;
        case 'V': increase_verbosity(3); break;
        case 'c': options.crc_check = 0; break;
        case 'm': options.metadata = 0; break;
        case 'p': options.color_profile = 0; break;
        case 'o': options.overwrite = 1; break;
        case 'q': options.quality=atoi(optarg);
                  if (options.quality < 0 || options.quality > 100) {e_printf("Not a sensible number for option -q\n"); return 1; }
                  break;
        case 's': options.scale=atoi(optarg);
                  if (options.scale < 1 || options.scale > 128) {e_printf("Not a sensible number for option -s\n"); return 1; }
                  break;
        case 'r': if (sscanf(optarg,"%ix%i", &options.resize_width, &options.resize_height) < 1) {
                    if (sscanf(optarg,"x%i", &options.resize_height) < 1) {e_printf("Not a sensible value for option -r (expected WxH)\n"); return 1; }
                  }
                  if (!options.resize_height) options.resize_height = options.resize_width;
                  break;
        case 'f': if (sscanf(optarg,"%ix%i", &options.resize_width, &options.resize_height) < 1) {
                    if (sscanf(optarg,"x%i", &options.resize_height) < 1) {e_printf("Not a sensible value for option -f (expected WxH)\n"); return 1; }
                  }
                  options.fit=1;
                  break;
        case 'i': options.scale = -1; break;
        case 'b': options.show_breakpoints = 8; mode=1; break;
        case 'k': options.keep_palette = true; break;
#ifdef HAS_ENCODER
        case 'e': mode=0; break;
        case 't': mode=2; break;
        case 'I': options.method.encoding=flifEncoding::interlaced; break;
        case 'n': // undocumented: lower case -n still works
        case 'N': options.method.encoding=flifEncoding::nonInterlaced; break;
        case 'A': options.acb=1; break;
        case 'B': options.acb=0; break;
        case 'P': options.palette_size=atoi(optarg);
                  if (options.palette_size < -32000 || options.palette_size > 32000) {e_printf("Not a sensible number for option -P\n"); return 1; }
                  if (options.palette_size > 512) {v_printf(1,"Warning: palette size above 512 implies that simple FLIF decoders (8-bit only) cannot decode this file.\n"); }
                  if (options.palette_size == 0) {v_printf(5,"Palette disabled\n"); }
                  break;
        case 'R': options.learn_repeats=atoi(optarg);
                  if (options.learn_repeats < 0 || options.learn_repeats > 20) {e_printf("Not a sensible number for option -R\n"); return 1; }
                  break;
        case 'F': options.frame_delay.clear();
                  while(optarg != 0) {
                    int d=strtol(optarg,&optarg,10);
                    if (d==0) break;
                    if (*optarg == ',' || *optarg == '+' || *optarg == ' ') optarg++;
                    options.frame_delay.push_back(d);
                    if (d < 0 || d > 60000) {e_printf("Not a sensible number for option -F: %i\n",d); return 1; }
                  }
                  if (options.frame_delay.size() < 1) options.frame_delay.push_back(100);
                  break;
        case 'L': options.lookback=atoi(optarg);
                  if (options.lookback < -1 || options.lookback > 256) {e_printf("Not a sensible number for option -L\n"); return 1; }
                  break;
        case 'D': options.divisor=atoi(optarg);
                  if (options.divisor <= 0 || options.divisor > 0xFFFFFFF) {e_printf("Not a sensible number for option -D\n"); return 1; }
                  break;
        case 'M': options.min_size=atoi(optarg);
                  if (options.min_size < 0) {e_printf("Not a sensible number for option -M\n"); return 1; }
                  break;
        case 'T': options.split_threshold=atoi(optarg);
                  if (options.split_threshold <= 3 || options.split_threshold > 100000) {e_printf("Not a sensible number for option -T\n"); return 1; }
                  options.split_threshold *= 5461;
                  break;
        case 'Y': options.ycocg=0; break;
        case 'W': options.ycocg=0; options.subtract_green=0; break;
        case 'C': options.plc=0; break;
        case 'S': options.frs=0; break;
        case 'K': options.alpha_zero_special=0; break;
        case 'X': options.cutoff=atoi(optarg);
                  if (options.cutoff < 1 || options.cutoff > 128) {e_printf("Not a sensible number for option -X (try something between 1 and 128)\n"); return 1; }
                  break;
        case 'Z': options.alpha=atoi(optarg);
                  if (options.alpha < 2 || options.alpha > 128) {e_printf("Not a sensible number for option -Z (try something between 2 and 128)\n"); return 1; }
                  break;
        case 'Q': options.loss=100-atoi(optarg);
                  // can't go above quality 100 = lossless
                  // can go way below 0 if you want
                  if (options.loss < 0) {e_printf("Not a sensible number for option -Q (try something between 0 and 100)\n"); return 1; }
                  break;
        case 'U': options.adaptive=1; break;
        case 'G': {
                  int p=0;
                  while(*optarg != 0) {
                    int d=0;
                    switch (*optarg) {
                        case '?': case 'G': case 'g': case 'H': case 'h': // guess/heuristically choose
                            d = -2; break;
                        case '0': case 'A': case 'a': // average
                            d = 0; break;
                        case '1': case 'M': case 'm': // median of 3 values (avg, grad1, grad2)
                            d = 1; break;
                        case '2': case 'N': case 'n': // median of 3 neighbors
                            d = 2; break;
                        case '3':
                        case 'X': case 'x': // auto/mixed, usually a bad idea
                            d = -1; break;
                        case ' ': case ',': case '+':
                            optarg++; continue;
                        default:
                        e_printf("Not a sensible value for option -G\nValid values are: 0 (avg), 1 (median avg/gradients), 2 (median neighbors), X (auto/mixed), ? (heuristically pick 0-2)\n"); return 1;
                    }
                    if (p>4) {e_printf("Error while parsing option -G: too many planes specified\n"); return 1; }
                    options.predictor[p] = d;
                    p++; optarg++;
                  }
                  for (; p<5; p++) options.predictor[p]=options.predictor[0];
                  }
                  break;
        case 'H': options.invisible_predictor=atoi(optarg);
                  if (options.invisible_predictor < 0 || options.invisible_predictor > 2) {e_printf("Not a sensible value for option -H\nValid values are: 0 (avg), 1 (median avg/gradients), 2 (median neighbors)\n"); return 1; }
                  break;
        case 'J': options.chroma_subsampling = 1;
                  break;
        case 'E': {
                  int effort=atoi(optarg);
                  if (effort < 0 || effort > 100) {e_printf("Not a sensible number for option -E (try something between 0 and 100)\n"); return 1; }
                  // set some parameters automatically
                  if (effort < 10) options.learn_repeats=0;
                  else if (effort <= 50) {options.learn_repeats=1; options.split_threshold=5461*8*5;}
                  else if (effort <= 70) {options.learn_repeats=2;  options.split_threshold=5461*8*8;}
                  else if (effort <= 90) {options.learn_repeats=3; options.split_threshold=5461*8*10;}
                  else if (effort <= 100) {options.learn_repeats=4; options.split_threshold=5461*8*12;}
                  if (effort < 15) { for (int i=0; i<5; i++) options.predictor[i]=0; }
                  else if (effort < 30) { options.predictor[1]=0; options.predictor[2]=0; }
                  if (effort < 5) options.acb=0;
                  if (effort < 8) options.palette_size=0;
                  if (effort < 25) options.plc=0;
                  if (effort < 30) options.lookback=0;
                  if (effort < 5) options.frs=0;
                  v_printf(3,"Encode effort: %i, corresponds to parameters -R%i -T%i%s%s%s%s\n", effort, options.learn_repeats, options.split_threshold/5461,
                                    (effort<15?" -G0":(effort<30?" -G?00":"")), (effort<5?" -B":""), (effort<8?" -P0":""), (effort<25?" -C":""));
                                    // not mentioning animation options since they're usually irrelevant
                  }
                  break;
#endif
        case 'h': showhelp=true; break;
        default: show_help(mode); return 0;
        }
    }
    argc -= optind;
    argv += optind;
    bool last_is_output = (options.scale != -1);
    if (options.show_breakpoints && argc == 1) { last_is_output = false; options.no_full_decode = 1; options.scale = 2; }

    if (!strcmp(argv[argc-1],"-")) {
        // writing output to stdout, so redirecting verbose output to stderr to avoid contaminating the output stream
        redirect_stdout_to_stderr();
    }

    show_banner();
    if (argc == 0 || showhelp) {
        if (get_verbosity() == 1 || showhelp) show_help(mode);
        return 0;
    }

    if (argc == 1 && last_is_output) {
        show_help(mode);
        e_printf("\nOutput file missing.\n");
        return 1;
    }
    if (options.scale == -1) mode = 1;
    if (mode < 0) mode = 0;
    if (file_exists(argv[0])) {
        char *f = strrchr(argv[0],'/');
        char *ext = f ? strrchr(f,'.') : strrchr(argv[0],'.');
#ifdef HAS_ENCODER
        if (mode == 0 && file_is_flif(argv[0])) {
            char *f = strrchr(argv[1],'/');
            char *ext = f ? strrchr(f,'.') : strrchr(argv[1],'.');
            if ((ext && ( !strcasecmp(ext,".flif")  || ( !strcasecmp(ext,".flf") )))) {
                v_printf(3,"Input and output file are both FLIF file, adding implicit -t\n");
                mode = 2;
            } else {
                v_printf(3,"Input file is a FLIF file, adding implicit -d\n");
                mode = 1;
            }
        }
        if (mode == 0) {
            char *f = strrchr(argv[argc-1],'/');
            char *ext = f ? strrchr(f,'.') : strrchr(argv[argc-1],'.');
            if (ext && !options.loss && strcasecmp(ext,".flif") && strcasecmp(ext,".flf") ) {
                e_printf("Warning: expected file name extension \".flif\" for output file.\n");
            } else if (options.loss && check_compatible_extension(ext)) {
                v_printf(2,"Not doing actual lossy encoding to FLIF, just applying loss.\n");
                options.just_add_loss = 1;
            }
        }
        if (mode != 0) {
#endif
            if (!(ext && ( !strcasecmp(ext,".flif")  || ( !strcasecmp(ext,".flf") )))) {
                e_printf("Warning: expected file name extension \".flif\" for input file, trying anyway...\n");
            }
#ifdef HAS_ENCODER
        } else {
            if (!check_compatible_extension(ext)) {
                e_printf("Warning: expected \".png\", \".pnm\" or \".pam\" file name extension for input file, trying anyway...\n");
            }
        }
#endif
    } else if (argc>0) {
        if (!strcmp(argv[0],"-")) {
          v_printf(4,"Taking input from standard input. Mode: %s\n",
             (mode==0?"encode": (mode==1?"decode":"transcode")));
        } else if (!strchr(argv[0],'%')) {
          e_printf("Error: input file does not exist: %s\n",argv[0]);
          return 1;
        }
    }
    if (last_is_output && file_exists(argv[argc-1]) && !options.overwrite) {
        e_printf("Error: output file already exists: %s\nUse --overwrite to force overwrite.\n",argv[argc-1]);
        return 1;
    }
    if (mode > 0 && argc > 2 && options.scale != -1) {
        e_printf("Too many arguments.\n");
        return 1;
    }

#ifdef HAS_ENCODER
    if (options.chroma_subsampling)
        v_printf(1,"Warning: chroma subsampling produces a truncated FLIF file. Image will not be lossless!\n");
    if (options.loss > 0) options.keep_palette = false; // not going to add loss to indexed colors
    if (options.adaptive) options.loss = -options.loss; // use negative loss to indicate we want to do adaptive lossy encoding
    if (mode == 0) {
        if (!handle_encode(argc, argv, images, options)) return 2;
    } else if (mode == 1) {
#endif
        return handle_decode(argc, argv, images, options);
#ifdef HAS_ENCODER
    } else if (mode == 2) {
//        if (scale > 1) {e_printf("Not yet supported: transcoding downscaled image; use decode + encode!\n");}
        if (!decode_flif(argv, images, options)) return 2;
        argc--; argv++;
        if (!encode_flif(argc, argv, images, options)) return 2;
    }
#endif
    return 0;
}
Exemplo n.º 2
0
void test_dyn_oseq (void)
{
	DDS_DynamicTypeSupport ts;
	DDS_DynamicTypeBuilder sb, oseqb;
	DDS_TypeDescriptor *desc;
	DDS_MemberDescriptor *md;
	DDS_DynamicType s, oseq;
	DDS_DynamicData dd, dda, dd2;
	DDS_ReturnCode_t rc;
	DDS_ByteSeq values;
	unsigned i;

	v_printf ("test_dyn_oseq - ");

	/* 1. Create the type. */
	desc = DDS_TypeDescriptor__alloc ();
	fail_unless (desc != NULL);

	desc->kind = DDS_STRUCTURE_TYPE;
	desc->name = "dstruct3";
	sb = DDS_DynamicTypeBuilderFactory_create_type (desc);
	fail_unless (sb != NULL);

	md = DDS_MemberDescriptor__alloc ();
	fail_unless (md != NULL);

	ADD_FIELD (sb, md, "anuint", 0, 0, DDS_UINT_32_TYPE);

	oseqb = DDS_DynamicTypeBuilderFactory_create_sequence_type (
		DDS_DynamicTypeBuilderFactory_get_primitive_type (DDS_BYTE_TYPE),
		0);
	fail_unless (oseqb != NULL);

	oseq = DDS_DynamicTypeBuilder_build (oseqb);
	fail_unless (oseq != NULL);

	DDS_DynamicTypeBuilderFactory_delete_type (oseqb);

	md->name = "oseq";
	md->index = md->id = 1;
	md->type = oseq;

	rc = DDS_DynamicTypeBuilder_add_member (sb, md);
	fail_unless (rc == DDS_RETCODE_OK);

	ADD_FIELD (sb, md, "ch", 2, 2, DDS_CHAR_8_TYPE);

	s = DDS_DynamicTypeBuilder_build (sb);
	fail_unless (s != NULL);

	DDS_DynamicTypeBuilderFactory_delete_type (sb);
	ts = DDS_DynamicTypeSupport_create_type_support (s);
	fail_unless (ts != NULL);

	DDS_TypeDescriptor__free (desc);
	DDS_MemberDescriptor__free (md);

	/* 2. Create a Dynamic Data item for this type. */
	dd = DDS_DynamicDataFactory_create_data (s);
	fail_unless (dd != NULL);

	dda = DDS_DynamicDataFactory_create_data (oseq);
	fail_unless (dda != NULL);

	SET_FIELD (dd, 0, uint32, 1000);
	DDS_SEQ_INIT (values);
	rc = dds_seq_require (&values, 21);
	fail_unless (rc == DDS_RETCODE_OK);

	for (i = 0; i < 21; i++)
		DDS_SEQ_ITEM (values, i) = i + '0';

	rc = DDS_DynamicData_set_byte_values (dda, 0, &values);
	fail_unless (rc == DDS_RETCODE_OK);

	SET_FIELD (dd, 1, complex, dda);
	SET_FIELD (dd, 2, char8, 'X');

	marshallDynamic (dd, &dd2, ts);

	DDS_DynamicDataFactory_delete_data (dd);
	DDS_DynamicDataFactory_delete_data (dda);

	DDS_DynamicTypeBuilderFactory_delete_type (oseq);
	DDS_DynamicTypeBuilderFactory_delete_type (s);
	DDS_DynamicTypeSupport_delete_type_support (ts);
	v_printf ("success!\r\n");
}
Exemplo n.º 3
0
static void test_qos (int enabled)
{
	DDS_DomainParticipantFactoryQos	qos;
	DDS_DomainParticipant		p;
	DDS_Publisher			pub;
	DDS_Subscriber			sub;
	DDS_DataWriter			dw;
	DDS_DataReader			dr;
	DDS_Topic			t;
	DDS_TopicDescription		td;
	DDS_DataReaderQos		rq, refrq;
	DDS_ReturnCode_t		r;
	static unsigned char		data [] = { 0x77, 0x88, 0xaa, 0xbb, 0xcc, 0xdd };
	unsigned char			d2 [sizeof (data) + 1];
	unsigned			n;
	int				err;

	v_printf (" - Set factory QoS to %sabled.\r\n", (enabled) ? "en" : "dis");
	r = DDS_DomainParticipantFactory_get_qos (&qos);
	fail_unless (r == DDS_RETCODE_OK);
	qos.entity_factory.autoenable_created_entities = enabled;
	r = DDS_DomainParticipantFactory_set_qos (&qos);
	fail_unless (r == DDS_RETCODE_OK);

	p = DDS_DomainParticipantFactory_create_participant (0, DDS_PARTICIPANT_QOS_DEFAULT, NULL, 0);
	fail_unless (p != NULL);
	r = register_HelloWorldData_type (p);
	fail_unless (r == DDS_RETCODE_OK);

	t = DDS_DomainParticipant_create_topic (p, "HelloWorld", TYPE_NAME, DDS_TOPIC_QOS_DEFAULT, NULL, 0);
	fail_unless (t != NULL);

	td = DDS_DomainParticipant_lookup_topicdescription (p, "HelloWorld");
	fail_unless (td != NULL);

	sub = DDS_DomainParticipant_create_subscriber (p, NULL, NULL, 0);
	fail_unless (sub != NULL);

	DDS_DataReaderQos__init (&refrq);
	err = dds_seq_from_array (&refrq.user_data, data, sizeof (data));
	fail_unless (err == 0);

	v_printf (" - Create datareader with specific QoS parameters.\r\n");
	dr = DDS_Subscriber_create_datareader (sub, td, &refrq, NULL, 0);
	fail_unless (dr != NULL);

	memset (&rq, 0, sizeof (rq));
	r = DDS_DataReader_get_qos (dr, &rq);
	n = dds_seq_to_array (&rq.user_data, d2, sizeof (d2));
	fail_unless (r == DDS_RETCODE_OK &&
		     DDS_SEQ_LENGTH (refrq.user_data.value) == sizeof (data));
	n = dds_seq_to_array (&rq.user_data, d2, sizeof (d2));
	fail_unless (n == sizeof (data) && !memcmp (data, d2, sizeof (data)));
	DDS_DataReaderQos__clear (&rq);
	r = DDS_Subscriber_delete_datareader (sub, dr);
	fail_unless (r == DDS_RETCODE_OK);

	v_printf (" - Create datareader with default QoS parameters.\r\n");
	dr = DDS_Subscriber_create_datareader (sub, td, DDS_DATAREADER_QOS_DEFAULT, NULL, 0);
	fail_unless (dr != NULL);
	pub = DDS_DomainParticipant_create_publisher (p, DDS_PUBLISHER_QOS_DEFAULT, NULL, 0);
	fail_unless (sub != NULL);
	dw = DDS_Publisher_create_datawriter (pub, t, DDS_DATAWRITER_QOS_DEFAULT, NULL, 0);
	fail_unless (dw != NULL);

	v_printf (" - Update datareader QoS parameters.\r\n");
	r = DDS_DataReader_get_qos (dr, &rq);
	fail_unless (r == DDS_RETCODE_OK);
	DDS_DataReaderQos__clear (&refrq);
	fail_unless (r == DDS_RETCODE_OK && !memcmp (&rq, &refrq, sizeof (refrq)));
	err = dds_seq_from_array (&refrq.user_data, data, sizeof (data));
	fail_unless (err == 0);

	r = DDS_DataReader_set_qos (dr, &refrq);
	fail_unless (r == DDS_RETCODE_OK);

	delay ();
	r = DDS_DataReader_get_qos (dr, &rq);
	fail_unless (r == DDS_RETCODE_OK &&
		     DDS_SEQ_LENGTH (rq.user_data.value) == sizeof (data));
	n = dds_seq_to_array (&rq.user_data, d2, sizeof (d2));
	fail_unless (n == sizeof (data) && !memcmp (data, d2, sizeof (data)));

	DDS_DataReaderQos__clear (&refrq);
	DDS_DataReaderQos__clear (&rq);

	delay ();
	if (!enabled) {
		v_printf (" - Enable all entities.\r\n");
		r = DDS_DomainParticipant_enable (p);
		fail_unless (r == DDS_RETCODE_OK);
		r = DDS_Topic_enable (t);
		fail_unless (r == DDS_RETCODE_OK);
		r = DDS_Publisher_enable (pub);
		fail_unless (r == DDS_RETCODE_OK);
		r = DDS_Subscriber_enable (sub);
		fail_unless (r == DDS_RETCODE_OK);
		r = DDS_DataWriter_enable (dw);
		fail_unless (r == DDS_RETCODE_OK);
		r = DDS_DataReader_enable (dr);
		fail_unless (r == DDS_RETCODE_OK);
		sleep (1);
	}
	r = DDS_Publisher_delete_datawriter (pub, dw);
	fail_unless (r == DDS_RETCODE_OK);
	r = DDS_Subscriber_delete_datareader (sub, dr);
	fail_unless (r == DDS_RETCODE_OK);
	r = DDS_DomainParticipant_delete_publisher (p, pub);
	fail_unless (r == DDS_RETCODE_OK);
	r = DDS_DomainParticipant_delete_subscriber (p, sub);
	fail_unless (r == DDS_RETCODE_OK);
	r = DDS_DomainParticipant_delete_topic (p, t);
	fail_unless (r == DDS_RETCODE_OK);

	unregister_HelloWorldData_type (p);
	r = DDS_DomainParticipantFactory_delete_participant (p);
	fail_unless (r == DDS_RETCODE_OK);
}
Exemplo n.º 4
0
/* 
 * DANG_BEGIN_FUNCTION video_init
 *
 * description:
 *  Set pointer to correct structure of functions to initialize, close,
 *  etc... video routines.
 *
 * DANG_END_FUNCTION
 */
int video_init()
{
    /* figure out which video front end we are to use */

    if (config.vga) {
	v_printf("VID: Video set to Video_graphics\n");
	Video = &Video_graphics;
    } else if (config.console_video) {
	if (config.cardtype == CARD_MDA) {
	    v_printf("VID: Video set to Video_hgc\n");
	    Video = &Video_hgc;
	} else {
	    v_printf("VID: Video set to Video_console\n");
	    Video = &Video_console;
	}
    }
#ifdef X_SUPPORT
    else if (config.X) {
	v_printf("VID: Video set to Video_X\n");
	Video = &Video_X;
    }
#endif
    else if (config.usesX) {
	v_printf("VID: Video set to Video_hgc\n");
	Video = &Video_hgc;
    } else {
	v_printf("VID: Video set to Video_term\n");
	Video = &Video_term;	/* ansi or ncurses */
    }

#if USE_DUALMON
    {
	extern void init_dualmon(void);
	init_dualmon();
    }
#endif

    ASSERT(Video->init);
    Video->init();		/* call the specific init routine */

    if (!Video->is_mapped) {
	/* allocate screen buffer for non-console video compare speedup */
	prev_screen = (ushort *) malloc(co * MAX_LINES * 2);
	if (prev_screen == NULL) {
	    error("could not malloc prev_screen\n");
	    leaveemu(ERR_MEM);
	}
/*      v_printf("SCREEN saves at: %p of %d size\n", prev_screen, co * li * 2); */
/* 
 * DANG_BEGIN_REMARK
 * Here the sleeping lion will be awoken and eat much of CPU time !!!
 *
 * The result of setting VM86_SCREEN_BITMAP (at state of Linux 1.1.56):
 *   Each vm86 call will set 32 pages of video mem RD-only
 *    (there may be 1000000 per second)
 *   Write access to RD-only page results in page-fault (mm/memory.c),

 *   which will set a bit in current->screen_bitmap and calls do_wp_page()
 *   which does __get_free_page(GFP_KERNEL) but frees it immediatly, 
 *   because copy-on-write is not neccessary and sets RD/WR for the page.
 *   (this could happen 32000000 per second, if the CPU were fast enough)
 * It would be better to get the DIRTY-bit directly from the page table,
 * isn't it?  A special syscall in emumodule could do this.
 * DANG_END_REMARK
 */
#if VIDEO_CHECK_DIRTY
	if (!config_dualmon) {
	    vm86s.flags |= VM86_SCREEN_BITMAP;
	}
#endif

    }
    clear_screen(video_page, 7);

    return 0;
}
Exemplo n.º 5
0
int main(int argc, char **argv)
{
    Images images;
    int mode = 0; // 0 = encode, 1 = decode
    int method = 0; // 1=non-interlacing, 2=interlacing
    int quality = 100; // 100 = everything, positive value: partial decode, negative value: only rough data
    int learn_repeats = -1;
    int acb = -1; // try auto color buckets
    int scale = 1;
    int frame_delay = 100;
    int palette_size = 512;
    int lookback = 1;
    if (strcmp(argv[0],"flif") == 0) mode = 0;
    if (strcmp(argv[0],"dflif") == 0) mode = 1;
    if (strcmp(argv[0],"deflif") == 0) mode = 1;
    if (strcmp(argv[0],"decflif") == 0) mode = 1;
    static struct option optlist[] = {
        {"help", 0, NULL, 'h'},
        {"encode", 0, NULL, 'e'},
        {"decode", 0, NULL, 'd'},
        {"first", 1, NULL, 'f'},
        {"verbose", 0, NULL, 'v'},
        {"interlace", 0, NULL, 'i'},
        {"no-interlace", 0, NULL, 'n'},
        {"acb", 0, NULL, 'a'},
        {"no-acb", 0, NULL, 'b'},
        {"quality", 1, NULL, 'q'},
        {"scale", 1, NULL, 's'},
        {"palette", 1, NULL, 'p'},
        {"repeats", 1, NULL, 'r'},
        {"frame-delay", 1, NULL, 'f'},
        {"lookback", 1, NULL, 'l'},
        {0, 0, 0, 0}
    };
    int i,c;
    while ((c = getopt_long (argc, argv, "hedvinabq:s:p:r:f:l:", optlist, &i)) != -1) {
        switch (c) {
        case 'e': mode=0; break;
        case 'd': mode=1; break;
        case 'v': verbosity++; break;
        case 'i': if (method==0) method=2; break;
        case 'n': method=1; break;
        case 'a': acb=1; break;
        case 'b': acb=0; break;
        case 'p': palette_size=atoi(optarg);
                  if (palette_size < -1 || palette_size > 30000) {fprintf(stderr,"Not a sensible number for option -p\n"); return 1; }
                  if (palette_size == 0) {v_printf(2,"Palette disabled\n"); }
                  break;
        case 'q': quality=atoi(optarg);
                  if (quality < -1 || quality > 100) {fprintf(stderr,"Not a sensible number for option -q\n"); return 1; }
                  break;
        case 's': scale=atoi(optarg);
                  if (scale < 1 || scale > 128) {fprintf(stderr,"Not a sensible number for option -s\n"); return 1; }
                  break;
        case 'r': learn_repeats=atoi(optarg);
                  if (learn_repeats < 0 || learn_repeats > 1000) {fprintf(stderr,"Not a sensible number for option -r\n"); return 1; }
                  break;
        case 'f': frame_delay=atoi(optarg);
                  if (frame_delay < 0 || frame_delay > 60000) {fprintf(stderr,"Not a sensible number for option -f\n"); return 1; }
                  break;
        case 'l': lookback=atoi(optarg);
                  if (lookback < -1 || lookback > 256) {fprintf(stderr,"Not a sensible number for option -l\n"); return 1; }
                  break;
        case 'h':
        default: show_help(); return 0;
        }
    }
    argc -= optind;
    argv += optind;

  v_printf(3,"  _____  __  (__) _____");
  v_printf(3,"\n (___  ||  | |  ||  ___)   ");v_printf(2,"FLIF 0.1 [2 October 2015]");
  v_printf(3,"\n  (__  ||  |_|__||  __)    Free Lossless Image Format");
  v_printf(3,"\n    (__||______) |__)      (c) 2010-2015 J.Sneyers & P.Wuille, GNU GPL v3+\n");
  v_printf(3,"\n");
  if (argc == 0) {
        //fprintf(stderr,"Input file missing.\n");
        if (verbosity == 1) show_help();
        return 1;
  }
  if (argc == 1) {
        fprintf(stderr,"Output file missing.\n");
        show_help();
        return 1;
  }

    if (file_exists(argv[0])) {
            if (mode == 0 && file_is_flif(argv[0])) {
              v_printf(2,"Input file is a FLIF file, adding implicit -d\n");
              mode = 1;
            }
            char *f = strrchr(argv[0],'/');
            char *ext = f ? strrchr(f,'.') : strrchr(argv[0],'.');
            if (mode == 0) {
                    if (ext && ( !strcasecmp(ext,".png") ||  !strcasecmp(ext,".pnm") ||  !strcasecmp(ext,".ppm")  ||  !strcasecmp(ext,".pgm") ||  !strcasecmp(ext,".pbm") ||  !strcasecmp(ext,".pam"))) {
                          // ok
                    } else {
                          fprintf(stderr,"Warning: expected \".png\" or \".pnm\" file name extension for input file, trying anyway...\n");
                    }
            } else {
                    if (ext && ( !strcasecmp(ext,".flif")  || ( !strcasecmp(ext,".flf") ))) {
                          // ok
                    } else {
                          fprintf(stderr,"Warning: expected file name extension \".flif\" for input file, trying anyway...\n");
                    }
            }
    } else if (argc>0) {
          fprintf(stderr,"Input file does not exist: %s\n",argv[0]);
          return 1;
    }


  if (mode == 0) {
        int nb_input_images = argc-1;
        while(argc>1) {
          Image image;
          v_printf(2,"\r");
          if (!image.load(argv[0])) {
            fprintf(stderr,"Could not read input file: %s\n", argv[0]);
            return 2;
          };
          images.push_back(image);
          if (image.rows() != images[0].rows() || image.cols() != images[0].cols() || image.numPlanes() != images[0].numPlanes()) {
            fprintf(stderr,"Dimensions of all input images should be the same!\n");
            fprintf(stderr,"  First image is %ux%u, %i channels.\n",images[0].cols(),images[0].rows(),images[0].numPlanes());
            fprintf(stderr,"  This image is %ux%u, %i channels: %s\n",image.cols(),image.rows(),image.numPlanes(),argv[0]);
            return 2;
          }
          argc--; argv++;
          if (nb_input_images>1) {v_printf(2,"    (%i/%i)         ",(int)images.size(),nb_input_images); v_printf(4,"\n");}
        }
        v_printf(2,"\n");
        bool flat=true;
        for (Image &image : images) if (image.uses_alpha()) flat=false;
        if (flat && images[0].numPlanes() == 4) {
              v_printf(2,"Alpha channel not actually used, dropping it.\n");
              for (Image &image : images) image.drop_alpha();
        }
        uint64_t nb_pixels = (uint64_t)images[0].rows() * images[0].cols();
        std::vector<std::string> desc;
        desc.push_back("YIQ");  // convert RGB(A) to YIQ(A)
        desc.push_back("BND");  // get the bounds of the color spaces
        if (palette_size > 0)
          desc.push_back("PLA");  // try palette (including alpha)
        if (palette_size > 0)
          desc.push_back("PLT");  // try palette (without alpha)
        if (acb == -1) {
          // not specified if ACB should be used
          if (nb_pixels > 10000) desc.push_back("ACB");  // try auto color buckets on large images
        } else if (acb) desc.push_back("ACB");  // try auto color buckets if forced
        if (method == 0) {
          // no method specified, pick one heuristically
          if (nb_pixels < 10000) method=1; // if the image is small, not much point in doing interlacing
          else method=2; // default method: interlacing
        }
        if (images.size() > 1) {
          desc.push_back("DUP");  // find duplicate frames
          desc.push_back("FRS");  // get the shapes of the frames
          if (lookback != 0) desc.push_back("FRA");  // make a "deep" alpha channel (negative values are transparent to some previous frame)
        }
        if (learn_repeats < 0) {
          // no number of repeats specified, pick a number heuristically
          learn_repeats = TREE_LEARN_REPEATS;
          if (nb_pixels < 5000) learn_repeats--;        // avoid large trees for small images
          if (learn_repeats < 0) learn_repeats=0;
        }
        encode(argv[0], images, desc, method, learn_repeats, acb, frame_delay, palette_size, lookback);
  } else {
        char *ext = strrchr(argv[1],'.');
        if (ext && ( !strcasecmp(ext,".png") ||  !strcasecmp(ext,".pnm") ||  !strcasecmp(ext,".ppm")  ||  !strcasecmp(ext,".pgm") ||  !strcasecmp(ext,".pbm") ||  !strcasecmp(ext,".pam"))) {
                 // ok
        } else {
           fprintf(stderr,"Error: expected \".png\", \".pnm\" or \".pam\" file name extension for output file\n");
           return 1;
        }
        if (!decode(argv[0], images, quality, scale)) return 3;
        if (scale>1)
          v_printf(3,"Downscaling output: %ux%u -> %ux%u\n",images[0].cols(),images[0].rows(),images[0].cols()/scale,images[0].rows()/scale);
        if (images.size() == 1) {
          if (!images[0].save(argv[1],scale)) return 2;
        } else {
          int counter=0;
          std::vector<char> vfilename(strlen(argv[1])+6);
          char *filename = &vfilename[0];
          strcpy(filename,argv[1]);
          char *a_ext = strrchr(filename,'.');
          for (Image& image : images) {
             sprintf(a_ext,"-%03d%s",counter++,ext);
             if (!image.save(filename,scale)) return 2;
             v_printf(2,"    (%i/%i)         \r",counter,(int)images.size()); v_printf(4,"\n");
          }
        }
        v_printf(2,"\n");
  }
  for (Image &image : images) image.clear();
  return 0;
}
Exemplo n.º 6
0
 void simplify(int divisor=CONTEXT_TREE_COUNT_DIV, int min_size=CONTEXT_TREE_MIN_SUBTREE_SIZE) {
     v_printf(10,"TREE BEFORE SIMPLIFICATION:\n");
     simplify_subtree(0, divisor, min_size, 0);
 }
Exemplo n.º 7
0
static inline void reserve_video_memory(void)
{
#if USE_DUALMON
    if (!config.max_umb || config.dualmon) {
#else
    if (!config.max_umb) {
#endif
        if (config.dualmon)
	    v_printf("CONF: Unable to maximize UMB's due to dual monitor setup\n");
	if (config.mem_size > 640) {
	    /* memcheck_reserve('v', config.mem_size * 1024, 0xC0000 - addr_start); */
	} else {
	    /* memcheck_reserve('v', GRAPH_BASE, GRAPH_SIZE); */
	}
    } else {
	int graph_base, graph_size;

	/* Okay, the usual procedure would be to reserve 128K of memory for
	   video unconditionally.  Clearly this is insane.  If you're running
	   in an x-term or across the network, you're wasting memory. */

	v_printf("CONF: Trying to set minimum video memory to maximize UMB's\n");

	if (config.usesX) {
	    graph_base = 0xB0000;
	    graph_size = 64 * 1024;
	    v_printf("CONF: X-Windows.  Assuming %uKB video memory @ 0x%5.5X\n",
		     graph_size / 1024, graph_base);
	} else if (!config.console_video) {
	    graph_base = 0xB0000;
	    graph_size = 64 * 1024;
	    v_printf("CONF: remote session.  Assuming %uKB video memory @ 0x%5.5X\n",
		     graph_size / 1024, graph_base);
	} else {
	    switch (config.cardtype) {
	    case CARD_MDA:
		graph_base = 0xB0000;
		graph_size = 64 * 1024;
		v_printf("CONF: MDA video card w/%uKB video memory @ 0x%5.5X\n",
			 graph_size / 1024, graph_base);
		break;
	    case CARD_CGA:
		graph_base = 0xB8000;
		graph_size = 32 * 1024;
		v_printf("CONF: CGA video card w/%uKB video memory @ 0x%5.5X\n",
			 graph_size / 1024, graph_base);
		break;
	    case CARD_EGA:
		graph_base = 0xB0000;
		graph_size = 64 * 1024;
		v_printf("CONF: EGA video card w/%uKB video memory @ 0x%5.5X\n",
			 graph_size / 1024, graph_base);
		break;
	    case CARD_VGA:
		graph_base = 0xA0000;
		graph_size = 128 * 1024;
		v_printf("CONF: VGA video card w/%uKB video memory @ 0x%5.5X\n",
			 graph_size / 1024, graph_base);
		break;
	    default:
		graph_base = 0xA0000;
		graph_size = 128 * 1024;
		v_printf("CONF: default video, guessing %uKB video memory @ 0x%5.5X\n",
			 graph_size / 1024, graph_base);
		break;
	    }
	}
	debug("graph_base=0x%08x  size=0x%08x\n", graph_base, graph_size);
    }
}


#if 0
void gettermcap(int i)
{
    struct winsize ws;		/* buffer for TIOCSWINSZ */

    li = LI;
    co = CO;
    if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) >= 0) {
	li = ws.ws_row;
	co = ws.ws_col;
    }
    if (li == 0 || co == 0) {

	error("unknown window sizes li=%d  co=%d, setting to 80x25\n", li, co);
	li = LI;
	co = CO;
    } else
	v_printf("VID: Setting windows size to li=%d, co=%d\n", li, co);
    get_screen_size();
    set_video_bios_size();
}
#endif

void set_video_bios_size(void)
{
    WRITE_WORD(BIOS_SCREEN_COLUMNS, co);	/* chars per line */
    WRITE_BYTE(BIOS_ROWS_ON_SCREEN_MINUS_1, li - 1); /* lines on screen - 1 */
    WRITE_WORD(BIOS_VIDEO_MEMORY_USED, TEXT_SIZE);   /* size of video regen area in bytes */
}
Exemplo n.º 8
0
bool encode_flif(int argc, char **argv, Images &images, int palette_size, int acb, flifEncodingOptional method, int lookback,
                 int learn_repeats, std::vector<int> &frame_delay, int divisor=CONTEXT_TREE_COUNT_DIV, int min_size=CONTEXT_TREE_MIN_SUBTREE_SIZE,
                 int split_threshold=CONTEXT_TREE_SPLIT_THRESHOLD, int yiq=1, int plc=1, int frs=1, int cutoff=2, int alpha=19) {
    bool flat=true;
    unsigned int framenb=0;
    for (Image& i : images) { i.frame_delay = frame_delay[framenb]; if (framenb+1 < frame_delay.size()) framenb++; }
    for (Image &image : images) if (image.uses_alpha()) flat=false;
    if (flat && images[0].numPlanes() == 4) {
        v_printf(2,"Alpha channel not actually used, dropping it.\n");
        for (Image &image : images) image.drop_alpha();
    }
    bool grayscale=true;
    for (Image &image : images) if (image.uses_color()) grayscale=false;
    if (grayscale && images[0].numPlanes() == 3) {
        v_printf(2,"Chroma not actually used, dropping it.\n");
        for (Image &image : images) image.drop_color();
    }
    uint64_t nb_pixels = (uint64_t)images[0].rows() * images[0].cols();
    std::vector<std::string> desc;
    if (nb_pixels > 2) {         // no point in doing anything for 1- or 2-pixel images
      if (plc) {
        desc.push_back("Channel_Compact");  // compactify channels
      }
      if (yiq) {
        desc.push_back("YCoCg");  // convert RGB(A) to YCoCg(A)
      }
      desc.push_back("Bounds");  // get the bounds of the color spaces
    }
    if (palette_size == -1) {
        palette_size = 1024;
        if (nb_pixels * images.size() / 2 < 1024) {
          palette_size = nb_pixels * images.size() / 2;
        }
    }
    if (palette_size != 0) {
        desc.push_back("Palette_Alpha");  // try palette (including alpha)
    }
    if (palette_size != 0) {
        desc.push_back("Palette");  // try palette (without alpha)
    }

    if (acb == -1) {
      // not specified if ACB should be used
      if (nb_pixels * images.size() > 10000) {
        desc.push_back("Color_Buckets");  // try auto color buckets on large images
      }
    } else if (acb) {
      desc.push_back("Color_Buckets");  // try auto color buckets if forced
    }
    if (method.o == Optional::undefined) {
        // no method specified, pick one heuristically
        if (nb_pixels * images.size() < 10000) method.encoding=flifEncoding::nonInterlaced; // if the image is small, not much point in doing interlacing
        else method.encoding=flifEncoding::interlaced; // default method: interlacing
    }
    if (images.size() > 1) {
        desc.push_back("Duplicate_Frame");  // find duplicate frames
        if (frs) desc.push_back("Frame_Shape");  // get the shapes of the frames
        if (lookback) desc.push_back("Frame_Lookback");  // make a "deep" alpha channel (negative values are transparent to some previous frame)
    }
    if (learn_repeats < 0) {
        // no number of repeats specified, pick a number heuristically
        learn_repeats = TREE_LEARN_REPEATS;
        if (nb_pixels * images.size() < 5000) learn_repeats--;        // avoid large trees for small images
        if (learn_repeats < 0) learn_repeats=0;
    }
    FILE *file = fopen(argv[0],"wb");
    if (!file)
        return false;
    FileIO fio(file, argv[0]);
    return flif_encode(fio, images, desc, method.encoding, learn_repeats, acb, palette_size, lookback, divisor, min_size, split_threshold, cutoff, alpha);
}
Exemplo n.º 9
0
int main(int argc, char **argv)
{
    Images images;
#ifdef HAS_ENCODER
    int mode = 0; // 0 = encode, 1 = decode, 2 = transcode
    flifEncodingOptional method;
    int learn_repeats = -1;
    int acb = -1; // try auto color buckets
    std::vector<int> frame_delay;
    frame_delay.push_back(100);
    int palette_size = -1;
    int lookback = 1;
    int divisor=CONTEXT_TREE_COUNT_DIV;
    int min_size=CONTEXT_TREE_MIN_SUBTREE_SIZE;
    int split_threshold=CONTEXT_TREE_SPLIT_THRESHOLD;
    int yiq = 1;
    int plc = 1;
    int frs = 1;
    bool alpha_zero_special = true;
    int alpha=19;
    int cutoff=2;
#else
    int mode = 1;
#endif
    int quality = 100; // 100 = everything, positive value: partial decode, negative value: only rough data
    int scale = 1;
    int resize_width = 0, resize_height = 0;
    bool showhelp = false;
    if (strcmp(argv[0],"flif") == 0) mode = 0;
    if (strcmp(argv[0],"dflif") == 0) mode = 1;
    if (strcmp(argv[0],"deflif") == 0) mode = 1;
    if (strcmp(argv[0],"decflif") == 0) mode = 1;
    static struct option optlist[] = {
        {"help", 0, NULL, 'h'},
        {"decode", 0, NULL, 'd'},
        {"verbose", 0, NULL, 'v'},
        {"quality", 1, NULL, 'q'},
        {"scale", 1, NULL, 's'},
        {"resize", 1, NULL, 'r'},
        {"identify", 0, NULL, 'i'},
        {"version", 0, NULL, 'V'},
#ifdef HAS_ENCODER
        {"encode", 0, NULL, 'e'},
        {"transcode", 0, NULL, 't'},
        {"interlace", 0, NULL, 'I'},
        {"no-interlace", 0, NULL, 'N'},
        {"frame-delay", 1, NULL, 'F'},
        {"keep-invisible-rgb", 0, NULL, 'K'},
        {"max-palette-size", 1, NULL, 'P'},
        {"force-color-buckets", 0, NULL, 'A'},
        {"no-color-buckets", 0, NULL, 'B'},
        {"no-ycocg", 0, NULL, 'Y'},
        {"no-channel-compact", 0, NULL, 'C'},
        {"max-frame-lookback", 1, NULL, 'L'},
        {"no-frame-shape", 0, NULL, 'S'},
        {"maniac-repeats", 1, NULL, 'R'},
        {"maniac-divisor", 1, NULL, 'D'},
        {"maniac-min-size", 1, NULL, 'M'},
        {"maniac-threshold", 1, NULL, 'T'},
        {"chance-cutoff", 1, NULL, 'X'},
        {"chance-alpha", 1, NULL, 'Z'},
#endif
        {0, 0, 0, 0}
    };
    int i,c;
#ifdef HAS_ENCODER
    while ((c = getopt_long (argc, argv, "hdviVq:s:r:etINnF:KP:ABYCL:SR:D:M:T:X:Z:", optlist, &i)) != -1) {
#else
    while ((c = getopt_long (argc, argv, "hdviVq:s:r:", optlist, &i)) != -1) {
#endif
        switch (c) {
        case 'd': mode=1; break;
        case 'v': increase_verbosity(); break;
        case 'V': increase_verbosity(3); break;
        case 'q': quality=atoi(optarg);
                  if (quality < 0 || quality > 100) {e_printf("Not a sensible number for option -q\n"); return 1; }
                  break;
        case 's': scale=atoi(optarg);
                  if (scale < 1 || scale > 128) {e_printf("Not a sensible number for option -s\n"); return 1; }
                  break;
        case 'r': if (sscanf(optarg,"%ix%i", &resize_width, &resize_height) < 1) {e_printf("Not a sensible value for option -r (expected WxH)\n"); return 1; }
                  if (!resize_height) resize_height = resize_width;
                  break;
        case 'i': scale = -1; break;
#ifdef HAS_ENCODER
        case 'e': mode=0; break;
        case 't': mode=2; break;
        case 'I': method.encoding=flifEncoding::interlaced; break;
        case 'n': // undocumented: lower case -n still works
        case 'N': method.encoding=flifEncoding::nonInterlaced; break;
        case 'A': acb=1; break;
        case 'B': acb=0; break;
        case 'P': palette_size=atoi(optarg);
                  if (palette_size < -32000 || palette_size > 32000) {e_printf("Not a sensible number for option -P\n"); return 1; }
                  if (palette_size == 0) {v_printf(5,"Palette disabled\n"); }
                  break;
        case 'R': learn_repeats=atoi(optarg);
                  if (learn_repeats < 0 || learn_repeats > 20) {e_printf("Not a sensible number for option -R\n"); return 1; }
                  break;
        case 'F': frame_delay.clear();
                  while(optarg != 0) {
                    int d=strtol(optarg,&optarg,10);
                    if (d==0) break;
                    if (*optarg == ',' || *optarg == '+') optarg++;
                    frame_delay.push_back(d);
                    if (d < 0 || d > 60000) {e_printf("Not a sensible number for option -F: %i\n",d); return 1; }
                  }
                  if (frame_delay.size() < 1) frame_delay.push_back(100);
                  break;
        case 'L': lookback=atoi(optarg);
                  if (lookback < -1 || lookback > 256) {e_printf("Not a sensible number for option -L\n"); return 1; }
                  break;
        case 'D': divisor=atoi(optarg);
                  if (divisor <= 0 || divisor > 0xFFFFFFF) {e_printf("Not a sensible number for option -D\n"); return 1; }
                  break;
        case 'M': min_size=atoi(optarg);
                  if (min_size < 0) {e_printf("Not a sensible number for option -M\n"); return 1; }
                  break;
        case 'T': split_threshold=atoi(optarg);
                  if (split_threshold <= 3 || split_threshold > 100000) {e_printf("Not a sensible number for option -T\n"); return 1; }
                  split_threshold *= 5461;
                  break;
        case 'Y': yiq=0; break;
        case 'C': plc=0; break;
        case 'S': frs=0; break;
        case 'K': alpha_zero_special=false; break;
        case 'X': cutoff=atoi(optarg);
                  if (cutoff < 1 || cutoff > 128) {e_printf("Not a sensible number for option -X (try something between 1 and 128)\n"); return 1; }
                  break;
        case 'Z': alpha=atoi(optarg);
                  if (alpha < 2 || alpha > 128) {e_printf("Not a sensible number for option -Z (try something between 2 and 128)\n"); return 1; }
                  break;
#endif
        case 'h': showhelp=true; break;
        default: show_help(); return 0;
        }
    }
    argc -= optind;
    argv += optind;

    show_banner();
    if (argc == 0 || showhelp) {
        if (get_verbosity() == 1 || showhelp) show_help();
        return 0;
    }

    if (argc == 1 && scale != -1) {
        show_help();
        e_printf("\nOutput file missing.\n");
        return 1;
    }
    if (scale == -1) mode = 1;
    if (file_exists(argv[0])) {
        char *f = strrchr(argv[0],'/');
        char *ext = f ? strrchr(f,'.') : strrchr(argv[0],'.');
#ifdef HAS_ENCODER
        if (mode == 0 && file_is_flif(argv[0])) {
            char *f = strrchr(argv[1],'/');
            char *ext = f ? strrchr(f,'.') : strrchr(argv[1],'.');
            if ((ext && ( !strcasecmp(ext,".flif")  || ( !strcasecmp(ext,".flf") )))) {
                v_printf(3,"Input and output file are both FLIF file, adding implicit -t\n");
                mode = 2;
            } else {
                v_printf(3,"Input file is a FLIF file, adding implicit -d\n");
                mode = 1;
            }
        }
        if (mode != 0) {
#endif
            if (!(ext && ( !strcasecmp(ext,".flif")  || ( !strcasecmp(ext,".flf") )))) {
                e_printf("Warning: expected file name extension \".flif\" for input file, trying anyway...\n");
            }
#ifdef HAS_ENCODER
        } else {
            if (!check_compatible_extension(ext)) {
                e_printf("Warning: expected \".png\", \".pnm\" or \".pam\" file name extension for input file, trying anyway...\n");
            }
        }
#endif
    } else if (argc>0) {
        e_printf("Input file does not exist: %s\n",argv[0]);
        return 1;
    }
    if (mode > 0 && argc > 2 && scale != -1) {
        e_printf("Too many arguments.\n");
        return 1;
    }

#ifdef HAS_ENCODER
    if (mode == 0) {
        if (!handle_encode(argc, argv, images, palette_size, acb, method, lookback, learn_repeats, frame_delay, divisor, min_size, split_threshold, yiq, plc, alpha_zero_special, frs, cutoff, alpha)) return 2;
    } else if (mode == 1) {
#endif
        return handle_decode(argc, argv, images, quality, scale, resize_width, resize_height);
#ifdef HAS_ENCODER
    } else if (mode == 2) {
//        if (scale > 1) {e_printf("Not yet supported: transcoding downscaled image; use decode + encode!\n");}
        if (!decode_flif(argv, images, quality, scale, resize_width, resize_height)) return 2;
        argc--; argv++;
        if (!encode_flif(argc, argv, images, palette_size, acb, method, lookback, learn_repeats, frame_delay, divisor, min_size, split_threshold, yiq, plc, frs, cutoff, alpha)) return 2;
    }
#endif
    return 0;
}
Exemplo n.º 10
0
void do_vesa_int()
{
  int err_code = VBE_ERROR_GENERAL_FAIL;

#if 0
  v_printf(
    "VBE: function 0x%02x, bx = 0x%04x cx = 0x%04x, dx = 0x%04x, es = 0x%04x, di = 0x%04x\n",
    (unsigned) _AL, (unsigned) _BX, (unsigned) _CX, (unsigned) _DX, (unsigned) _ES, (unsigned) _DI
  );
#endif

  switch(_AL) {
    case 0x00:		/* return VBE controller info */
      err_code = vbe_info(SEGOFF2LINEAR(_ES, _DI));
      break;

    case 0x01:		/* return VBE mode info */
      err_code = vbe_mode_info(_CX, SEGOFF2LINEAR(_ES, _DI));
      break;

    case 0x02:		/* set VBE mode */
      err_code = vbe_set_mode(_BX);
      break;

    case 0x03:		/* get current VBE mode */
      err_code = vbe_get_mode();
      break;

    case 0x04:		/* save/restore state */
      err_code = vbe_save_restore(_DL, _CX, SEGOFF2LINEAR(_ES, _BX));
      break;

    case 0x05:		/* display window control (aka set/get bank) */
      err_code = vbe_display_window(_BH, _BL, _DL /* must be _DX !!!*/);
      break;

    case 0x06:		/* set/get logical scan line length */
      err_code = vbe_scan_length(_BL, _CX);
      break;

    case 0x07:		/* set/get display start */
      err_code = vbe_display_start(_BL, _CX, _DX);
      break;

    case 0x08:		/* set/get DAC palette format */
      err_code = vbe_dac_format(_BL, _BH);
      break;

    case 0x09:		/* set/get palette data */
      err_code = vbe_palette_data(_BL, _CX, _DX, SEGOFF2LINEAR(_ES, _DI));
      break;

    case 0x0a:		/* return VBE PM interface */
      err_code = vbe_pm_interface(_BL);
      break;

    case 0x10:		/* set/get display power state */
      err_code = vbe_power_state(_BL, _BH);
      break;

    default:
      err_code = VBE_ERROR_UNSUP;
#ifdef DEBUG_VBE
      v_printf(
        "VBE: unsupported function 0x%02x, retval = %d, bx = 0x%04x cx = 0x%04x, dx = 0x%04x, es = 0x%04x, di = 0x%04x\n",
        (unsigned) _AL, err_code, (unsigned) _BX, (unsigned) _CX, (unsigned) _DX, (unsigned) _ES, (unsigned) _DI
      );
#endif
  }

 if(err_code >= 0) {
   _AL = 0x4f;
   _AH = (unsigned char) err_code;
 }
}
Exemplo n.º 11
0
void show_banner() {
    v_printf(3,"  ____ _(_)____\n");
    v_printf(3," (___ | | | ___)   ");v_printf(2,"FLIF (Free Lossless Image Format) 0.2.0rc5 [17 Jan 2016]\n");
    v_printf(3,"  (__ | |_| __)    ");v_printf(2,"Copyright (C) 2016 Jon Sneyers and Pieter Wuille\n");
    v_printf(3,"    (_|___|_)      ");v_printf(2,"License GPLv3+: GNU GPL version 3 or later\n");
    v_printf(3,"\n");
    v_printf(4,"This is free software: you are free to change and redistribute it.\n");
    v_printf(4,"There is NO WARRANTY, to the extent permitted by law.\n");
#ifndef HAS_ENCODER
    v_printf(2,"Non-default compile-option: DECODER ONLY\n");
#endif
#ifndef SUPPORT_HDR
    v_printf(2,"Non-default compile-option: 8-BIT ONLY\n");
#endif
#ifndef FAST_BUT_WORSE_COMPRESSION
    v_printf(2,"Non-default compile-option: SLOWER, BETTER COMPRESSION (CANNOT ENCODE/DECODE NORMAL FLIF FILES!)\n");
#endif
}
Exemplo n.º 12
0
void vbe_pre_init(void)
{
  int i;
  vga_mode_info *vmi = NULL;
  unsigned int dos_vga_bios = SEGOFF2LINEAR(0xc000,0x0000);
  int bios_ptr = (char *) vgaemu_bios_end - (char *) vgaemu_bios_start;

  static struct {
    char modes[3];
    char reserved1[4];
    char scanlines;
    char character_blocks;
    char max_active_blocks;
    short support_flags;
    short reserved2;
    char save_function_flags;
    char reserved3;
  } vgaemu_bios_functionality_table =
  { .modes =		 {0xff,0xe0,0x0f}, /* Modes 0-7, 0dh-0fh, 10h-13h supported */
    .scanlines =	 7,		   /* scanlines 200,350,400 supported */
    .character_blocks =  2,		   /* This all corresponds to a real BIOS */
    .max_active_blocks = 8,		   /* See Ralf Brown's interrupt list */
    .support_flags =	 0xeff,		   /* INT 10h, AH=1b for documentation */
    .save_function_flags=0x3f
  };

  MEMSET_DOS(dos_vga_bios, 0, VBE_BIOS_MAXPAGES << 12);	/* one page */
  MEMCPY_2DOS(dos_vga_bios, vgaemu_bios_start, bios_ptr);

  vgaemu_bios.prod_name = (char *) vgaemu_bios_prod_name - (char *) vgaemu_bios_start;

  if (Video->setmode) {
    i = (char *) vgaemu_bios_pm_interface_end - (char *) vgaemu_bios_pm_interface;

    if(i + bios_ptr > (VBE_BIOS_MAXPAGES << 12) - 8) {
      error("VBE: vbe_init: protected mode interface to large, disabling\n");
      vgaemu_bios.vbe_pm_interface_len =
	vgaemu_bios.vbe_pm_interface = 0;
    }

    vgaemu_bios.vbe_pm_interface_len = i;
    vgaemu_bios.vbe_pm_interface = bios_ptr;
    MEMCPY_2DOS(dos_vga_bios + bios_ptr, vgaemu_bios_pm_interface, i);
    bios_ptr += i;

    bios_ptr = (bios_ptr + 3) & ~3;
    vgaemu_bios.vbe_mode_list = bios_ptr;

    /* set up video mode list */
    for(i = 0x100; i <= vgaemu_bios.vbe_last_mode; i++) {
      if((vmi = vga_emu_find_mode(i, NULL))) {
	if(vmi->VESA_mode != -1 && bios_ptr < ((VBE_BIOS_MAXPAGES << 12) - 4)) {
	  WRITE_WORD(dos_vga_bios + bios_ptr, vmi->VESA_mode);
	  bios_ptr += 2;
	}
      }
    }

    WRITE_WORD(dos_vga_bios + bios_ptr, -1);
    bios_ptr += 2;

    /* add fonts */
    vgaemu_bios.font_8 = bios_ptr;
    MEMCPY_2DOS(dos_vga_bios + bios_ptr, vga_rom_08, sizeof vga_rom_08);
    bios_ptr += sizeof vga_rom_08;

    vgaemu_bios.font_14 = bios_ptr;
    MEMCPY_2DOS(dos_vga_bios + bios_ptr, vga_rom_14, sizeof vga_rom_14);
    bios_ptr += sizeof vga_rom_14;

    vgaemu_bios.font_16 = bios_ptr;
    MEMCPY_2DOS(dos_vga_bios + bios_ptr, vga_rom_16, sizeof vga_rom_16);
    bios_ptr += sizeof vga_rom_16;

    vgaemu_bios.font_14_alt = bios_ptr;
    MEMCPY_2DOS(dos_vga_bios + bios_ptr, vga_rom_14_alt, sizeof vga_rom_14_alt);
    bios_ptr += sizeof vga_rom_14_alt;

    vgaemu_bios.font_16_alt = bios_ptr;
    MEMCPY_2DOS(dos_vga_bios + bios_ptr, vga_rom_16_alt, sizeof vga_rom_16_alt);
    bios_ptr += sizeof vga_rom_16_alt;
  } else {
    /* only support the initial video mode, can't change it */
    vgaemu_bios_functionality_table.modes[0] = 1 << video_mode;
    vgaemu_bios_functionality_table.modes[1] =
      vgaemu_bios_functionality_table.modes[2] = 0;
  }
  vgaemu_bios.functionality = bios_ptr;
  MEMCPY_2DOS(dos_vga_bios + bios_ptr, &vgaemu_bios_functionality_table,
      sizeof vgaemu_bios_functionality_table);
  bios_ptr += sizeof vgaemu_bios_functionality_table;

  vgaemu_bios.size = bios_ptr;

  WRITE_BYTE(dos_vga_bios + 2, (bios_ptr + ((1 << 9) - 1)) >> 9);
  vgaemu_bios.pages = (bios_ptr + ((1 << 12) - 1)) >> 12;

  if (config.vgaemubios_file) {
    /* EXPERIMENTAL: load and boot the Bochs BIOS */
    int fd = open(config.vgaemubios_file, O_RDONLY);
    int bytes;
    if (fd != -1) {
      bytes = read(fd, LINEAR2UNIX(0xc0000), 65536);
      close(fd);
      vgaemu_bios.pages = (bytes + PAGE_SIZE - 1) / PAGE_SIZE;
      config.vbios_post = 1;
    }
  }

  memcheck_addtype('V', "VGAEMU Video BIOS");
  memcheck_reserve('V', dos_vga_bios, vgaemu_bios.pages << 12);

  if(!config.X_pm_interface) {
    v_printf("VBE: vbe_init: protected mode interface disabled\n");
  }

  v_printf(
    "VBE: vbe_init: %d pages for VGA BIOS, vga.mem.base = %p\n",
    vgaemu_bios.pages, vga.mem.base
  );
}
Exemplo n.º 13
0
int
main(int argc, char **argv)
{
   int /*ch, */ i, ii, ret, err_flag = 0;

   clock_t beg, end, Beg, End;

   int files = 0;

   struct tms ts;

   char buf[256];

   char *e;

   prgname = strrchr(argv[0], '/');

   if (prgname)
      prgname++;
   else
      prgname = argv[0];

   e = getenv("CLIP_HOSTCS");
   if (e && *e)
   {
      sourceCharset = targetCharset = strdup(e);
   }
   else if (!e)
   {
      e = getenv("CLIP_LANG");
      if (e == NULL)
	 e = getenv("LANG");
      if (!e || !*e || !strcmp(e, "C"))
	 e = getenv("LC_MESSAGES");
      if (!e || !*e || !strcmp(e, "C"))
	 e = getenv("LC_ALL");
      if (e && *e)
      {
	 char *s = strrchr(e, '.');

	 if (s)
	 {
	    snprintf(buf, sizeof(buf), "%s", s + 1);
	    for (s = buf; *s; s++)
	       *s = tolower(*s);
	    sourceCharset = targetCharset = strdup(buf);
	 }
      }
   }

   {
      e = getenv("CLIP_LANG");
      if (e == NULL)
	 e = getenv("LANG");
      if (!e || !*e || !strcmp(e, "C"))
	 e = getenv("LC_MESSAGES");
      if (!e || !*e || !strcmp(e, "C"))
	 e = getenv("LC_ALL");
      if (e && *e)
      {
	 char *s = strrchr(e, '.');

	 if (s)
	 {
	    snprintf(buf, sizeof(buf), "%s", s + 1);
	    for (s = buf; *s; s++)
	       *s = tolower(*s);
	    out_charset = strdup(buf);
	 }
      }
   }

   {
      char *locale;

      locale = getenv("CLIP_LANG");
      if (!locale || !*locale)
	 locale = getenv("LANG");
      /*if (locale && *locale &&
         strcasecmp(locale, "C") && strcasecmp(locale, "POSIX")) */
      /*
         setlocale(LC_ALL, locale);
       */
   }

   if (!sourceCharset)
      sourceCharset = targetCharset = strdup("c");

   getEnvironment();

   init_Coll(&includePaths, NULL, NULL);
   init_Coll(&lib_dirs, NULL, NULL);
   init_Coll(&arglibs, NULL, NULL);

#if 1
   insert_Coll(&includePaths, ".");
   snprintf(buf, sizeof(buf), "%s/include", CLIPROOT);
   insert_Coll(&includePaths, strdup(buf));
#ifdef STD_LIBDIR
   snprintf(buf, sizeof(buf), STD_LIB_DIR);
   insert_Coll(&lib_dirs, strdup(buf));
#endif
   snprintf(buf, sizeof(buf), "%s/lib", CLIPROOT);
   insert_Coll(&lib_dirs, strdup(buf));
#endif
   init_Coll(&predefines, NULL, NULL);
   init_Coll(&poName, NULL, NULL);
   init_Coll(&paName, NULL, NULL);
   init_Coll(&include_files, NULL, NULL);

   snprintf(buf, sizeof(buf), "__CLIP__=\"%s\"", CLIP_VERSION);
   append_Coll(&predefines, strdup(buf));

   init_module();

   {
      char buf[256], *s;

      s = getenv("HOME");
      if (s && *s)
      {
	 snprintf(buf, sizeof(buf), "%s/.cliprc", s);
	 getrc(buf);
      }

   }

   getrc(".cliprc");

   {
      char buf[256], *s;

      DIR *dp;

      s = CLIPROOT;
      if (s && *s)
      {
	 snprintf(buf, sizeof(buf), "%s/.cliprc", s);
	 getrc(buf);
      }

      snprintf(buf, sizeof(buf), "%s/cliprc", CLIPROOT);
      dp = opendir(buf);
      if (dp)
      {
	 struct dirent *ep;

	 struct stat st;

	 Coll files;

	 int i;

	 init_Coll(&files, free, strcmp);
	 while ((ep = readdir(dp)))
	 {
	    snprintf(buf, sizeof(buf), "%s/cliprc/%s", CLIPROOT, ep->d_name);
	    if (stat(buf, &st))
	       continue;
	    if (!S_ISREG(st.st_mode))
	       continue;
	    if (access(buf, R_OK))
	       continue;
	    insert_Coll(&files, strdup(buf));
	 }
	 closedir(dp);

	 for (i = 0; i < files.count_of_Coll; i++)
	 {
		 char *name = (char *) files.items_of_Coll[i];

	    getrc(name);
	 }

	 destroy_Coll(&files);
      }
   }

   argc--;
   argv++;
   get_opt(argc, argv);

   argc -= optind;
   argv += optind;

   if (err_flag)
      return 1;

#if 0
   insert_Coll(&includePaths, ".");
   snprintf(buf, sizeof(buf), "%s/include", CLIPROOT);
   insert_Coll(&includePaths, strdup(buf));
#ifdef STD_LIBDIR
   snprintf(buf, sizeof(buf), STD_LIBDIR);
   insert_Coll(&lib_dirs, strdup(buf));
#endif
   snprintf(buf, sizeof(buf), "%s/lib", CLIPROOT);
   insert_Coll(&lib_dirs, strdup(buf));
#endif

   if (syntax_tree_flag)
   {
      write_obj_flag = 0;
      codegen_flag = 1;
      compile_flag = 0;
      pcode_flag = 0;
      pc_flag = 0;
      asm_flag = 0;
      exec_flag = 0;
   }

   if (!write_obj_flag)
   {
      /*codegen_flag = 0; */
      compile_flag = 0;
   }
   if (preproc_flag)
   {
      write_obj_flag = 0;
      codegen_flag = 0;
      syntax_tree_flag = 0;
      compile_flag = 0;
      exec_flag = 0;
      pcode_flag = 0;
      pc_flag = 0;
      asm_flag = 0;
      shared_flag = 0;
   }

   if (pcode_flag)
   {
      pc_flag = 0;
      asm_flag = 0;
      shared_flag = 0;
   }

   if (pc_flag)
   {
      pcode_flag = 1;
#ifdef USE_AS
      if (use_asm)
	 asm_flag = 1;
      else
	 asm_flag = 0;
#endif
   }

   if (xpc_flag)
   {
      pcode_flag = 1;
      pc_flag = 1;
#ifdef USE_AS
      if (use_asm)
	 asm_flag = 0;
      else
	 asm_flag = 1;
#endif
   }

#if 0
   if (shared_flag && pcode_flag)
   {
      v_printf(0, "conflict between -s and -p flags\n");
      exit(1);
   }
#endif

   if (pcode_flag && c_flag)
   {
      v_printf(0, "conflict between -c and -p flags\n");
      exit(1);
   }

   /*if ( exec_flag && !main_flag && !shared_flag)
      {
      v_printf(0, "-e(xec) flag without -M(ain) or -s(hared) flags\n");
      exit(2);
      } */

   if (pcode_flag)
   {
      compile_flag = 0;
   }

   if (nomain_flag && main_flag)
   {
      v_printf(0, "conflict between -n and -m flags\n");
      exit(1);
   }

   if (!exec_flag && oname)
   {
      char *e;

      if (oname[0] == '/')
	 snprintf(buf, sizeof(buf), "%s", oname);
      else
	 snprintf(buf, sizeof(buf), "%s%s%s", outdir ? outdir : "", outdir ? "/" : "", oname);
      e = strrchr(buf, '/');
      if (e)
      {
	 *e = 0;
	 outdir = strdup(buf);
      }
   }

   if (!outdir)
      outdir = ".";

   if (outdir)
   {
      char cdir[256];

      getcwd(cdir, sizeof(cdir));

      if (!chdir(outdir))
      {
	 getcwd(buf, sizeof(buf));
	 outdir = strdup(buf);
	 chdir(cdir);
      }
      else
      {
	 yyerror("cannot change to output dir '%s': %s", outdir, strerror(errno));
	 exit(1);
      }
   }

   if (!preproc_flag)
   {
      v_printf(2, "set source charset to %s\n", sourceCharset);
      v_printf(2, "set target charset to %s\n", targetCharset);
   }

   init_lex();
   init_parser();

   if (argc < 1)
      ii = -1;
   else
      ii = 0;

   Beg = times(&ts);
   if (argc > 0)
   {
      for (i = 0; i < argc; i++)
      {
	 char *e;

	 e = argv[i];
	 if (e[0] == '-' && e[1] == 'L')
	 {
	    insert_Coll(&lib_dirs, strdup(e + 2));
	    continue;
	 }
	 e = strrchr(argv[i], '.');
	 if (!e)
	 {
	    e = argv[i];
	    if (e[0] == '-' && e[1] == 'l')
	       /*append_Coll(&arglibs, strdup(e+2)) */ ;
	    else
	       yyerror("unknown file type '' file '%s'", argv[i]);
	    continue;
	 }
	 else if (!strcasecmp(e, ".po"))
	    insert_Coll(&poName, strdup(argv[i]));
	 else if (!strcasecmp(e, ".pa"))
	    insert_Coll(&paName, strdup(argv[i]));
	 else if (strcasecmp(e, ".prg") && strcasecmp(e, ".c") && strcasecmp(e, ".cc") && strcasecmp(e, OBJSUF) && strcasecmp(e, SOBJSUF) && strcasecmp(e, ".a") && strcasecmp(e, ".lib"))
	 {
	    /*yywarning("unknown file type '%s' file '%s'", e, argv[i]); */
	    continue;
	 }
      }
   }

   for (; clic_errorcount == 0 && ii < argc; ii++)
   {
      ++files;
      if (ii < 0)
      {
	 v_printf(1, "no input files, so use stdin; -h will help\n");
	 fflush(stderr);
	 set_locale_name("stdin");
	 ret = clic_parse("stdin", stdin);
	 add_name("stdin");
      }
      else
      {
	 char *e;

	 e = strrchr(argv[ii], '.');
	 add_name(argv[ii]);

	 if (!e)
	    continue;
	 else if (!strcasecmp(e, ".c") || !strcasecmp(e, ".cc") || !strcasecmp(e, ".cpp"))
	 {
	    if (!preproc_flag)
	    {
	       v_printf(1, "process file '%s' ..", argv[ii]);
	       v_neednl = 1;
	    }

	    beg = times(&ts);
	    compile_CFile(argv[ii]);
	    end = times(&ts);

	    if (!preproc_flag)
	    {
	       v_neednl = 0;
	       if (clic_errorcount == 0)
		  v_printf(1, ".. done, %s\n", diff_clock(beg, end));
	       else
		  pr_errorcount(1);
	    }
	    continue;
	 }
	 else if (strcasecmp(e, ".prg"))
	 {
	    continue;
	 }

	 if (ii > 0)
	    main_flag = 0;

	 if (!preproc_flag)
	 {
	    v_printf(1, "parsing file '%s' ..", argv[ii]);
	    v_neednl = 1;
	 }
	 beg = times(&ts);
	 set_locale_name(argv[ii]);
	 ret = clic_parse(argv[ii], 0);
	 end = times(&ts);

	 if (!preproc_flag)
	 {
	    v_neednl = 0;
	    if (clic_errorcount == 0)
	       v_printf(1, ".. done (%d/%d %s, %d %s, %s)\n",
			clic_line, all_lines, _clic_ngettext("line", "lines", clic_line), clic_warncount, _clic_ngettext("warning", "warnings", clic_warncount), diff_clock(beg, end));
	    else
	       vr_printf(1, "%d %s, %d %s\n", clic_errorcount, _clic_ngettext("error", "errors", clic_errorcount), clic_warncount, _clic_ngettext("warning", "warnings", clic_warncount));
	 }
      }
      if (ret)
	 break;

      if (clic_errorcount == 0 && codegen_flag)
      {
	 v_printf(2, "codegen file '%s' ..", curFile->name_of_File);
	 v_neednl = 1;
	 beg = times(&ts);
	 codegen_File(curFile);
	 end = times(&ts);
	 v_neednl = 0;
	 if (clic_errorcount == 0)
	    v_printf(2, ".. done, %s\n", diff_clock(beg, end));
	 else
	    pr_errorcount(2);
      }
      if (clic_errorcount == 0 && syntax_tree_flag)
      {
	 print_File(curFile);
      }
      if (clic_errorcount == 0 && write_obj_flag)
      {
	 if (pcode_flag)
	 {
	    long len;

	    v_printf(1, "writing file '%s' ..", curFile->s_cname_of_File);
	    v_neednl = 1;
	    beg = times(&ts);
	    write_OFile(curFile, &len);
	    write_names(curFile);
	    end = times(&ts);
	    v_neednl = 0;
	    if (clic_errorcount == 0)
	       v_printf(1, ".. done, %ld %s ,%s\n", len, _clic_ngettext("byte", "bytes", len), diff_clock(beg, end));
	    else
	       pr_errorcount(1);
	 }
	 else
	 {
	    v_printf(2, "writing file '%s' ..", curFile->s_cname_of_File);
	    v_neednl = 1;
	    write_File(curFile);
	    write_names(curFile);
	    v_neednl = 0;
	    if (clic_errorcount == 0)
	       v_printf(2, ".. done\n");
	    else
	       pr_errorcount(2);
	 }
      }

      if (clic_errorcount == 0 && (compile_flag || pc_flag))
      {
	 if (ii)
	    main_flag = 0;
	 v_printf(1, "compile file '%s' ..", curFile->s_cname_of_File);
	 v_neednl = 1;
	 beg = times(&ts);
	 compile_File(curFile->cname_of_File);
	 end = times(&ts);
	 v_neednl = 0;
	 if (clic_errorcount == 0)
	    v_printf(1, ".. done, %s\n", diff_clock(beg, end));
	 else
	    pr_errorcount(1);

	 if (clic_errorcount == 0 && shared_flag && !exec_flag)
	 {
	    v_printf(1, "make shared object '%s' ..", curFile->s_cname_of_File);
	    v_neednl = 1;
	    beg = times(&ts);
	    share_File(curFile->cname_of_File);
	    end = times(&ts);
	    v_neednl = 0;
	    if (clic_errorcount == 0)
	       v_printf(1, ".. done, %s\n", diff_clock(beg, end));
	    else
	       pr_errorcount(1);

	 }
      }

      if (ii < 0)
	 break;

      delete_File(curFile);
      curFile = NULL;
   }

   if (clic_errorcount == 0 && exec_flag)
   {
      char cmd[1024 * 8], *e;

      char cfuncname[256], ofuncname[256];

      char *libroot;

      int i;

      Coll ex, nm;

      init_Coll(&ex, free, strcasecmp);
      init_Coll(&nm, free, strcasecmp);
#ifdef STD_LIBDIR
      libroot = 0;
#else
      libroot = CLIPROOT;
#endif

      ++files;
#ifdef STD_LIBDIR
      if (eshared_flag || shared_flag)
      {
	 snprintf(cmd, sizeof(cmd), "-lclip");
	 add_name(cmd);
      }
      else
#endif
      {
	 e = (eshared_flag || shared_flag) ? CLIPSLIB : CLIPLIB;
	 lib_name(cmd, sizeof(cmd), libroot, "lib", e, strlen(e));
	 add_name(cmd);
      }
      for (e = CLIPLIBS; *e;)
      {
	 int l;

	 l = strspn(e, " \t");
	 e += l;
	 l = strcspn(e, " \t");
	 if (!l)
	    break;
	 lib_name(cmd, sizeof(cmd), libroot, "lib", e, l);
	 add_name(cmd);
	 e += l;
      }
      for (e = ADDLIBS; *e;)
      {
	 int l;

	 l = strspn(e, " \t");
	 e += l;
	 l = strcspn(e, " \t");
	 if (!l)
	    break;
	 memcpy(cmd, e, l);
	 cmd[l] = 0;
	 add_name(cmd);
	 e += l;
      }
      add_name(MATHLIB);
      add_name(DLLIB);

      /* generate _cfunctions */
      if (asm_flag)
	 sprintf(cfuncname, "%s_ref.s", oname);
      else
	 sprintf(cfuncname, "%s_ref.c", oname);
      sprintf(ofuncname, "%s_ref.o", oname);
      v_printf(1, "generate reference file '%s' ..", cfuncname);
      v_neednl = 1;
      beg = times(&ts);
      write_Cfunc(cfuncname, onum, ovect, &ex, &nm);
      check_names(&ex, &nm);
      end = times(&ts);
      v_neednl = 0;
      if (clic_errorcount == 0)
	 v_printf(1, ".. done, %s\n", diff_clock(beg, end));
      else
	 pr_errorcount(1);
      if (clic_errorcount)
	 goto end;

      v_printf(1, "compile file '%s' ..", cfuncname);
      v_neednl = 1;
      beg = times(&ts);
      compile_File(cfuncname);
      end = times(&ts);
      v_neednl = 0;
      if (clic_errorcount == 0)
	 v_printf(1, ".. done, %s\n", diff_clock(beg, end));
      else
	 pr_errorcount(1);

#ifdef USE_LD
      if (use_asm && (shared_flag || eshared_flag))
      {
	 int ll;

	 const char *ld_prg, *ld_end;

	 if (shared_flag || eshared_flag)
	 {
	    ld_prg = LD_PRG;
	    ld_end = LD_END;
	 }
	 else
	 {
	    ld_prg = LDS_PRG;
	    ld_end = LDS_END;
	 }

	 snprintf(cmd, sizeof(cmd), "%s", ld_prg);
	 ll = strlen(cmd);
	 for (e = cmd + ll, i = 0; i < lib_dirs.count_of_Coll; ++i)
	 {
		 snprintf(e, sizeof(cmd) - ll, " -L%s", (char *) lib_dirs.items_of_Coll[i]);
	    ll = strlen(cmd);
	    e = cmd + ll;
	 }
	 ll = strlen(cmd);
	 snprintf(cmd + ll, sizeof(cmd) - ll, " %s %s %s -o %s", optLevel ? COPT : "", genDebug ? CDBG : "", ofuncname, oname);
	 ll = strlen(cmd);
	 for (e = cmd + ll, i = 0; i < onum; ++i)
	 {
	    snprintf(e, sizeof(cmd) - ll, " %s", ovect[i]);
	    ll = strlen(cmd);
	    e = cmd + ll;
	 }
	 ll = strlen(cmd);
	 snprintf(cmd + ll, sizeof(cmd) - ll, " %s", ld_end);
      }
      else
#endif
      {
	 sprintf(cmd, "%s", CC);
	 for (e = cmd + strlen(cmd), i = 0; i < includePaths.count_of_Coll; ++i)
	 {
		 sprintf(e, " %s %s", INCLUDE_FLAG, (char *) includePaths.items_of_Coll[i]);
	    e = cmd + strlen(cmd);
	 }

	 for (e = cmd + strlen(cmd), i = 0; i < lib_dirs.count_of_Coll; ++i)
	 {
		 sprintf(e, " -L%s", (char *) lib_dirs.items_of_Coll[i]);
	    e = cmd + strlen(cmd);
	 }

	 sprintf(cmd + strlen(cmd), " %s %s %s %s %s %s %s", optLevel ? COPT : "", genDebug ? CDBG : "", CFLAGS, ADDCFLAGS, ofuncname, OUT_FLAG, oname);
	 for (e = cmd + strlen(cmd), i = 0; i < onum; ++i)
	 {
	    sprintf(e, " %s", ovect[i]);
	    e = cmd + strlen(cmd);
	 }
      }

      v_printf(1, "make file '%s' ..", oname);
      v_neednl = 1;
      beg = times(&ts);
      v_printf(2, "%s\n", cmd);
      if (system(cmd))
	 yyerror("C level error in command: %s", cmd);
      else if (rmc_flag)
      {
	 unlink(cfuncname);
	 unlink(ofuncname);
      }

      end = times(&ts);
      v_neednl = 0;
      if (clic_errorcount == 0)
	 v_printf(1, ".. done, %s\n", diff_clock(beg, end));
      else
	 pr_errorcount(1);
   }

 end:
   End = times(&ts);

   resume_parser();
   resume_lex();
   resume_locale();

   if (!preproc_flag)
      v_printf(1, "clip: %d %s, %s\n", files, _clic_ngettext("file", "files", files), diff_clock(Beg, End));
   return clic_errorcount == 0 ? 0 : 1;
}
Exemplo n.º 14
0
void show_help(int mode) {
    // mode = 0: only encode options
    // mode = 1: only decode options
    v_printf(1,"Usage:\n");
#ifdef HAS_ENCODER
    v_printf(1,"   flif [-e] [encode options] <input image(s)> <output.flif>\n");
#endif
    v_printf(1,"   flif [-d] [decode options] <input.flif> <output.pnm | output.pam | output.png>\n");
#ifdef HAS_ENCODER
    v_printf(2,"   flif [-t] [decode options] [encode options] <input.flif> <output.flif>\n");
#endif
    v_printf(1,"Supported input/output image formats: PNG, PNM (PPM,PGM,PBM), PAM\n");
    v_printf(1,"General Options:\n");
    v_printf(1,"   -h, --help                  show help (use -hvv for advanced options)\n");
    v_printf(1,"   -v, --verbose               increase verbosity (multiple -v for more output)\n");
    v_printf(2,"   -c, --no-crc                don't verify the CRC (or don't add a CRC)\n");
    v_printf(2,"   -m, --no-metadata           strip Exif/XMP metadata (default is to keep it)\n");
    v_printf(2,"   -p, --no-color-profile      strip ICC color profile (default is to keep it)\n");
    v_printf(2,"   -o, --overwrite             overwrite existing files\n");
    v_printf(2,"   -k, --keep-palette          use input PNG palette / write palette PNG if possible\n");
#ifdef HAS_ENCODER
    if (mode != 1) {
    v_printf(1,"Encode options: (-e, --encode)\n");
    v_printf(1,"   -E, --effort=N              0=fast/poor compression, 100=slowest/best? (default: -E60)\n");
    v_printf(1,"   -I, --interlace             interlacing (default, except for tiny images)\n");
    v_printf(1,"   -N, --no-interlace          force no interlacing\n");
    v_printf(1,"   -Q, --lossy=N               lossy compression; default: -Q100 (lossless)\n");
    v_printf(1,"   -K, --keep-invisible-rgb    store original RGB values behind A=0\n");
    v_printf(1,"   -F, --frame-delay=N[,N,..]  delay between animation frames in ms; default: -F100\n");
//    v_printf(1,"Multiple input images (for animated FLIF) must have the same dimensions.\n");
    v_printf(2,"Advanced encode options: (mostly useful for flifcrushing)\n");
    v_printf(2,"   -P, --max-palette-size=N    max size for Palette(_Alpha); default: -P%i\n",DEFAULT_MAX_PALETTE_SIZE);
    v_printf(2,"   -A, --force-color-buckets   force Color_Buckets transform\n");
    v_printf(2,"   -B, --no-color-buckets      disable Color_Buckets transform\n");
    v_printf(2,"   -C, --no-channel-compact    disable Channel_Compact transform\n");
    v_printf(2,"   -Y, --no-ycocg              disable YCoCg transform; use G(R-G)(B-G)\n");
    v_printf(2,"   -W, --no-subtract-green     disable YCoCg and SubtractGreen transform; use GRB\n");
    v_printf(2,"   -S, --no-frame-shape        disable Frame_Shape transform\n");
    v_printf(2,"   -L, --max-frame-lookback=N  max nb of frames for Frame_Lookback; default: -L1\n");
    v_printf(2,"   -R, --maniac-repeats=N      MANIAC learning iterations; default: -R%i\n",TREE_LEARN_REPEATS);
    v_printf(3,"   -T, --maniac-threshold=N    MANIAC tree growth split threshold, in bits saved; default: -T%i\n",CONTEXT_TREE_SPLIT_THRESHOLD/5461);
    v_printf(3,"   -D, --maniac-divisor=N      MANIAC inner node count divisor; default: -D%i\n",CONTEXT_TREE_COUNT_DIV);
    v_printf(3,"   -M, --maniac-min-size=N     MANIAC post-pruning threshold; default: -M%i\n",CONTEXT_TREE_MIN_SUBTREE_SIZE);
    v_printf(3,"   -X, --chance-cutoff=N       minimum chance (N/4096); default: -X2\n");
    v_printf(3,"   -Z, --chance-alpha=N        chance decay factor; default: -Z19\n");
    v_printf(3,"   -U, --adaptive              adaptive lossy, second input image is saliency map\n");
    v_printf(3,"   -G, --guess=N[N..]          pixel predictor for each plane (Y,Co,Cg,Alpha,Lookback)\n");
    v_printf(3,"                               ?=pick heuristically, 0=avg, 1=median_grad, 2=median_nb, X=mixed\n");
    v_printf(3,"   -H, --invisible-guess=N     predictor for invisible pixels (only if -K is not used)\n");
    v_printf(3,"   -J, --chroma-subsample      write an incomplete 4:2:0 chroma subsampled FLIF file (lossy!)\n");
    }
#endif
    if (mode != 0) {
    v_printf(1,"Decode options: (-d, --decode)\n");
    v_printf(1,"   -i, --identify             do not decode, just identify the input FLIF file\n");
    v_printf(1,"   -q, --quality=N            lossy decode quality percentage; default -q100\n");
    v_printf(1,"   -s, --scale=N              lossy downscaled image at scale 1:N (2,4,8,16,32); default -s1\n");
    v_printf(1,"   -r, --resize=WxH           lossy downscaled image to fit inside WxH (but typically smaller)\n");
    v_printf(1,"   -f, --fit=WxH              lossy downscaled image to exactly WxH\n");
    v_printf(2,"   -b, --breakpoints          report breakpoints (truncation offsets) for truncations at scales 1:8, 1:4, 1:2\n");
    }
}
Exemplo n.º 15
0
u_char trident_ext_video_port_in(ioport_t port)
{
  switch (port) {
  case SEQ_D:
    if (dosemu_regs.regs[SEQI] == 0x0b) {
      trident_old_regs = !trident_old_regs;
      v_printf("old=1/new=0 = 0x%02x\n", trident_old_regs);
      return (0x04);
    }
    if (trident_old_regs) {
      if (dosemu_regs.regs[SEQI] == 0x0d) {
	v_printf("OLD Read on SEQI 0x0d got 0x%02x\n", dosemu_regs.xregs[1]);
	return (dosemu_regs.xregs[1]);
      }
      else if (dosemu_regs.regs[SEQI] == 0x0e) {
	v_printf("OLD Read on SEQI 0x0e got 0x%02x\n", dosemu_regs.xregs[2]);
	return (dosemu_regs.xregs[2]);
      }
    }
    else {
      if (dosemu_regs.regs[SEQI] == 0x0d) {
	v_printf("NEW Read on SEQI 0x0d got 0x%02x\n", dosemu_regs.xregs[3]);
	return (dosemu_regs.xregs[3]);
      }
      else if (dosemu_regs.regs[SEQI] == 0x0e) {
	v_printf("NEW Read on SEQI 0x0e got 0x%02x\n", dosemu_regs.xregs[4]);
	return (dosemu_regs.xregs[4]);
      }
    }
    if (dosemu_regs.regs[SEQI] == 0x0f) {
      v_printf("Read on SEQI 0x0f got 0x%02x\n", dosemu_regs.xregs[5]);
      return (dosemu_regs.xregs[5]);
    }
    if (dosemu_regs.regs[SEQI] == 0x0c) {
      v_printf("Read on SEQI 0x0c got 0x%02x\n", dosemu_regs.xregs[0]);
      return (dosemu_regs.xregs[0]);
    }
    break;
  case CRT_DC:
  case CRT_DM:
    if (dosemu_regs.regs[CRTI] == 0x1e) {
      v_printf("Read on CRT_D 0x1e got 0x%02x\n", dosemu_regs.xregs[6]);
      return (dosemu_regs.xregs[6]);
    }
    else if (dosemu_regs.regs[CRTI] == 0x1f) {
      v_printf("Read on CRT_D 0x1f got 0x%02x\n", dosemu_regs.xregs[7]);
      return (dosemu_regs.xregs[7]);
    }
    break;
  case GRA_D:
    if (dosemu_regs.regs[GRAI] == 0x0f) {
      v_printf("Read on GRA_D 0x0f got 0x%02x\n", dosemu_regs.xregs[8]);
      return (dosemu_regs.xregs[8]);
    }
    break;
  }
  v_printf("Bad Read on port 0x%04x\n", port);
  return (0);
}
Exemplo n.º 16
0
void show_help() {
    v_printf(1,"Usage:\n");
#ifdef HAS_ENCODER
    v_printf(1,"   flif [-e] [encode options] <input image(s)> <output.flif>\n");
#endif
    v_printf(1,"   flif [-d] [decode options] <input.flif> <output.pnm | output.pam | output.png>\n");
#ifdef HAS_ENCODER
    v_printf(2,"   flif [-t] [decode options] [encode options] <input.flif> <output.flif>\n");
#endif
    v_printf(1,"Supported input/output image formats: PNG, PNM (PPM,PGM,PBM), PAM\n");
    v_printf(1,"General Options:\n");
    v_printf(1,"   -h, --help                  show help (use -hvv for advanced options)\n");
    v_printf(1,"   -v, --verbose               increase verbosity (multiple -v for more output)\n");
#ifdef HAS_ENCODER
    v_printf(1,"Encode options: (-e, --encode)\n");
    v_printf(1,"   -I, --interlace             interlacing (default, except for tiny images)\n");
    v_printf(1,"   -N, --no-interlace          force no interlacing\n");
    v_printf(1,"   -K, --keep-invisible-rgb    store original RGB values behind A=0\n");
    v_printf(1,"   -F, --frame-delay=N[,N,..]  delay between animation frames in ms; default: -F100\n");
//    v_printf(1,"Multiple input images (for animated FLIF) must have the same dimensions.\n");
    v_printf(2,"Advanced encode options: (mostly useful for flifcrushing)\n");
    v_printf(2,"   -P, --max-palette-size=N    max size for Palette(_Alpha); default: -P1024\n");
    v_printf(2,"   -A, --force-color-buckets   force Color_Buckets transform\n");
    v_printf(2,"   -B, --no-color-buckets      disable Color_Buckets transform\n");
    v_printf(2,"   -C, --no-channel-compact    disable Channel_Compact transform\n");
    v_printf(2,"   -Y, --no-ycocg              disable YCoCg transform (use plain RGB instead)\n");
    v_printf(2,"   -S, --no-frame-shape        disable Frame_Shape transform\n");
    v_printf(2,"   -L, --max-frame-lookback=N  max nb of frames for Frame_Lookback; default: -L1\n");
    v_printf(2,"   -R, --maniac-repeats=N      MANIAC learning iterations; default: -R%i\n",TREE_LEARN_REPEATS);
    v_printf(3,"   -T, --maniac-threshold=N    MANIAC tree growth split threshold, in bits saved; default: -T%i\n",CONTEXT_TREE_SPLIT_THRESHOLD/5461);
    v_printf(3,"   -D, --maniac-divisor=N      MANIAC inner node count divisor; default: -D%i\n",CONTEXT_TREE_COUNT_DIV);
    v_printf(3,"   -M, --maniac-min-size=N     MANIAC post-pruning threshold; default: -M%i\n",CONTEXT_TREE_MIN_SUBTREE_SIZE);
    v_printf(3,"   -X, --chance-cutoff=N       minimum chance (N/4096); default: -X2\n");
    v_printf(3,"   -Z, --chance-alpha=N        chance decay factor; default: -Z19\n");
#endif
    v_printf(1,"Decode options: (-d, --decode)\n");
    v_printf(1,"   -i, --identify             do not decode, just identify the input FLIF file\n");
    v_printf(1,"   -q, --quality=N            lossy decode quality percentage; default -q100\n");
    v_printf(1,"   -s, --scale=N              lossy downscaled image at scale 1:N (2,4,8,16,32); default -s1\n");
    v_printf(1,"   -r, --resize=WxH           lossy downscaled image to fit WxH\n");
}
Exemplo n.º 17
0
void trident_ext_video_port_out(ioport_t port, u_char value)
{
  switch (port) {
  case SEQ_D:
    if (dosemu_regs.regs[SEQI] == 0x0b) {
      trident_old_regs = 1;
      v_printf("Old_regs reset to OLD = 0x%02x\n", trident_old_regs);
      return;
    }
    if (trident_old_regs) {
      if (dosemu_regs.regs[SEQI] == 0x0d) {
	v_printf("OLD Write on SEQ_D 0x0d sent 0x%02x\n", value);
	dosemu_regs.xregs[1] = value;
	return;
      }
      else if (dosemu_regs.regs[SEQI] == 0x0e) {
	v_printf("OLD Write to SEQI at 0x0e put 0x%02x->0x%02x\n", value, dosemu_regs.xregs[2]);
	return;
	dosemu_regs.xregs[2] = value;
	return;
      }
    }
    else {
      if (dosemu_regs.regs[SEQI] == 0x0d) {
	v_printf("NEW Write to SEQI at 0x0d put 0x%02x->0x%02x\n", value, dosemu_regs.xregs[3]);
	dosemu_regs.xregs[3] = value;
	return;
      }
      else if (dosemu_regs.regs[SEQI] == 0x0e) {
	v_printf("NEW Write to SEQI at 0x0e put 0x%02x->0x%02x\n", value, dosemu_regs.xregs[4]);
	dosemu_regs.xregs[4] = value;
	return;
      }
    }
    if (dosemu_regs.regs[SEQI] == 0x0c) {
      v_printf("Write to SEQI at 0x0c put 0x%02x->0x%02x\n", value, dosemu_regs.xregs[0]);
      dosemu_regs.xregs[0] = value;
      return;
    }
    if (dosemu_regs.regs[SEQI] == 0x0f) {
      v_printf("Write to SEQI at 0x0f put 0x%02x->0x%02x\n", value, dosemu_regs.xregs[5]);
      dosemu_regs.xregs[5] = value;
      return;
    }
    break;
  case CRT_DC:
  case CRT_DM:
    if (dosemu_regs.regs[CRTI] == 0x1e) {
      v_printf("Write to CRTI at 0x1e put 0x%02x->0x%02x\n", value, dosemu_regs.xregs[6]);
      dosemu_regs.xregs[6] = value;
      return;
    }
    else if (dosemu_regs.regs[CRTI] == 0x1f) {
      v_printf("Write to CRTI at 0x1f put 0x%02x->0x%02x\n", value, dosemu_regs.xregs[7]);
      dosemu_regs.xregs[7] = value;
      return;
    }
    break;
  case GRA_D:
    if (dosemu_regs.regs[GRAI] == 0x0f) {
      v_printf("Write to GRAD at 0x0f put 0x%02x->0x%02x\n", value, dosemu_regs.xregs[8]);
      return;
    }
    break;
  }
  v_printf("Bad Write on port 0x%04x with value 0x%02x\n", port, value);
}
Exemplo n.º 18
0
 void simplify(int divisor=CONTEXT_TREE_COUNT_DIV, int min_size=CONTEXT_TREE_MIN_SUBTREE_SIZE, int plane=0) {
     v_printf(10,"PLANE %i: TREE BEFORE SIMPLIFICATION:\n",plane);
     simplify_subtree(0, divisor, min_size, 0, plane);
 }
Exemplo n.º 19
0
void test_dyn_map1 (void)
{
	DDS_DynamicTypeSupport ts;
	DDS_DynamicTypeBuilder sb1, mb, sb;
	DDS_DynamicType s1, s, m;
	DDS_TypeDescriptor *desc;
	DDS_MemberDescriptor *md;
	DDS_DynamicData dd, dd2, ddm;
	DDS_ReturnCode_t rc;

	v_printf ("test_dyn_map1 - ");

	/* 1. Create the type. */
	desc = DDS_TypeDescriptor__alloc ();
	fail_unless (desc != NULL);

	md = DDS_MemberDescriptor__alloc ();
	fail_unless (md != NULL);

	sb = DDS_DynamicTypeBuilderFactory_create_string_type (50);
	fail_unless (sb != NULL);

	s = DDS_DynamicTypeBuilder_build (sb);
	fail_unless (s != NULL);

	DDS_DynamicTypeBuilderFactory_delete_type (sb);

	mb = DDS_DynamicTypeBuilderFactory_create_map_type (
		DDS_DynamicTypeBuilderFactory_get_primitive_type (DDS_INT_32_TYPE),
		s, DDS_UNBOUNDED_COLLECTION);
	fail_unless (mb != NULL);

	m = DDS_DynamicTypeBuilder_build (mb);
	fail_unless (m != NULL);

	DDS_DynamicTypeBuilderFactory_delete_type (mb);

	desc->kind = DDS_STRUCTURE_TYPE;
	desc->name = "dmap1";

	sb1 = DDS_DynamicTypeBuilderFactory_create_type (desc);
	fail_unless (sb1 != NULL);

	md->name = "m";
	md->id = 0;
	md->type = m;
	md->index = 0;
	fail_unless (md->type != NULL);

	rc = DDS_DynamicTypeBuilder_add_member (sb1, md);
	fail_unless (rc == DDS_RETCODE_OK);

	md->name = "b";
	md->id = 1;
	md->type = DDS_DynamicTypeBuilderFactory_get_primitive_type (DDS_INT_64_TYPE);
	md->index = 1;
	fail_unless (md->type != NULL);

	rc = DDS_DynamicTypeBuilder_add_member (sb1, md);
	fail_unless (rc == DDS_RETCODE_OK);

	s1 = DDS_DynamicTypeBuilder_build (sb1);
	fail_unless (s1 != NULL);

	DDS_DynamicTypeBuilderFactory_delete_type (sb1);

	ts = DDS_DynamicTypeSupport_create_type_support (s1);
	fail_unless (ts != NULL);

	DDS_TypeDescriptor__free (desc);
	DDS_MemberDescriptor__free (md);

	DDS_TypeSupport_dump_type (0, (DDS_TypeSupport) ts, 15);

	/* 2. Create a Dynamic data item for this type. */
	ddm = DDS_DynamicDataFactory_create_data (m);
	md->name = "key";
	md->id = DDS_DynamicData_get_member_id_by_name (ddm, "alfa");
	md->type = DDS_DynamicTypeBuilderFactory_get_primitive_type (DDS_INT_32_TYPE);
	md->default_value = "0"; 
	md->index = 0;
	md->default_label = 0;


	dd = DDS_DynamicDataFactory_create_data (s1);
	fail_unless (dd != NULL);

	rc = DDS_DynamicData_set_int32_value (dd, 0, 0xCAFEBABE);
	fail_unless (rc == DDS_RETCODE_OK);

	rc = DDS_DynamicData_set_int64_value (dd, 1, -1);
	fail_unless (rc == DDS_RETCODE_OK);

	marshallDynamic (dd, &dd2, ts);

	DDS_DynamicDataFactory_delete_data (dd);
	DDS_DynamicTypeBuilderFactory_delete_type (s1);
	DDS_DynamicTypeSupport_delete_type_support (ts);

	v_printf ("success!\r\n");
}
Exemplo n.º 20
0
static void test_aux (void)
{
	DDS_DomainParticipant		p;
	DDS_Topic			t;
	DDS_TopicDescription		td;
	DDS_Subscriber			sub, nsub;
	DDS_DataReader			dr;
	DDS_StatusCondition		sc, sc2;
	DDS_StatusMask 			sm;
	DDS_InstanceHandle_t		h, h2;
	DDS_Duration_t			w;
	DDS_LivelinessChangedStatus	lcs;
	DDS_RequestedDeadlineMissedStatus dms;
	DDS_RequestedIncompatibleQosStatus iqs;
	DDS_SampleLostStatus		sls;
	DDS_SampleRejectedStatus	srs;
	DDS_SubscriptionMatchedStatus	sms;
	DDS_InstanceHandleSeq		handles;
	DDS_ReturnCode_t		r;

	p = DDS_DomainParticipantFactory_create_participant (1, DDS_PARTICIPANT_QOS_DEFAULT, NULL, 0);
	fail_unless (p != NULL);

	r = register_HelloWorldData_type (p);
	fail_unless (r == DDS_RETCODE_OK);
	t = DDS_DomainParticipant_create_topic (p, "HelloWorld", TYPE_NAME, DDS_TOPIC_QOS_DEFAULT, NULL, 0);
	fail_unless (t != NULL);

	td = DDS_DomainParticipant_lookup_topicdescription (p, "HelloWorld");
	fail_unless (td != NULL);

	sub = DDS_DomainParticipant_create_subscriber (p, DDS_SUBSCRIBER_QOS_DEFAULT, NULL, 0);
	fail_unless (sub != NULL);

	v_printf (" - Test reader auxiliary functions.\r\n");
	dr = DDS_Subscriber_create_datareader (sub, td, DDS_DATAREADER_QOS_DEFAULT, NULL, 0);
	fail_unless (dr != NULL);

	sc = DDS_DataReader_get_statuscondition (dr);
	fail_unless (sc != NULL);
	
	sc2 = DDS_Entity_get_statuscondition (dr);
	fail_unless (sc2 == sc);
	
	sm = DDS_DataReader_get_status_changes (dr);
	fail_unless (sm == 0);

	sm = DDS_Entity_get_status_changes (dr);
	fail_unless (sm == 0);

	h = DDS_Entity_get_instance_handle (dr);
	fail_unless (h != 0);

	h2 = DDS_DataReader_get_instance_handle (dr);
	fail_unless (h == h2);

	r = DDS_DataReader_get_liveliness_changed_status (dr, &lcs);
	fail_unless (r == DDS_RETCODE_OK);

	r = DDS_DataReader_get_requested_deadline_missed_status (dr, &dms);
	fail_unless (r == DDS_RETCODE_OK);

	r = DDS_DataReader_get_requested_incompatible_qos_status (dr, &iqs);
	fail_unless (r == DDS_RETCODE_OK);

	r = DDS_DataReader_get_sample_lost_status (dr, &sls);
	fail_unless (r == DDS_RETCODE_OK);

	r = DDS_DataReader_get_sample_rejected_status (dr, &srs);
	fail_unless (r == DDS_RETCODE_OK);

	r = DDS_DataReader_get_subscription_matched_status (dr, &sms);
	fail_unless (r == DDS_RETCODE_OK);

	td = DDS_DataReader_get_topicdescription (dr);
	fail_unless ((DDS_Topic) td == t);

	nsub = DDS_DataReader_get_subscriber (dr);
	fail_unless (nsub == sub);

	w.sec = 2;
	w.nanosec = 0;
	r = DDS_DataReader_wait_for_historical_data (dr, &w);
	fail_unless (r == DDS_RETCODE_OK);

	DDS_InstanceHandleSeq__init (&handles);
	r = DDS_DataReader_get_matched_publications (dr, &handles);
	fail_unless (r == DDS_RETCODE_OK);
	DDS_InstanceHandleSeq__clear (&handles);

	r = DDS_Subscriber_delete_datareader (sub, dr);
	fail_unless (r == DDS_RETCODE_OK);
	r = DDS_DomainParticipant_delete_subscriber (p, sub);
	fail_unless (r == DDS_RETCODE_OK);
	r = DDS_DomainParticipant_delete_topic (p, t);
	fail_unless (r == DDS_RETCODE_OK);
	unregister_HelloWorldData_type (p);
	r = DDS_DomainParticipantFactory_delete_participant (p);
	fail_unless (r == DDS_RETCODE_OK);
}
Exemplo n.º 21
0
void video_config_init(void)
{
/*     gettermcap(0); */

    switch (config.cardtype) {
    case CARD_MDA:
	{
	    configuration |= (MDA_CONF_SCREEN_MODE);
	    video_mode = MDA_INIT_SCREEN_MODE;
	    phys_text_base = MDA_PHYS_TEXT_BASE;
	    virt_text_base = MDA_VIRT_TEXT_BASE;
	    video_combo = MDA_VIDEO_COMBO;
	    video_subsys = MDA_VIDEO_SUBSYS;
	    break;
	}
    case CARD_CGA:
	{
	    configuration |= (CGA_CONF_SCREEN_MODE);
	    video_mode = CGA_INIT_SCREEN_MODE;
	    phys_text_base = CGA_PHYS_TEXT_BASE;
	    virt_text_base = CGA_VIRT_TEXT_BASE;
	    video_combo = CGA_VIDEO_COMBO;
	    video_subsys = CGA_VIDEO_SUBSYS;

	    break;
	}
    case CARD_EGA:
	{
	    configuration |= (EGA_CONF_SCREEN_MODE);
	    video_mode = EGA_INIT_SCREEN_MODE;
	    phys_text_base = EGA_PHYS_TEXT_BASE;
	    virt_text_base = EGA_VIRT_TEXT_BASE;
	    video_combo = EGA_VIDEO_COMBO;
	    video_subsys = EGA_VIDEO_SUBSYS;
	    break;
	}
    case CARD_VGA:
	{
	    configuration |= (VGA_CONF_SCREEN_MODE);
	    video_mode = VGA_INIT_SCREEN_MODE;
	    phys_text_base = VGA_PHYS_TEXT_BASE;
	    virt_text_base = VGA_VIRT_TEXT_BASE;
	    video_combo = VGA_VIDEO_COMBO;
	    video_subsys = VGA_VIDEO_SUBSYS;
	    break;
	}
    default:			/* or Terminal, is this correct ? */
	{
	    configuration |= (CGA_CONF_SCREEN_MODE);
	    video_mode = CGA_INIT_SCREEN_MODE;
	    phys_text_base = CGA_PHYS_TEXT_BASE;
	    virt_text_base = CGA_VIRT_TEXT_BASE;
	    video_combo = CGA_VIDEO_COMBO;
	    video_subsys = CGA_VIDEO_SUBSYS;
	    break;
	}
    }

#if 0                 /* FIXME XXX  why/where does config.console get cleared?  */
    if (!config.console) {
	/* NOTE: BIG FAT WARNING !!!
	 *       without this you will reproduceable KILL LINUX
	 *       (seen with Linux-2.0.28)            ^^^^^^^^^^
	 *       This happens in xterm, not console and not xdos.
	 *       I was unable to trace it down, because directly at
	 *       startup you get a black screen and no logs are left
	 *       once you repaired your files system :(
	 *       Though this is a userspace bug, it should not
	 *       kill the kernel IMHO. -- Hans
	 */
	v_printf("VID: not running on console - resetting to terminal mode\n");
	config.console_video = 0;
/*      scr_state.console_no = 0; */
	config.console_keyb = 0;
	config.console_video = 0;
	config.mapped_bios = 0;
	config.vga = 0;
	config.graphics = 0;
	config.console = 0;
	if (config.speaker == SPKR_NATIVE)
	    config.speaker = SPKR_EMULATED;
    }
#endif
    video_page = 0;
    screen_mask = 1 << (((int) phys_text_base - 0xA0000) / 4096);
    screen_adr = SCREEN_ADR(0);
    if (!config.vga) {
	WRITE_BYTE(BIOS_CURRENT_SCREEN_PAGE, 0x0);	/* Current Screen Page */
	WRITE_WORD(BIOS_CURSOR_SHAPE, (configuration & MDA_CONF_SCREEN_MODE) ? 0x0A0B : 0x0607);

	/* This is needed in the video stuff. Grabbed from boot(). */
	if ((configuration & MDA_CONF_SCREEN_MODE) == MDA_CONF_SCREEN_MODE)
	    WRITE_WORD(BIOS_VIDEO_PORT, 0x3b4);		/* base port of CRTC - IMPORTANT! */
	else
	    WRITE_WORD(BIOS_VIDEO_PORT, 0x3d4);		/* base port of CRTC - IMPORTANT! */

	WRITE_BYTE(BIOS_VDU_CONTROL, 9);	/* current 3x8 (x=b or d) value */

	WRITE_BYTE(BIOS_VIDEO_MODE, video_mode);	/* video mode */
	set_video_bios_size();
	WRITE_WORD(BIOS_VIDEO_MEMORY_ADDRESS, 0);	/* offset of current page in buffer */

	WRITE_WORD(BIOS_FONT_HEIGHT, 16);

	/* XXX - these are the values for VGA color!
	   should reflect the real display hardware. */
	WRITE_BYTE(BIOS_VIDEO_INFO_0, 0x60);
	WRITE_BYTE(BIOS_VIDEO_INFO_1, 0xF9);
	WRITE_BYTE(BIOS_VIDEO_INFO_2, 0x51);
	WRITE_BYTE(BIOS_VIDEO_COMBO, video_combo);

	WRITE_DWORD(BIOS_VIDEO_SAVEPTR, 0);	/* pointer to video table */
    }

/*     if (config.console_video && !config.usesX) */
/* 	set_process_control(); */
    if (config.console_video) {
	set_console_video();
    }
/*     if (config.usesX) */
/* 	set_consoleX_video(); */

    video_init();

    reserve_video_memory();
    get_video_ram(0);
}
Exemplo n.º 22
0
int SDL_init(void)
{
  Uint32 flags = SDL_WINDOW_HIDDEN;
  Uint32 rflags = config.sdl_hwrend ? 0 : SDL_RENDERER_SOFTWARE;
  int bpp, features;
  Uint32 rm, gm, bm, am;

  assert(pthread_equal(pthread_self(), dosemu_pthread_self));
  if (config.X_lin_filt || config.X_bilin_filt) {
    v_printf("SDL: enabling scaling filter\n");
    SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
  }
  if (config.X_fullscreen)
    flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
  else
    flags |= SDL_WINDOW_RESIZABLE;
#if 0
  /* it is better to create window and renderer at once. They have
   * internal cyclic dependencies, so if you create renderer after
   * creating window, SDL will destroy and re-create the window. */
  int err = SDL_CreateWindowAndRenderer(0, 0, flags, &window, &renderer);
  if (err || !window || !renderer) {
    error("SDL window failed: %s\n", SDL_GetError());
    goto err;
  }
  SDL_SetWindowTitle(window, config.X_title);
#else
  window = SDL_CreateWindow(config.X_title, SDL_WINDOWPOS_UNDEFINED,
      SDL_WINDOWPOS_UNDEFINED, 0, 0, flags);
  if (!window) {
    error("SDL window failed: %s\n", SDL_GetError());
    goto err;
  }
  renderer = SDL_CreateRenderer(window, -1, rflags);
  if (!renderer) {
    error("SDL renderer failed: %s\n", SDL_GetError());
    goto err;
  }
#endif

#ifdef X_SUPPORT
  init_x11_support(window);
#else
  use_bitmap_font = 1;
#endif

  if (config.X_fullscreen) {
    window_grab(1, 1);
    force_grab = 1;
  }

  pixel_format = SDL_GetWindowPixelFormat(window);
  if (pixel_format == SDL_PIXELFORMAT_UNKNOWN) {
    error("SDL: unable to get pixel format\n");
    pixel_format = SDL_PIXELFORMAT_RGB888;
  }
  SDL_PixelFormatEnumToMasks(pixel_format, &bpp, &rm, &gm, &bm, &am);
  SDL_csd.bits = bpp;
  SDL_csd.r_mask = rm;
  SDL_csd.g_mask = gm;
  SDL_csd.b_mask = bm;
  color_space_complete(&SDL_csd);
  features = 0;
  if (use_bitmap_font)
    features |= RFF_BITMAP_FONT;
  register_render_system(&Render_SDL);
  if (remapper_init(1, 1, features, &SDL_csd)) {
    error("SDL: SDL_init: VGAEmu init failed!\n");
    config.exitearly = 1;
    return -1;
  }

#if THREADED_REND
  sem_init(&rend_sem, 0, 0);
  pthread_create(&rend_thr, NULL, render_thread, NULL);
#ifdef HAVE_PTHREAD_SETNAME_NP
  pthread_setname_np(rend_thr, "dosemu: sdl_r");
#endif
#endif

  c_printf("VID: SDL plugin initialization completed\n");

  return 0;

err:
  SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
  return -1;
}
Exemplo n.º 23
0
int dump_edit(char *filename, int edit) 
{
    FILE *f = fopen(filename, (edit) ? "r+b" : "rb");
    IMAGE_FILE_HEADER filhdr;
    IMAGE_SECTION_HEADER scnhdr;
    int i;

    if (f == NULL) {
	fprintf(stderr, "%s: cannot open %s.\n", progname, filename);
	return 1;
    }
    
    if (fread(&filhdr, sizeof(filhdr), 1, f) == 0) {
	fprintf(stderr,"%s: Could not read COFF header from %s,"
		" is this a PE (COFF) file?\n", progname, filename);
	fclose(f);
	return 1;
    }
    v_printf("File: %s\n", filename);
    v_printf("Magic number: 0x%08x\n", filhdr.Machine);
    v_printf("Number of sections: %d\n",filhdr.NumberOfSections);
    
    if (fseek(f, (long) filhdr.SizeOfOptionalHeader, SEEK_CUR) != 0) {
	fprintf(stderr,"%s: Could not read COFF optional header from %s,"
		" is this a PE (COFF) file?\n", progname, filename);
	fclose(f);
	return 1;
    }
    
    for (i = 0; i < filhdr.NumberOfSections; ++i) {
	if (fread(&scnhdr, sizeof(scnhdr), 1, f) == 0) {
	    fprintf(stderr,"%s: Could not read section header from %s,"
		    " is this a PE (COFF) file?\n", progname, filename);
	    fclose(f);
	    return 1;
	}
	v_printf("Section %s:\n", scnhdr.Name);
	v_printf("Physical address: 0x%08x\n", scnhdr.Misc.PhysicalAddress);
	v_printf("Size: 0x%08x\n", scnhdr.SizeOfRawData);
	if (scnhdr.Misc.PhysicalAddress != 0 &&
	    scnhdr.SizeOfRawData == 0) {
	    printf("Section header %s in file %s will confuse MSC linker, "
		   "virtual size is 0x%08x and raw size is 0\n",
		   scnhdr.Name, filename, scnhdr.Misc.PhysicalAddress, 
		   scnhdr.SizeOfRawData);
	    if (edit) {
		scnhdr.SizeOfRawData = scnhdr.Misc.PhysicalAddress;
		scnhdr.Misc.PhysicalAddress = 0;
		if (fseek(f, (long) -((long)sizeof(scnhdr)), SEEK_CUR) != 0 ||
		    fwrite(&scnhdr, sizeof(scnhdr), 1, f) == 0) {
		    fprintf(stderr,"%s: could not edit file %s.\n",
			    progname, filename);
		    fclose(f);
		    return 1;
		}
		printf("Edited object, virtual size is now 0, and "
		       "raw size is 0x%08x.\n", scnhdr.SizeOfRawData);
	    } else {
		printf("Specify option '-e' to correct the problem.\n");
	    }
	}
    }
    fclose(f);
    return 0;
}
Exemplo n.º 24
0
static void SDL_change_mode(int x_res, int y_res, int w_x_res, int w_y_res)
{
  Uint32 flags;

  assert(pthread_equal(pthread_self(), dosemu_pthread_self));
  v_printf("SDL: using mode %dx%d %dx%d %d\n", x_res, y_res, w_x_res,
	   w_y_res, SDL_csd.bits);
  if (surface) {
    SDL_FreeSurface(surface);
    SDL_DestroyTexture(texture_buf);
  }
  if (x_res > 0 && y_res > 0) {
    texture_buf = SDL_CreateTexture(renderer,
        pixel_format,
        SDL_TEXTUREACCESS_STREAMING,
        x_res, y_res);
    if (!texture_buf) {
      error("SDL target texture failed: %s\n", SDL_GetError());
      leavedos(99);
    }
    surface = SDL_CreateRGBSurface(0, x_res, y_res, SDL_csd.bits,
            SDL_csd.r_mask, SDL_csd.g_mask, SDL_csd.b_mask, 0);
    if (!surface) {
      error("SDL surface failed: %s\n", SDL_GetError());
      leavedos(99);
    }
  } else {
    surface = NULL;
    texture_buf = NULL;
  }

  if (config.X_fixed_aspect)
    SDL_RenderSetLogicalSize(renderer, w_x_res, w_y_res);
  flags = SDL_GetWindowFlags(window);
  if (!(flags & SDL_WINDOW_MAXIMIZED))
    SDL_SetWindowSize(window, w_x_res, w_y_res);
  set_resizable(use_bitmap_font
		|| vga.mode_class == GRAPH, w_x_res, w_y_res);
  if (!initialized) {
    initialized = 1;
    SDL_ShowWindow(window);
    SDL_RaiseWindow(window);
    m_cursor_visible = 1;
    if (config.X_fullscreen)
      render_gain_focus();
  }
  SDL_RenderClear(renderer);
  SDL_RenderPresent(renderer);
  if (texture_buf) {
    SDL_SetRenderTarget(renderer, texture_buf);
    SDL_RenderClear(renderer);
  }

  m_x_res = w_x_res;
  m_y_res = w_y_res;
  win_width = x_res;
  win_height = y_res;
  /* forget about those rectangles */
  sdl_rects_num = 0;

  update_mouse_coords();
}
Exemplo n.º 25
0
void test_dyn_array2 (void)
{
	DDS_DynamicTypeSupport ts;
	DDS_DynamicTypeBuilder sb1, sb1a, abi64, abs1a;
	DDS_DynamicType s1, s1a, ai64, as1a;
	DDS_TypeDescriptor *desc;
	DDS_MemberDescriptor *md;
	DDS_DynamicData dd, dds, dda, ddas, dd2;
	DDS_ReturnCode_t rc;
	DDS_BoundSeq bounds;
	unsigned i, j;

	v_printf ("test_dyn_array2 - ");

	/* 1. Create the type. */
	desc = DDS_TypeDescriptor__alloc ();
	fail_unless (desc != NULL);

	desc->kind = DDS_STRUCTURE_TYPE;
	desc->name = "dstruct2a";
	sb1a = DDS_DynamicTypeBuilderFactory_create_type (desc);
	fail_unless (sb1a != NULL);

	md = DDS_MemberDescriptor__alloc ();
	fail_unless (md != NULL);

	DDS_SEQ_INIT (bounds);
	dds_seq_require (&bounds, 1);
	DDS_SEQ_LENGTH (bounds) = 1;
	DDS_SEQ_ITEM (bounds, 0) = 5;

	abi64 = DDS_DynamicTypeBuilderFactory_create_array_type (
		DDS_DynamicTypeBuilderFactory_get_primitive_type (DDS_INT_64_TYPE),
		&bounds);
	fail_unless (abi64 != NULL);

	ai64 = DDS_DynamicTypeBuilder_build (abi64);
	fail_unless (ai64 != NULL);

	DDS_DynamicTypeBuilderFactory_delete_type (abi64);

	md->name = "i64";
	md->index = md->id = 0;
	md->type = ai64;

	rc = DDS_DynamicTypeBuilder_add_member (sb1a, md);
	fail_unless (rc == DDS_RETCODE_OK);

	ADD_FIELD (sb1a, md, "ch", 1, 1, DDS_CHAR_8_TYPE);

	s1a = DDS_DynamicTypeBuilder_build (sb1a);
	fail_unless (s1a != NULL);

	DDS_DynamicTypeBuilderFactory_delete_type (sb1a);

	DDS_SEQ_ITEM (bounds, 0) = 7;
	abs1a = DDS_DynamicTypeBuilderFactory_create_array_type (s1a, &bounds);
	fail_unless (abs1a != NULL);

	dds_seq_cleanup (&bounds);

	as1a = DDS_DynamicTypeBuilder_build (abs1a);
	fail_unless (as1a != NULL);

	DDS_DynamicTypeBuilderFactory_delete_type (abs1a);
	desc->kind = DDS_STRUCTURE_TYPE;
	desc->name = "dstruct2";
	sb1 = DDS_DynamicTypeBuilderFactory_create_type (desc);
	fail_unless (sb1 != NULL);

	ADD_FIELD (sb1, md, "c", 0, 0, DDS_CHAR_8_TYPE);

	md->name = "str2";
	md->index = md->id = 1;
	md->type = as1a;
	rc = DDS_DynamicTypeBuilder_add_member (sb1, md);
	fail_unless (rc == DDS_RETCODE_OK);

	ADD_FIELD (sb1, md, "u16", 2, 2, DDS_UINT_16_TYPE);

	s1 = DDS_DynamicTypeBuilder_build (sb1);
	fail_unless (s1 != NULL);

	DDS_DynamicTypeBuilderFactory_delete_type (sb1);
	ts = DDS_DynamicTypeSupport_create_type_support (s1);
	fail_unless (ts != NULL);

	DDS_TypeDescriptor__free (desc);
	DDS_MemberDescriptor__free (md);

	/* 2. Create a Dynamic Data item for this type. */
	dd = DDS_DynamicDataFactory_create_data (s1);
	fail_unless (dd != NULL);

	ddas = DDS_DynamicDataFactory_create_data (as1a);
	fail_unless (ddas != NULL);

	SET_FIELD (dd, 0, char8, 'A');
	for (i = 0; i < 7; i++) {
		dds = DDS_DynamicDataFactory_create_data (s1a);
		fail_unless (dds != NULL);

		dda = DDS_DynamicDataFactory_create_data (ai64);
		fail_unless (dda != NULL);

		for (j = 0; j < 5; j++) {
			SET_FIELD (dda, j, int64, ((i + 6) * j) << i);
		}
		SET_FIELD (dds, 0, complex, dda);
		DDS_DynamicDataFactory_delete_data (dda);

		SET_FIELD (dds, 1, char8, i + 0x30);

		SET_FIELD (ddas, i, complex, dds);
		DDS_DynamicDataFactory_delete_data (dds);
	}
	SET_FIELD (dd, 1, complex, ddas);
	DDS_DynamicDataFactory_delete_data (ddas);

	SET_FIELD (dd, 2, uint16, 1366);

	marshallDynamic (dd, &dd2, ts);

	DDS_DynamicDataFactory_delete_data (dd);
	DDS_DynamicTypeBuilderFactory_delete_type (s1);
	DDS_DynamicTypeBuilderFactory_delete_type (as1a);
	DDS_DynamicTypeBuilderFactory_delete_type (s1a);
	DDS_DynamicTypeBuilderFactory_delete_type (ai64);
	DDS_DynamicTypeSupport_delete_type_support (ts);
	v_printf ("success!\r\n");
}
Exemplo n.º 26
0
/*
 * This function provides an interface to reconfigure parts
 * of SDL and the VGA emulation during a DOSEMU session.
 * It is used by the xmode.exe program that comes with DOSEMU.
 */
static int SDL_change_config(unsigned item, void *buf)
{
  int err = 0;

  v_printf("SDL: SDL_change_config: item = %d, buffer = %p\n", item, buf);

  switch (item) {

  case CHG_TITLE:
    /* low-level write */
    if (buf) {
      char *sw, /**si,*/ *charset;
/*	size_t iconlen = strlen(config.X_icon_name) + 1;
	wchar_t iconw[iconlen];
	if (mbstowcs(iconw, config.X_icon_name, iconlen) == -1)
	  iconlen = 1;
	iconw[iconlen-1] = 0;*/
      charset = "utf8";
      sw = unicode_string_to_charset(buf, charset);
//      si = unicode_string_to_charset(iconw, charset);
      v_printf("SDL: SDL_change_config: win_name = %s\n", sw);
      SDL_SetWindowTitle(window, sw);
      free(sw);
//      free(si);
      break;
    }
    /* high-level write (shows name of emulator + running app) */
    /* fallthrough */

  case CHG_TITLE_EMUNAME:
  case CHG_TITLE_APPNAME:
  case CHG_TITLE_SHOW_APPNAME:
  case CHG_WINSIZE:
  case CHG_BACKGROUND_PAUSE:
  case GET_TITLE_APPNAME:
    change_config(item, buf, grab_active, kbd_grab_active);
    break;

#ifdef X_SUPPORT
  case CHG_FONT:{
      if (!x11_display || x11_window == None || use_bitmap_font)
	break;
      X_load_text_font(x11_display, 1, x11_window, buf,
		       &font_width, &font_height);
      if (win_width != vga.text_width * font_width ||
	  win_height != vga.text_height * font_height) {
	if (vga.mode_class == TEXT) {
	  render_mode_lock();
	  SDL_change_mode(0, 0, vga.text_width * font_width,
			  vga.text_height * font_height);
	  render_mode_unlock();
	}
      }
      break;
    }
#endif

  case CHG_FULLSCREEN:
    v_printf("SDL: SDL_change_config: fullscreen %i\n", *((int *) buf));
    if (*((int *) buf) == !config.X_fullscreen)
      toggle_fullscreen_mode();
    break;

  default:
    err = 100;
  }

  return err;
}
Exemplo n.º 27
0
void test_dyn_array1 (void)
{
	DDS_DynamicTypeSupport ts;
	DDS_DynamicTypeBuilder sb, abc20;
	DDS_TypeDescriptor *desc;
	DDS_MemberDescriptor *md;
	DDS_DynamicType s, ac20;
	DDS_BoundSeq bounds;
	DDS_DynamicData dd, dda, dd2;
	DDS_ReturnCode_t rc;
	unsigned i;

	v_printf ("test_dyn_array1 - ");

	/* 1. Create the type. */
	desc = DDS_TypeDescriptor__alloc ();
	fail_unless (desc != NULL);

	desc->kind = DDS_STRUCTURE_TYPE;
	desc->name = "dstruct1";
	sb = DDS_DynamicTypeBuilderFactory_create_type (desc);
	fail_unless (sb != NULL);

	md = DDS_MemberDescriptor__alloc ();
	fail_unless (md != NULL);

	DDS_SEQ_INIT (bounds);
	dds_seq_require (&bounds, 1);
	DDS_SEQ_LENGTH (bounds) = 1;
	DDS_SEQ_ITEM (bounds, 0) = 20;

	abc20 = DDS_DynamicTypeBuilderFactory_create_array_type (
		DDS_DynamicTypeBuilderFactory_get_primitive_type (DDS_CHAR_8_TYPE),
		&bounds);
	fail_unless (abc20 != NULL);

	dds_seq_cleanup (&bounds);

	ac20 = DDS_DynamicTypeBuilder_build (abc20);
	fail_unless (ac20 != NULL);

	DDS_DynamicTypeBuilderFactory_delete_type (abc20);

	md->name = "char_a";
	md->index = md->id = 0;
	md->type = ac20;

	rc = DDS_DynamicTypeBuilder_add_member (sb, md);
	fail_unless (rc == DDS_RETCODE_OK);

	s = DDS_DynamicTypeBuilder_build (sb);
	fail_unless (s != NULL);

	DDS_DynamicTypeBuilderFactory_delete_type (sb);
	ts = DDS_DynamicTypeSupport_create_type_support (s);
	fail_unless (ts != NULL);

	DDS_TypeDescriptor__free (desc);
	DDS_MemberDescriptor__free (md);

	/* 2. Create a Dynamic Data item for this type. */
	dd = DDS_DynamicDataFactory_create_data (s);
	fail_unless (dd != NULL);

	dda = DDS_DynamicDataFactory_create_data (ac20);
	fail_unless (dda != NULL);

	for (i = 0; i < 20; i++) {
		SET_FIELD (dda, i, char8, i + '0');
	}
	SET_FIELD (dd, 0, complex, dda);

	marshallDynamic (dd, &dd2, ts);

	DDS_DynamicDataFactory_delete_data (dd);
	DDS_DynamicDataFactory_delete_data (dda);

	DDS_DynamicTypeBuilderFactory_delete_type (ac20);
	DDS_DynamicTypeBuilderFactory_delete_type (s);
	DDS_DynamicTypeSupport_delete_type_support (ts);
	v_printf ("success!\r\n");
}
Exemplo n.º 28
0
static void SDL_handle_events(void)
{
  SDL_Event event;

  assert(pthread_equal(pthread_self(), dosemu_pthread_self));
  if (render_is_updating())
    return;
  while (SDL_PollEvent(&event)) {
    switch (event.type) {

    case SDL_WINDOWEVENT:
      switch (event.window.event) {
      case SDL_WINDOWEVENT_FOCUS_GAINED:
	v_printf("SDL: focus in\n");
	render_gain_focus();
	if (config.X_background_pause && !dosemu_user_froze)
	  unfreeze_dosemu();
	break;
      case SDL_WINDOWEVENT_FOCUS_LOST:
	v_printf("SDL: focus out\n");
	render_lose_focus();
	if (config.X_background_pause && !dosemu_user_froze)
	  freeze_dosemu();
	break;
      case SDL_WINDOWEVENT_RESIZED:
	/* very strange things happen: if renderer size was explicitly
	 * set, SDL reports mouse coords relative to that. Otherwise
	 * it reports mouse coords relative to the window. */
	SDL_RenderGetLogicalSize(renderer, &m_x_res, &m_y_res);
	if (!m_x_res || !m_y_res) {
	  m_x_res = event.window.data1;
	  m_y_res = event.window.data2;
	}
	update_mouse_coords();
	SDL_redraw();
	break;
      case SDL_WINDOWEVENT_EXPOSED:
	SDL_redraw();
	break;
      case SDL_WINDOWEVENT_ENTER:
        /* ignore fake enter events */
        if (config.X_fullscreen)
          break;
        mouse_drag_to_corner(m_x_res, m_y_res);
        break;
      }
      break;

    case SDL_KEYDOWN:
      {
	if (wait_kup)
	  break;
	SDL_Keysym keysym = event.key.keysym;
	if ((keysym.mod & KMOD_CTRL) && (keysym.mod & KMOD_ALT)) {
	  if (keysym.sym == SDLK_HOME || keysym.sym == SDLK_k) {
	    force_grab = 0;
	    toggle_grab(keysym.sym == SDLK_k);
	    break;
	  } else if (keysym.sym == SDLK_f) {
	    toggle_fullscreen_mode();
	    /* some versions of SDL re-send the keydown events after the
	     * full-screen switch. We need to filter them out to prevent
	     * the infinite switching loop. */
	    wait_kup = 1;
	    break;
	  }
	}
	if (vga.mode_class == TEXT &&
	    (keysym.sym == SDLK_LSHIFT || keysym.sym == SDLK_RSHIFT)) {
	  copypaste = 1;
	  /* enable cursor for copy/paste */
	  if (!m_cursor_visible)
	    SDL_ShowCursor(SDL_ENABLE);
	}
      }
#if CONFIG_SDL_SELECTION
      clear_if_in_selection();
#endif
#ifdef X_SUPPORT
#if HAVE_XKB
      if (x11_display && config.X_keycode)
	SDL_process_key_xkb(x11_display, event.key);
      else
#endif
#endif
	SDL_process_key(event.key);
      break;
    case SDL_KEYUP: {
      SDL_Keysym keysym = event.key.keysym;
      wait_kup = 0;
      if (copypaste && (keysym.sym == SDLK_LSHIFT ||
              keysym.sym == SDLK_RSHIFT)) {
        copypaste = 0;
        if (!m_cursor_visible)
	    SDL_ShowCursor(SDL_DISABLE);
      }
#ifdef X_SUPPORT
#if HAVE_XKB
      if (x11_display && config.X_keycode)
	SDL_process_key_xkb(x11_display, event.key);
      else
#endif
#endif
	SDL_process_key(event.key);
      break;
    }

    case SDL_MOUSEBUTTONDOWN:
      {
	int buttons = SDL_GetMouseState(NULL, NULL);
#if CONFIG_SDL_SELECTION
	if (window_has_focus() && !shift_pressed()) {
	  clear_selection_data();
	} else if (vga.mode_class == TEXT && !grab_active) {
	  if (event.button.button == SDL_BUTTON_LEFT)
	    start_selection(x_to_col(event.button.x, m_x_res),
			    y_to_row(event.button.y, m_y_res));
	  else if (event.button.button == SDL_BUTTON_RIGHT)
	    start_extend_selection(x_to_col(event.button.x, m_x_res),
				   y_to_row(event.button.y, m_y_res));
	  else if (event.button.button == SDL_BUTTON_MIDDLE) {
	    char *paste = SDL_GetClipboardText();
	    if (paste)
	      paste_text(paste, strlen(paste), "utf8");
	  }
	  break;
	}
#endif				/* CONFIG_SDL_SELECTION */
	mouse_move_buttons(buttons & SDL_BUTTON(1),
			   buttons & SDL_BUTTON(2),
			   buttons & SDL_BUTTON(3));
	break;
      }
    case SDL_MOUSEBUTTONUP:
      {
	int buttons = SDL_GetMouseState(NULL, NULL);
#if CONFIG_SDL_SELECTION
	if (vga.mode_class == TEXT && !grab_active) {
	    t_unicode *sel = end_selection();
	    if (sel) {
		char *send_text = get_selection_string(sel, "utf8");
		SDL_SetClipboardText(send_text);
		free(send_text);
	    }
	}
#endif				/* CONFIG_SDL_SELECTION */
	mouse_move_buttons(buttons & SDL_BUTTON(1),
			   buttons & SDL_BUTTON(2),
			   buttons & SDL_BUTTON(3));
	break;
      }

    case SDL_MOUSEMOTION:
#if CONFIG_SDL_SELECTION
      extend_selection(x_to_col(event.motion.x, m_x_res),
			 y_to_row(event.motion.y, m_y_res));
#endif				/* CONFIG_SDL_SELECTION */
      if (grab_active)
	mouse_move_relative(event.motion.xrel, event.motion.yrel,
			    m_x_res, m_y_res);
      else
	mouse_move_absolute(event.motion.x, event.motion.y, m_x_res,
			    m_y_res);
      break;
    case SDL_MOUSEWHEEL:
      mouse_move_wheel(-event.wheel.y);
      break;
    case SDL_QUIT:
      leavedos(0);
      break;
    default:
      v_printf("PAS ENCORE TRAITE %x\n", event.type);
      /* TODO */
      break;
    }
  }

#ifdef X_SUPPORT
  if (x11_display && !use_bitmap_font && vga.mode_class == TEXT &&
      X_handle_text_expose()) {
    /* need to check separately because SDL_VIDEOEXPOSE is eaten by SDL */
    redraw_text_screen();
  }
#endif
}
Exemplo n.º 29
0
static void test_listener (void)
{
	DDS_DomainParticipant		p;
	DDS_Topic			t;
	DDS_TopicDescription		td;
	DDS_Subscriber			sub;
	DDS_DataReader			dr;
	DDS_DataReaderListener		*lp;
	DDS_ReturnCode_t		r;

	p = DDS_DomainParticipantFactory_create_participant (0, DDS_PARTICIPANT_QOS_DEFAULT, NULL, 0);
	fail_unless (p != NULL);

	r = register_HelloWorldData_type (p);
	fail_unless (r == DDS_RETCODE_OK);
	t = DDS_DomainParticipant_create_topic (p, "HelloWorld", TYPE_NAME, DDS_TOPIC_QOS_DEFAULT, NULL, 0);
	fail_unless (t != NULL);

	td = DDS_DomainParticipant_lookup_topicdescription (p, "HelloWorld");
	fail_unless (td != NULL);

	sub = DDS_DomainParticipant_create_subscriber (p, DDS_SUBSCRIBER_QOS_DEFAULT, NULL, 0);
	fail_unless (sub != NULL);

	v_printf (" - Test reader listener.\r\n");
	dr = DDS_Subscriber_create_datareader (sub, td, DDS_DATAREADER_QOS_DEFAULT, NULL, 0);
	fail_unless (dr != NULL);

	lp = DDS_DataReader_get_listener (dr);
	fail_unless (lp != NULL &&
		     lp->on_sample_rejected == NULL &&
		     lp->on_liveliness_changed == NULL &&
		     lp->on_requested_deadline_missed == NULL &&
		     lp->on_requested_incompatible_qos == NULL &&
		     lp->on_data_available == NULL &&
		     lp->on_subscription_matched == NULL &&
		     lp->on_sample_lost == NULL);

	v_printf (" - Test specific reader listener updates.\r\n");
	r = DDS_DataReader_set_listener (dr, &r_listener,
			DDS_SAMPLE_REJECTED_STATUS |
			DDS_LIVELINESS_CHANGED_STATUS |
			DDS_REQUESTED_DEADLINE_MISSED_STATUS |
			DDS_REQUESTED_INCOMPATIBLE_QOS_STATUS |
			DDS_DATA_AVAILABLE_STATUS |
			DDS_SUBSCRIPTION_MATCHED_STATUS |
			DDS_SAMPLE_LOST_STATUS);
	fail_unless (r == DDS_RETCODE_OK);

	lp = DDS_DataReader_get_listener (dr);
	fail_unless (lp != NULL &&
		     lp->on_sample_rejected == sample_rejected &&
		     lp->on_liveliness_changed == liveliness_changed &&
		     lp->on_requested_deadline_missed == requested_deadline_missed &&
		     lp->on_requested_incompatible_qos == requested_inc_qos &&
		     lp->on_data_available == data_available &&
		     lp->on_subscription_matched == subscription_matched &&
		     lp->on_sample_lost == sample_lost &&
		     lp->cookie == (void *) 0x44556677);

	v_printf (" - Test default reader listener update.\r\n");
	r = DDS_DataReader_set_listener (dr, NULL, DDS_REQUESTED_DEADLINE_MISSED_STATUS);
	fail_unless (r == DDS_RETCODE_OK);
	lp = DDS_DataReader_get_listener (dr);
	fail_unless (lp != NULL &&
		     lp->on_sample_rejected == NULL &&
		     lp->on_liveliness_changed == NULL &&
		     lp->on_requested_deadline_missed == NULL &&
		     lp->on_requested_incompatible_qos == NULL &&
		     lp->on_data_available == NULL &&
		     lp->on_subscription_matched == NULL &&
		     lp->on_sample_lost == NULL);
	r = DDS_Subscriber_delete_datareader (sub, dr);
	fail_unless (r == DDS_RETCODE_OK);
	r = DDS_DomainParticipant_delete_subscriber (p, sub);
	fail_unless (r == DDS_RETCODE_OK);
	r = DDS_DomainParticipant_delete_topic (p, t);
	fail_unless (r == DDS_RETCODE_OK);
	unregister_HelloWorldData_type (p);
	r = DDS_DomainParticipantFactory_delete_participant (p);
	fail_unless (r == DDS_RETCODE_OK);
}
Exemplo n.º 30
0
int handle_decode(int argc, char **argv, Images &images, flif_options &options) {
    if (options.scale < 0) {
        // just identify the file(s), don't actually decode
        while (argc>0) {
            decode_flif(argv, images, options);
            argv++; argc--;
        }
        return 0;
    }
    if (argc == 1 && options.show_breakpoints) {
        decode_flif(argv, images, options);
        return 0;
    }
    char *ext = strrchr(argv[1],'.');
    if (check_metadata_extension(ext)) {
        // only requesting metadata, no need to actually decode the file
        options.scale = -2;
        decode_flif(argv, images, options);
        if (!images[0].save(argv[1])) return 2;
        v_printf(2,"\n");
        return 0;
    }
    if (!check_compatible_extension(ext) && strcmp(argv[1],"null:") && strcmp(argv[1],"-")) {
        e_printf("Error: expected \".png\", \".pnm\" or \".pam\" file name extension for output file\n");
        return 1;
    }
    if (!(ext && ( !strcasecmp(ext,".png"))))
        options.keep_palette = false;   // don't try to make a palette PNM

    try {
      if (!decode_flif(argv, images, options)) {
        e_printf("Error: could not decode FLIF file\n"); return 3;
      }
    } catch (std::bad_alloc& ba) {
        e_printf("Error: memory allocation problem (unexpected)\n"); return 3;
    }
    if (!strcmp(argv[1],"null:")) return 0;
//    if (scale>1)
//        v_printf(3,"Downscaling output: %ux%u -> %ux%u\n",images[0].cols(),images[0].rows(),images[0].cols()/scale,images[0].rows()/scale);
    if (images.size() == 1) {
        if (!images[0].save(argv[1])) return 2;
    } else {
        bool to_stdout=false;
        if (!strcmp(argv[1],"-")) {
            to_stdout=true;
            v_printf(1,"Warning: writing animation to standard output as a concatenation of PAM files.\n");
        }
        int counter=0;
        int maxlength = strlen(argv[1])+100;
        std::vector<char> vfilename(maxlength);
        char *filename = &vfilename[0];
        bool use_custom_format = false;
        if (strchr(argv[1],'%')) use_custom_format = true;
        strcpy(filename,argv[1]);
        char *a_ext = strrchr(filename,'.');
        if (!a_ext && !to_stdout) {
            e_printf("Problem saving animation to %s\n",filename);
            return 2;
        }
        for (Image& image : images) {
            if (!to_stdout) {
              if (use_custom_format) snprintf(filename,maxlength,argv[1],counter);
              else if (images.size() < 1000) sprintf(a_ext,"-%03d%s",counter,ext);
              else if (images.size() < 10000) sprintf(a_ext,"-%04d%s",counter,ext);
              else if (images.size() < 100000) sprintf(a_ext,"-%05d%s",counter,ext);
              else sprintf(a_ext,"-%08d%s",counter,ext);
              if (file_exists(filename) && !options.overwrite) {
                e_printf("Error: output file already exists: %s\nUse --overwrite to force overwrite.\n",filename);
                return 4;
              }
              if (!image.save(filename)) return 2;
            } else {
              if (!image.save(argv[1])) return 2;
            }
            counter++;
            v_printf(2,"    (%i/%i)         \r",counter,(int)images.size()); v_printf(4,"\n");
        }
    }
    // get rid of palette (should also do this in the non-standard/error paths, but being lazy here since the tool will exit anyway)
    images[0].clear();
    v_printf(2,"\n");
    return 0;
}