Example #1
0
/**
 *  Test that for Jpeg files that use the JFIF colorspace, they are
 *  directly embedded into the PDF (without re-encoding) when that
 *  makes sense.
 */
DEF_TEST(PDFJpegEmbedTest, r) {
    const char test[] = "PDFJpegEmbedTest";
    SkAutoTUnref<SkData> mandrillData(
            load_resource(r, test, "mandrill_512_q075.jpg"));
    SkAutoTUnref<SkData> cmykData(load_resource(r, test, "CMYK.jpg"));
    if (!mandrillData || !cmykData) {
        return;
    }

    SkDynamicMemoryWStream pdf;
    SkAutoTUnref<SkDocument> document(SkDocument::CreatePDF(&pdf));
    SkCanvas* canvas = document->beginPage(642, 1028);

    canvas->clear(SK_ColorLTGRAY);

    SkBitmap bm1(bitmap_from_data(mandrillData));
    canvas->drawBitmap(bm1, 65.0, 0.0, NULL);
    SkBitmap bm2(bitmap_from_data(cmykData));
    canvas->drawBitmap(bm2, 0.0, 512.0, NULL);

    canvas->flush();
    document->endPage();
    document->close();
    SkAutoTUnref<SkData> pdfData(pdf.copyToData());
    SkASSERT(pdfData);
    pdf.reset();

    REPORTER_ASSERT(r, is_subset_of(mandrillData, pdfData));

    // This JPEG uses a nonstandard colorspace - it can not be
    // embedded into the PDF directly.
    REPORTER_ASSERT(r, !is_subset_of(cmykData, pdfData));
}
Example #2
0
struct level *
load_dat_level (struct level *l, int n)
{
  char *filename;
  xasprintf (&filename, levels_dat_filename);

  int8_t *dat =
    load_resource (filename, (load_resource_f) load_file);

  if (! dat) {
    error (0, 0, "cannot read dat level file %s", filename);
    return NULL;
  }

  al_free (filename);

  int8_t *offset;
  int16_t size;
  dat_getres (dat, 2000 + n, &offset, &size);

  if (! offset) {
    error (0, 0, "incorrect format for dat level file %s", filename);
    return NULL;
  }

  memcpy (&lv, offset, sizeof (lv));

  interpret_legacy_level (l, n);
  l->next_level = next_dat_level;

  al_free (dat);
  return l;
}
Example #3
0
void
load_dat_level (int number)
{
  char *filename;
  xasprintf (&filename, levels_dat_filename);

  int8_t *dat =
    load_resource (filename, (load_resource_f) load_file);

  if (! dat)
    error (-1, 0, "cannot read dat level file %s", filename);

  al_free (filename);

  int8_t *offset;
  int16_t size;
  dat_getres (dat, 2000 + number, &offset, &size);

  if (! offset)
    error (-1, 0, "incorrect format for dat level file %s", filename);

  memcpy (&lv, offset, sizeof (lv));

  interpret_legacy_level (number);
  legacy_level.next_level = next_dat_level;

  al_free (dat);
}
Example #4
0
/**
   Read all resources in the resource manager block in CCS.

   @param reslist       Empty list to fill with resources.
   @param rulelist      List of rules to use when searching CCS.
   @return              0 on success, nonzero on failure.
 */
int
load_resources(resource_t ** reslist, resource_rule_t ** rulelist)
{
    int resID = 0;
    resource_t *newres;
    resource_rule_t *currule;
    char tok[256];

    list_do(rulelist, currule) {

        for (resID = 1;; resID++) {
            /* XXX check */
            snprintf(tok, sizeof(tok), RESOURCE_BASE "/%s[%d]", currule->rr_type, resID);

            newres = load_resource(currule, tok);
            if (!newres)
                break;

            if (store_resource(reslist, newres) != 0) {
                fprintf(stderr, "Error storing %s resource\n", newres->r_rule->rr_type);

                destroy_resource(newres);
                continue;
            }

            /* Just information */
            newres->r_flags = RF_DEFINED;
        }
    }
    while (!list_done(rulelist, currule)) ;

    return 0;
}
DEF_TEST(JpegIdentification, r) {
    static struct {
        const char* path;
        bool isJfif;
        SkJFIFInfo::Type type;
    } kTests[] = {{"CMYK.jpg", false, SkJFIFInfo::kGrayscale},
                  {"color_wheel.jpg", true, SkJFIFInfo::kYCbCr},
                  {"grayscale.jpg", true, SkJFIFInfo::kGrayscale},
                  {"mandrill_512_q075.jpg", true, SkJFIFInfo::kYCbCr},
                  {"randPixels.jpg", true, SkJFIFInfo::kYCbCr}};
    for (size_t i = 0; i < SK_ARRAY_COUNT(kTests); ++i) {
        SkAutoTUnref<SkData> data(
                load_resource(r, "JpegIdentification", kTests[i].path));
        if (!data) {
            continue;
        }
        SkJFIFInfo info;
        bool isJfif = SkIsJFIF(data, &info);
        if (isJfif != kTests[i].isJfif) {
            ERRORF(r, "%s failed isJfif test", kTests[i].path);
            continue;
        }
        if (!isJfif) {
            continue;  // not applicable
        }
        if (kTests[i].type != info.fType) {
            ERRORF(r, "%s failed jfif type test", kTests[i].path);
            continue;
        }
        if (r->verbose()) {
            SkDebugf("\nJpegIdentification: %s [%d x %d]\n", kTests[i].path,
                     info.fSize.width(), info.fSize.height());
        }
    }
}
Example #6
0
/**
 *  Test that for Jpeg files that use the JFIF colorspace, they are
 *  directly embedded into the PDF (without re-encoding) when that
 *  makes sense.
 */
DEF_TEST(PDFJpegEmbedTest, r) {
    const char test[] = "PDFJpegEmbedTest";
    SkAutoTUnref<SkData> mandrillData(
            load_resource(r, test, "mandrill_512_q075.jpg"));
    SkAutoTUnref<SkData> cmykData(load_resource(r, test, "CMYK.jpg"));
    if (!mandrillData || !cmykData) {
        return;
    }

    SkDynamicMemoryWStream pdf;
    SkAutoTUnref<SkDocument> document(SkDocument::CreatePDF(&pdf));
    SkCanvas* canvas = document->beginPage(642, 1028);

    canvas->clear(SK_ColorLTGRAY);

    SkBitmap bm1(bitmap_from_data(mandrillData));
    canvas->drawBitmap(bm1, 65.0, 0.0, NULL);
    SkBitmap bm2(bitmap_from_data(cmykData));
    canvas->drawBitmap(bm2, 0.0, 512.0, NULL);

    canvas->flush();
    document->endPage();
    document->close();
    SkAutoTUnref<SkData> pdfData(pdf.copyToData());
    SkASSERT(pdfData);
    pdf.reset();

    // Test disabled, waiting on resolution to http://skbug.com/3180
    // REPORTER_ASSERT(r, is_subset_of(mandrillData, pdfData));

    // This JPEG uses a nonstandard colorspace - it can not be
    // embedded into the PDF directly.
    REPORTER_ASSERT(r, !is_subset_of(cmykData, pdfData));

    // The following is for debugging purposes only.
    const char* outputPath = getenv("SKIA_TESTS_PDF_JPEG_EMBED_OUTPUT_PATH");
    if (outputPath) {
        SkFILEWStream output(outputPath);
        if (output.isValid()) {
            output.write(pdfData->data(), pdfData->size());
        }
    }
}
Example #7
0
    bool load(const char *file_name)
    {
        auto r = load_resource(file_name);
        if (!r.get_data())
            return false;

        const bool result = load(r.get_data(), r.get_size());
        r.free();
        return result;
    }
Example #8
0
File: main.c Project: firejox/UML
int main (int argc, char **argv) {
    application_t app = {0};

    application_init (&app, &argc, &argv);

    load_resource (&app);

    application_run (&app);

    return 0;
}
Example #9
0
static BOOL WINAPI test_enum_proc(HMODULE module, LPCTSTR type, LPSTR name, LONG_PTR param)
{
    const char *cmd_data, *out_data;
    DWORD cmd_size, out_size;
    char res_name[100];

    trace("running %s test...\n", name);

    cmd_size = load_resource(name, type, &cmd_data);
    if(!cmd_size)
        return TRUE;

    sprintf(res_name, "%s.exp", name);
    out_size = load_resource(res_name, "TESTOUT", &out_data);
    if(!out_size)
        return TRUE;

    run_test(cmd_data, cmd_size, out_data, out_size);
    return TRUE;
}
Example #10
0
xaeSound::xaeSound(string path, bool loop, int volume, int pan, float pitch) :
    m_nVolume(volume),
    m_bLoop(loop),
    m_nPan(pan),
    m_fPitch(pitch)
{
    if(!_bEffectInited)
    {
        _bEffectInited = true;
        _hEffect.clear();
        ::InitializeCriticalSection(&_eff_cs);
    }

    load_resource(path);
}
void TexturePacker::load_resources(CL_GraphicContext &gc, const CL_String &filename)
{
	resources = CL_ResourceManager(filename);

	// TODO: Delete items before clearing
	resource_items.clear();

	std::vector<CL_String> resource_names = resources.get_resource_names();
	std::vector<CL_String>::iterator resource_it;
	for(resource_it = resource_names.begin(); resource_it != resource_names.end(); ++resource_it)
	{
		CL_String resource_id = (*resource_it);
		CL_Resource resource = resources.get_resource(resource_id);

		resource_items.push_back(load_resource(gc, resource_id, resource, resources));
	}
}
Example #12
0
void TexturePacker::load_resources(Canvas &canvas, const std::string &filename)
{
	resources = ResourceManager(filename);

	// TODO: Delete items before clearing
	resource_items.clear();

	std::vector<std::string> resource_names = resources.get_resource_names();
	std::vector<std::string>::iterator resource_it;
	for(resource_it = resource_names.begin(); resource_it != resource_names.end(); ++resource_it)
	{
		std::string resource_id = (*resource_it);
		Resource resource = resources.get_resource(resource_id);

		resource_items.push_back(load_resource(canvas, resource_id, resource, resources));
	}
}
Example #13
0
ALLEGRO_BITMAP *
load_bitmap (char *filename)
{
  set_target_backbuffer (display);

  ALLEGRO_BITMAP *bitmap =
    load_resource (filename, (load_resource_f) al_load_bitmap);

  if (! bitmap)
    error (-1, 0, "%s: cannot load bitmap file '%s'",
           __func__, filename);

  validate_bitmap_for_mingw (bitmap);

  if (load_callback) load_callback ();

  return bitmap;
}
Example #14
0
void TexturePacker::load_resources(clan::Canvas &canvas, const std::string &filename)
{
	resources_doc = clan::XMLResourceDocument(filename);
	resources = clan::XMLResourceManager::create(resources_doc);

	// TODO: Delete items before clearing
	resource_items.clear();

	std::vector<std::string> resource_names = resources_doc.get_resource_names();
	std::vector<std::string>::iterator resource_it;
	for(resource_it = resource_names.begin(); resource_it != resource_names.end(); ++resource_it)
	{
		std::string resource_id = (*resource_it);
		clan::XMLResourceNode resource = resources_doc.get_resource(resource_id);

		resource_items.push_back(load_resource(canvas, resource_id, resource, resources));
	}
}
Example #15
0
static multicart_open_error load_all_resources(emu_options &options, multicart_load_state *state)
{
	multicart_open_error err;
	xml_data_node *resource_node;
	multicart_resource_type resource_type;

	for (resource_node = state->resources_node->child; resource_node != NULL; resource_node = resource_node->next)
	{
		resource_type = get_resource_type(resource_node->name);
		if (resource_type != MULTICART_RESOURCE_TYPE_INVALID)
		{
			err = load_resource(options, state, resource_node, resource_type);
			if (err != MCERR_NONE)
				return err;
		}
	}

	state->multicart->resources = state->resources;
	return MCERR_NONE;
}
Example #16
0
bool effect_clouds::read_bdd(const char *name, bdd &bdd_res)
{
    nya_memory::tmp_buffer_ref res = load_resource(name);
    if (!res.get_size())
        return false;

    nya_memory::memory_reader reader(res.get_data(), res.get_size());

    bdd_header header = reader.read<bdd_header>();

    assume(header.unknown == '0001');
    assume(header.zero == 0);

    bdd_res.hiflat_clouds.resize(header.hiflat_clouds_count);
    for (auto &p: bdd_res.hiflat_clouds)
        p.x = reader.read<float>(), p.y = reader.read<float>();

    bdd_res.type2_pos.resize(header.type2_count);
    for (auto &p: bdd_res.type2_pos)
        p.x = reader.read<float>(), p.y = reader.read<float>();

    bdd_res.type3_pos.resize(header.type3_count);
    for (auto &p: bdd_res.type3_pos)
        p.x = reader.read<float>(), p.y = reader.read<float>();

    bdd_res.type4_pos.resize(header.type4_count);
    for (auto &p: bdd_res.type4_pos)
        p.x = reader.read<float>(), p.y = reader.read<float>();

    bdd_res.obj_clouds.resize(header.obj_clouds_count);
    for (auto &p: bdd_res.obj_clouds)
        p.first = reader.read<int>(), p.second.x = reader.read<float>(), p.second.y = reader.read<float>();

    assume(reader.get_remained() == 0);

    bdd_res.header=header; //ToDo

    res.free();
    return true;
}
Example #17
0
nya_scene::texture load_tonecurve(const char *file_name)
{
    nya_scene::shared_texture t;
    auto res = load_resource(file_name);
    assert(res.get_size() == 256 * 3);

    const unsigned char *data = (const unsigned char *)res.get_data();
    unsigned char color[256 * 3];
    for (int i = 0; i < 3; ++i)
    {
        for (int j = 0; j < 256; ++j)
            color[j*3+i]=data[j+i*256];
    }

    t.tex.build_texture(color, 256, 1, nya_render::texture::color_rgb);
    t.tex.set_wrap(nya_render::texture::wrap_clamp, nya_render::texture::wrap_clamp);
    res.free();
    
    nya_scene::texture result;
    result.create(t);
    return result;
}
Example #18
0
bool sky_mesh::load(const char *name)
{
    if (!name)
        return false;

    renderer::sph t;

    if (is_native_location(name))
    {
        auto &p = get_native_location_provider(name);
        nya_memory::tmp_buffer_scoped res(load_resource(p.access("sky.sph")));
        t.load(res.get_data(), res.get_size());
    }
    else
        t.load((std::string("Map/sph_") + name + ".sph").c_str());

    renderer::sph::color_table ct(t.data[0]);

    solid_sphere s(64000.0, ct);

    m_mesh.set_vertex_data(&s.vertices[0], sizeof(solid_sphere::vert), (unsigned int)s.vertices.size());
    m_mesh.set_colors(sizeof(solid_sphere::vert::pos), 3);
    m_mesh.set_index_data(&s.indices[0], nya_render::vbo::index2b, (unsigned int)s.indices.size());

    auto dithering = shared::get_texture(shared::load_texture("PostProcess/dithering.nut"));

    m_material.get_default_pass().set_shader(nya_scene::shader("shaders/sky.nsh"));
    m_material.get_default_pass().get_state().zwrite = false;
    m_material.set_texture("dithering", dithering);

    m_fog_color.x = ct.fog_color.r * hdr_k;
    m_fog_color.y = ct.fog_color.g * hdr_k;
    m_fog_color.z = ct.fog_color.b * hdr_k;

    return true;
}
Example #19
0
static void test_wmp_ifaces(IOleObject *oleobj)
{
    IWMPSettings *settings, *settings_qi;
    IWMPPlayer4 *player4;
    IWMPPlayer *player;
    IWMPMedia *media;
    IWMPControls *controls;
    VARIANT_BOOL vbool;
    IWMPNetwork *network;
    HRESULT hres;
    BSTR filename;
    BSTR url;

    hres = IOleObject_QueryInterface(oleobj, &IID_IWMPPlayer4, (void**)&player4);
    ok(hres == S_OK, "Could not get IWMPPlayer4 iface: %08x\n", hres);

    controls = NULL;
    hres = IWMPPlayer4_get_controls(player4, &controls);
    ok(hres == S_OK, "get_controls failed: %08x\n", hres);
    ok(controls != NULL, "controls = NULL\n");

    player = NULL;
    hres = IWMPControls_QueryInterface(controls, &IID_IWMPPlayer, (void**)&player);
    ok(hres != S_OK, "Getting IWMPPlayer from IWMPControls SUCCEEDED\n");
    ok(player == NULL, "player != NULL\n");

    IWMPControls_Release(controls);

    /* IWPNetwork */
    network = NULL;
    hres = IWMPPlayer4_get_network(player4, &network);
    ok(hres == S_OK, "get_network failed: %08x\n", hres);
    ok(network != NULL, "network = NULL\n");

    player = NULL;
    hres = IWMPNetwork_QueryInterface(network, &IID_IWMPPlayer, (void**)&player);
    ok(hres != S_OK, "Getting IWMPPlayer from IWMPNetwork SUCCEEDED\n");
    ok(player == NULL, "player != NULL\n");

    IWMPNetwork_Release(network);

    media = NULL;
    hres = IWMPPlayer4_QueryInterface(player4, &IID_IWMPMedia, (void**)&media);
    ok(hres == E_NOINTERFACE, "get_currentMedia SUCCEEDED: %08x\n", hres);
    ok(media == NULL, "media != NULL\n");

    /* Test media put/get */
    media = NULL;
    hres = IWMPPlayer4_get_currentMedia(player4, &media);
    ok(hres == S_FALSE, "get_currentMedia SUCCEEDED\n");
    ok(media == NULL, "media != NULL\n");

    filename = SysAllocString(load_resource(mp3file));

    SET_EXPECT(GetContainer);
    SET_EXPECT(Invoke_USERMODE);
    hres = IWMPPlayer4_put_URL(player4, filename);
    ok(hres == S_OK, "IWMPPlayer4_put_URL failed: %08x\n", hres);
    todo_wine CHECK_CALLED_OR_BROKEN(GetContainer);
    todo_wine CHECK_CALLED(Invoke_USERMODE);

    url = NULL;
    SET_EXPECT(Invoke_USERMODE);
    hres = IWMPPlayer4_get_URL(player4, &url);
    ok(hres == S_OK, "IWMPPlayer4_get_URL failed: %08x\n", hres);
    ok(0 == lstrcmpW(url, filename), "%s != %s\n", wine_dbgstr_w(url), wine_dbgstr_w(filename));
    todo_wine CHECK_CALLED(Invoke_USERMODE);
    SysFreeString(url);

    hres = IWMPPlayer4_get_currentMedia(player4, &media);
    ok(hres == S_OK, "get_currentMedia failed: %08x\n", hres);
    ok(media != NULL, "media = (%p)\n", media);

    url = NULL;
    hres = IWMPMedia_get_sourceURL(media, &url);
    ok(hres == S_OK, "IWMPMedia_get_sourceURL failed: %08x\n", hres);
    ok(0 == lstrcmpW(url, filename), "%s != %s\n", wine_dbgstr_w(url), wine_dbgstr_w(filename));
    SysFreeString(url);

    SET_EXPECT(GetContainer);
    hres = IWMPPlayer4_put_currentMedia(player4, media);
    ok(hres == S_OK, "put_currentMedia failed: %08x\n", hres);
    todo_wine CHECK_CALLED_OR_BROKEN(GetContainer);

    IWMPMedia_Release(media);

    hres = IWMPPlayer4_get_currentMedia(player4, &media);
    ok(hres == S_OK, "get_currentMedia failed: %08x\n", hres);
    ok(media != NULL, "media = (%p)\n", media);

    IWMPMedia_Release(media);

    settings = NULL;
    hres = IWMPPlayer4_get_settings(player4, &settings);
    ok(hres == S_OK, "get_settings failed: %08x\n", hres);
    ok(settings != NULL, "settings = NULL\n");

    hres = IOleObject_QueryInterface(oleobj, &IID_IWMPSettings, (void**)&settings_qi);
    ok(hres == S_OK, "Could not get IWMPSettings iface: %08x\n", hres);
    ok(settings == settings_qi, "settings != settings_qi\n");
    IWMPSettings_Release(settings_qi);

    /* Test few settings put/gets */
    hres = IWMPSettings_get_autoStart(settings, &vbool);
    ok(hres == S_OK, "Could not get autoStart from IWMPSettings: %08x\n", hres);
    ok(vbool == VARIANT_TRUE, "autoStart = %x\n", vbool);
    hres = IWMPSettings_put_autoStart(settings, VARIANT_FALSE);
    ok(hres == S_OK, "Could not put autoStart in IWMPSettings: %08x\n", hres);
    hres = IWMPSettings_get_autoStart(settings, &vbool);
    ok(hres == S_OK, "Could not get autoStart from IWMPSettings: %08x\n", hres);
    ok(!vbool, "autoStart = %x\n", vbool);

    hres = IWMPSettings_get_invokeURLs(settings, &vbool);
    ok(hres == S_OK, "Could not get invokeURLs from IWMPSettings: %08x\n", hres);
    ok(vbool == VARIANT_TRUE, "invokeURLs = %x\n", vbool);
    hres = IWMPSettings_put_invokeURLs(settings, VARIANT_FALSE);
    ok(hres == S_OK, "Could not put invokeURLs in IWMPSettings: %08x\n", hres);
    hres = IWMPSettings_get_invokeURLs(settings, &vbool);
    ok(hres == S_OK, "Could not get invokeURLs from IWMPSettings: %08x\n", hres);
    ok(!vbool, "invokeURLs = %x\n", vbool);

    hres = IWMPSettings_get_enableErrorDialogs(settings, &vbool);
    ok(hres == S_OK, "Could not get enableErrorDialogs from IWMPSettings: %08x\n", hres);
    ok(vbool == VARIANT_FALSE, "enableErrorDialogs = %x\n", vbool);
    hres = IWMPSettings_put_enableErrorDialogs(settings, VARIANT_TRUE);
    ok(hres == S_OK, "Could not put enableErrorDialogs in IWMPSettings: %08x\n", hres);
    hres = IWMPSettings_get_enableErrorDialogs(settings, &vbool);
    ok(hres == S_OK, "Could not get enableErrorDialogs from IWMPSettings: %08x\n", hres);
    ok(vbool == VARIANT_TRUE, "enableErrorDialogs = %x\n", vbool);

    IWMPSettings_Release(settings);
    IWMPPlayer4_Release(player4);

    hres = IOleObject_QueryInterface(oleobj, &IID_IWMPPlayer, (void**)&player);
    ok(hres == S_OK, "Could not get IWMPPlayer iface: %08x\n", hres);

    settings = NULL;
    hres = IWMPPlayer_get_settings(player, &settings);
    ok(hres == S_OK, "get_settings failed: %08x\n", hres);
    ok(settings != NULL, "settings = NULL\n");

    hres = IOleObject_QueryInterface(oleobj, &IID_IWMPSettings, (void**)&settings_qi);
    ok(hres == S_OK, "Could not get IWMPSettings iface: %08x\n", hres);
    ok(settings == settings_qi, "settings != settings_qi\n");
    IWMPSettings_Release(settings_qi);

    IWMPSettings_Release(settings);
    IWMPPlayer_Release(player);
    DeleteFileW(filename);
    SysFreeString(filename);
}
Example #20
0
TileMapParseStatus TileMap_parse_tileset(xmlTextReaderPtr reader,
                                         Engine *engine, TileMap *map,
                                         Tileset **out_tileset) {
  TileMapParseStatus status = TILEMAP_PARSE_OK;
  Tileset *tileset = calloc(1, sizeof(Tileset));
  check(tileset != NULL, "Couldn't create tileset");
  
  while (xmlTextReaderMoveToNextAttribute(reader)) {
    xmlChar *attrName = xmlTextReaderName(reader);
    xmlChar *attrVal = xmlTextReaderValue(reader);
    
    if (streq(attrName, "firstgid")) {
      tileset->first_gid = atoi((const char *)attrVal);
    } else if (streq(attrName, "tilewidth")) {
      tileset->tile_size.w = atoi((const char *)attrVal);
    } else if (streq(attrName, "tileheight")) {
      tileset->tile_size.h = atoi((const char *)attrVal);
    } else if (streq(attrName, "name")) {
      tileset->name = calloc(1, strlen((const char *)attrVal) + 1);
      strcpy(tileset->name, (const char *)attrVal);
    }
  }
  while (xmlTextReaderRead(reader)) {
    xmlChar *childName = xmlTextReaderName(reader);
    if (xmlTextReaderNodeType(reader) == XML_ELEMENT_DECL &&
        streq(childName, "tileset")) {
      break;
    } else if (streq(childName, "image")) {
      while (xmlTextReaderMoveToNextAttribute(reader)) {
        xmlChar *attrName = xmlTextReaderName(reader);
        xmlChar *attrVal = xmlTextReaderValue(reader);
        
        if (streq(attrName, "source")) {
          // Check for existence of image
          bstring imgpath = bfromcstr("media/tilesets/");
          bstring src = bfromcstr((const char *)attrVal);
          bconcat(imgpath, src);
          char *cpath = bstr2cstr(imgpath, '\0');
          bdestroy(imgpath);
          bdestroy(src);
          
          FILE *fileexists = load_resource(cpath);
          if (fileexists == NULL) {
            free(cpath);
            Tileset_destroy(tileset);
            Engine_log("Cannot open map. Missing tileset <%s>", attrVal);
            return TILEMAP_PARSE_MISSING_IMAGE;
          }
          fclose(fileexists);
          
          tileset->texture = Graphics_texture_from_image(engine->graphics,
                                                         cpath);
          tileset->img_src = cpath;
        }
      }
    }
  }
  
  *out_tileset = tileset;
  
  return status;
error:
  if (tileset) Tileset_destroy(tileset);
  if (status == TILEMAP_PARSE_OK) status = TILEMAP_PARSE_UNKNOWN_ERR;
  return status;
}
Example #21
0
void *roadmap_res_get (unsigned int type, unsigned int flags,
                       const char *name) {

   void *data = NULL;
   int mem;
   RoadMapResource *res = &Resources[type];
   int slot;
	
   if (name == NULL || (name[0] == 0))
   	return NULL;
   if (Resources[type].hash == NULL) allocate_resource (type);

   if (! (flags & RES_NOCACHE))
   {
      int slot;
         slot = find_resource ( type, name );

      if ( slot >= 0 )
	  {
    	  roadmap_res_cache_set_MRU( res, slot );
    	  data = res->slots[slot].data;
    	  return data;
	  }
   }

   if (flags & RES_NOCREATE) return NULL;

   switch (type) {
   case RES_BITMAP:
   case RES_NATIVE_IMAGE:
      if ( strchr (name, '.') )
      {
     	 if ( !data )
     	 {
     		 data = load_resource( type, flags, name, &mem );
     	 }
      }
      else
      {
			 char *full_name = malloc (strlen (name) + 5);
			 data = NULL;


			 if ( flags & RES_DOWNLOADED_IMAGE){
#ifdef RIMAPI
				 /* Try BIN */
				 if ( !data )
				 {
					sprintf( full_name, "%s.bin", name );
					data = load_resource (type, flags, full_name, &mem);
				 }
#endif
			 }

			 /* Try PNG */
			 if ( !data )
			 {
				 sprintf( full_name, "%s.png", name );
				 data = load_resource (type, flags, full_name, &mem);
			 }
#if   defined (ANDROID) || defined (RIMAPI)
			 /* Try BIN */
			 if ( !data )
			 {
			 	sprintf( full_name, "%s.bin", name );
				data = load_resource (type, flags, full_name, &mem);
			 }
#endif
			 free (full_name);
      }
      break;

   default:
      data = load_resource (type, flags, name, &mem);
   }

   if (!data) {
   	if (type != RES_SOUND)
   		roadmap_log (ROADMAP_ERROR, "roadmap_res_get - resource %s type=%d not found.", name, type);
   	return NULL;
   }

   if ( flags & RES_NOCACHE )
   {
	   if ( type == RES_BITMAP )
	   {
		   roadmap_canvas_unmanaged_list_add( data );
	   }
	   return data;
   }

   slot = roadmap_res_cache_add( res, roadmap_hash_string( name ) );

   roadmap_log( ROADMAP_DEBUG, "Placing the resource at Slot: %d, Flags: %d, ", slot, flags );

   res->slots[slot].data = data;
   res->slots[slot].name = strdup(name);
   res->slots[slot].flags = flags;

   res->used_mem += mem;

   return data;
}
Example #22
0
/* main:
 *  Guess what this function does.
 */
int main(int argc, char *argv[])
{
   PACKFILE *f;
   CFURLRef cf_url_ref;
   FSRef fs_ref;
   FSSpec fs_spec;
   IconFamilyHandle icon_family;
   Handle raw_data;
   char datafile[MAX_STRING_SIZE];
   char bundle[MAX_STRING_SIZE];
   char bundle_dir[MAX_STRING_SIZE];
   char bundle_contents_dir[MAX_STRING_SIZE];
   char bundle_contents_resources_dir[MAX_STRING_SIZE];
   char bundle_contents_macos_dir[MAX_STRING_SIZE];
   char bundle_contents_frameworks_dir[MAX_STRING_SIZE];
   char *bundle_exe = NULL;
   char bundle_plist[MAX_STRING_SIZE];
   char bundle_pkginfo[MAX_STRING_SIZE];
   char bundle_icns[MAX_STRING_SIZE];
   char bundle_version[MAX_STRING_SIZE];
   char bundle_long_version[MAX_STRING_SIZE];
   char *buffer = NULL;
   int arg, type = 0, result = 0;
   int i, size, x, y, mask_bit, mask_byte;
   unsigned char *data;
   
   install_allegro(SYSTEM_NONE, &errno, &atexit);
   set_color_depth(32);
   set_color_conversion(COLORCONV_TOTAL | COLORCONV_KEEP_TRANS);
   
   if (argc < 2)
      usage();
   
   datafile[0] = '\0';
   bundle[0] = '\0';
   select_palette(black_palette);
   
   /* Parse command line and load any given resource */
   for (arg = 2; arg < argc; arg++) {
      if (!strcmp(argv[arg], "-m"))
         flags |= F_MOVE;
      else if (!strcmp(argv[arg], "-e"))
         flags |= F_EMBED_FRAMEWORK;
      else if (!strcmp(argv[arg], "-o")) {
         if ((argc < arg + 2) || (bundle[0] != '\0'))
	    usage();
	 strcpy(bundle, argv[++arg]);
      }
      else if (!strcmp(argv[arg], "-v")) {
         if (argc < arg + 2)
	    usage();
	 flags |= F_GOT_VERSION;
	 strcpy(bundle_version, argv[++arg]);
      }
      else if (!strcmp(argv[arg], "-V")) {
         if (argc < arg + 2)
	    usage();
	 flags |= F_GOT_LONG_VERSION;
	 strcpy(bundle_long_version, argv[++arg]);
      }
      else if (!strcmp(argv[arg], "-d")) {
         if (argc < arg + 2)
	    usage();
	 strcpy(datafile, argv[++arg]);
      }
      else if ((!strcmp(argv[arg], "-16")) || (!strcmp(argv[arg], "-32")) ||
               (!strcmp(argv[arg], "-48")) || (!strcmp(argv[arg], "-128"))) {
         if (argc < arg + 2)
	    usage();
	 switch (atoi(&argv[arg][1])) {
	    case 16: type = 0; break;
	    case 32: type = 1; break;
	    case 48: type = 2; break;
	    case 128: type = 3; break;
	 }
	 if (load_resource(datafile, argv[++arg], &icon_data[type])) {
	    result = -1;
	    goto exit_error;
	 }
      }
      else {
         if (load_resource(datafile, argv[arg], NULL)) {
	    result = -1;
	    goto exit_error;
	 }
      }
   }
   
   buffer = malloc(4096);
   if (!buffer) {
      result = -1;
      goto exit_error_bundle;
   }
   
   bundle_exe = argv[1];
   if (!exists(bundle_exe)) {
      fprintf(stderr, "Cannot locate executable file '%s'\n", bundle_exe);
      result = -1;
      goto exit_error;
   }
   if (bundle[0] == '\0')
      strcpy(bundle, bundle_exe);
   replace_extension(bundle_dir, bundle, "app", MAX_STRING_SIZE);
   strcpy(bundle_contents_dir, bundle_dir);
   strcat(bundle_contents_dir, "/Contents");
   strcpy(bundle_contents_resources_dir, bundle_contents_dir);
   strcat(bundle_contents_resources_dir, "/Resources");
   strcpy(bundle_contents_macos_dir, bundle_contents_dir);
   strcat(bundle_contents_macos_dir, "/MacOS");
   strcpy(bundle_contents_frameworks_dir, bundle_contents_dir);
   strcat(bundle_contents_frameworks_dir, "/Frameworks");
   bundle_icns[0] = '\0';
   bundle_plist[0] = '\0';
   bundle_pkginfo[0] = '\0';
   
   /* Create bundle structure */
   if ((mkdir(bundle_dir, 0777) && (errno != EEXIST)) ||
       (mkdir(bundle_contents_dir, 0777) && (errno != EEXIST)) ||
       (mkdir(bundle_contents_resources_dir, 0777) && (errno != EEXIST)) ||
       (mkdir(bundle_contents_macos_dir, 0777) && (errno != EEXIST))) {
      fprintf(stderr, "Cannot create %s\n", bundle_dir);
      result = -1;
      goto exit_error_bundle;
   }
   
   /* Copy/move executable into the bundle */
   if (copy_file(bundle_exe, bundle_contents_macos_dir)) {
      fprintf(stderr, "Cannot create %s\n", bundle_contents_macos_dir);
      result = -1;
      goto exit_error_bundle;
   }
   strcat(bundle_contents_macos_dir, "/");
   strcat(bundle_contents_macos_dir, get_filename(bundle_exe));
   chmod(bundle_contents_macos_dir, 0755);
   if (flags & F_MOVE)
      unlink(bundle_exe);
   
   /* Embed Allegro framework if requested */
   if (flags & F_EMBED_FRAMEWORK) {
      if (!file_exists("/Library/Frameworks/Allegro.framework", FA_RDONLY | FA_DIREC, NULL)) {
         fprintf(stderr, "Cannot find Allegro framework\n");
	 result = -1;
	 goto exit_error_bundle;
      }
      if (!exists("/Library/Frameworks/Allegro.framework/Resources/Embeddable")) {
         fprintf(stderr, "Cannot embed system wide Allegro framework; install embeddable version first!\n");
	 result = -1;
	 goto exit_error_bundle;
      }
      sprintf(buffer, "/Developer/Tools/pbxcp -exclude .DS_Store -exclude CVS -resolve-src-symlinks /Library/Frameworks/Allegro.framework %s", bundle_contents_frameworks_dir);
      if ((mkdir(bundle_contents_frameworks_dir, 0777) && (errno != EEXIST)) ||
	  (system(buffer))) {
         fprintf(stderr, "Cannot create %s\n", bundle_contents_frameworks_dir);
	 result = -1;
	 goto exit_error_bundle;
      }
   }
   
   /* Setup the .icns resource */
   if (flags & F_ICONS_DEFINED) {
      strcat(bundle_contents_resources_dir, "/");
      strcat(bundle_contents_resources_dir, get_filename(bundle));
      replace_extension(bundle_icns, bundle_contents_resources_dir, "icns", MAX_STRING_SIZE);
      
      icon_family = (IconFamilyHandle)NewHandle(0);
      
      for (i = 0; i < 4; i++) {
         if (flags & icon_data[i].defined) {
	    /* Set 32bit RGBA data */
	        raw_data = NewHandle(icon_data[i].size * icon_data[i].size * 4);
	    data = *(unsigned char **)raw_data;
	    for (y = 0; y < icon_data[i].size; y++) {
	       for (x = 0; x < icon_data[i].size; x++) {
	          *data++ = geta32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]);
	          *data++ = getr32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]);
	          *data++ = getg32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]);
	          *data++ = getb32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]);
	       }
	    }
	    if (SetIconFamilyData(icon_family, icon_data[i].data, raw_data) != noErr) {
               DisposeHandle(raw_data);
	       fprintf(stderr, "Error setting %dx%d icon resource RGBA data\n", icon_data[i].size, icon_data[i].size);
	       result = -1;
	       goto exit_error_bundle;
	    }
	    DisposeHandle(raw_data);
	    /* Set 8bit mask */
            raw_data = NewHandle(icon_data[i].size * icon_data[i].size);
	    data = *(unsigned char **)raw_data;
	    for (y = 0; y < icon_data[i].size; y++) {
	       for (x = 0; x < icon_data[i].size; x++) {
	          *data++ = geta32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]);
	       }
	    }
	    if (SetIconFamilyData(icon_family, icon_data[i].mask8, raw_data) != noErr) {
               DisposeHandle(raw_data);
	       fprintf(stderr, "Error setting %dx%d icon resource 8bit mask\n", icon_data[i].size, icon_data[i].size);
	       result = -1;
	       goto exit_error_bundle;
	    }
	    DisposeHandle(raw_data);
	    /* Set 1bit mask */
	    if (icon_data[i].mask1) {
	       size = ((icon_data[i].size * icon_data[i].size) + 7) / 8;
	       raw_data = NewHandle(size * 2);
	       data = *(unsigned char **)raw_data;
	       mask_byte = 0;
	       mask_bit = 7;
	       for (y = 0; y < icon_data[i].size; y++) {
	          for (x = 0; x < icon_data[i].size; x++) {
		     if (geta32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]) >= 0xfd)
		        mask_byte |= (1 << mask_bit);
		     mask_bit--;
		     if (mask_bit < 0) {
		        *data++ = mask_byte;
			mask_byte = 0;
			mask_bit = 7;
		     }
		  }
	       }
	       memcpy(*raw_data + size, *raw_data, size);
               if (SetIconFamilyData(icon_family, icon_data[i].mask1, raw_data) != noErr) {
                  DisposeHandle(raw_data);
	          fprintf(stderr, "Error setting %dx%d icon resource 1bit mask\n", icon_data[i].size, icon_data[i].size);
	          result = -1;
	          goto exit_error_bundle;
	       }
	       DisposeHandle(raw_data);
	    }
	 }
      }

      f = pack_fopen(bundle_icns, F_WRITE);
      if (!f) {
         fprintf(stderr, "Cannot create %s\n", bundle_icns);
	 result = -1;
	 goto exit_error_bundle;
      }
      pack_fclose(f);
      
      cf_url_ref = CFURLCreateWithBytes(kCFAllocatorDefault, (unsigned char *)bundle_icns, strlen(bundle_icns), 0, NULL);
      if (!cf_url_ref) {
         fprintf(stderr, "Cannot create %s\n", bundle_icns);
	 result = -1;
	 goto exit_error_bundle;
      }
      CFURLGetFSRef(cf_url_ref, &fs_ref);
      CFRelease(cf_url_ref);
      if ((FSGetCatalogInfo(&fs_ref, kFSCatInfoNone, NULL, NULL, &fs_spec, NULL)) || 
          (WriteIconFile(icon_family, &fs_spec) != noErr)) {
         fprintf(stderr, "Cannot create %s\n", bundle_icns);
	 result = -1;
	 goto exit_error_bundle;
      }
      DisposeHandle((Handle)icon_family);
   }
   
   /* Setup Info.plist */
   sprintf(bundle_plist, "%s/Info.plist", bundle_contents_dir);
   f = pack_fopen(bundle_plist, F_WRITE);
   if (!f) {
      fprintf(stderr, "Cannot create %s\n", bundle_plist);
      result = -1;
      goto exit_error_bundle;
   }
   sprintf(buffer, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
      "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
      "<plist version=\"1.0\">\n"
      "<dict>\n"
      "\t<key>CFBundleExecutable</key>\n"
      "\t<string>%s</string>\n"
      "\t<key>CFBundleInfoDictionaryVersion</key>\n"
      "\t<string>6.0</string>\n"
      "\t<key>CFBundlePackageType</key>\n"
      "\t<string>APPL</string>\n"
      "\t<key>CFBundleSignature</key>\n"
      "\t<string>%s</string>\n"
      "\t<key>CFBundleVersion</key>\n"
      "\t<string>%s</string>\n"
      "\t<key>CFBundleDocumentTypes</key>\n"
      "\t<array>\n"
      "\t\t<dict>\n"
      "\t\t\t<key>CFBundleTypeExtensions</key>\n"
      "\t\t\t<array>\n"
      "\t\t\t\t<string>*</string>\n"
      "\t\t\t</array>\n"
      "\t\t\t<key>CFBundleTypeName</key>\n"
      "\t\t\t<string>NSStringPboardType</string>\n"
      "\t\t\t<key>CFBundleTypeOSTypes</key>\n"
      "\t\t\t<array>\n"
      "\t\t\t\t<string>****</string>\n"
      "\t\t\t</array>\n"
      "\t\t\t<key>CFBundleTypeRole</key>\n"
      "\t\t\t<string>Viewer</string>\n"
      "\t\t</dict>\n"
      "\t</array>\n",
      get_filename(bundle_exe), "????", (flags & F_GOT_VERSION) ? bundle_version : "1.0");
   pack_fputs(buffer, f);
   if (flags & F_GOT_LONG_VERSION) {
      sprintf(buffer, "\t<key>CFBundleGetInfoString</key>\n"
         "\t<string>%s</string>\n", bundle_long_version);
      pack_fputs(buffer, f);
   }
   if (flags & F_ICONS_DEFINED) {
      sprintf(buffer, "\t<key>CFBundleIconFile</key>\n"
         "\t<string>%s</string>\n", get_filename(bundle_icns));
      pack_fputs(buffer, f);
   }
   pack_fputs("</dict>\n</plist>\n", f);
   pack_fclose(f);
   
   /* Setup PkgInfo */
   sprintf(bundle_pkginfo, "%s/PkgInfo", bundle_contents_dir);
   f = pack_fopen(bundle_pkginfo, F_WRITE);
   if (!f) {
      fprintf(stderr, "Cannot create %s\n", bundle_pkginfo);
      result = -1;
      goto exit_error_bundle;
   }
   pack_fputs("APPL????", f);
   pack_fclose(f);
   
exit_error:
   if (buffer)
      free(buffer);
   for (i = 0; i < 4; i++) {
      if (icon_data[i].original)
         destroy_bitmap(icon_data[i].original);
      if (icon_data[i].workspace)
         destroy_bitmap(icon_data[i].workspace);
      if (icon_data[i].scaled)
         destroy_bitmap(icon_data[i].scaled);
   }
   return result;

exit_error_bundle:
   sprintf(buffer, "%s/%s", bundle_contents_macos_dir, get_filename(bundle_exe));
   unlink(buffer);
   unlink(bundle_plist);
   unlink(bundle_pkginfo);
   unlink(bundle_icns);
   rmdir(bundle_dir);
   rmdir(bundle_contents_dir);
   rmdir(bundle_contents_resources_dir);
   rmdir(bundle_contents_macos_dir);
   goto exit_error;
}
Example #23
0
static void test_filter_graph(void)
{
    IFileSourceFilter *pfile = NULL;
    IBaseFilter *preader = NULL, *pavi = NULL;
    IEnumPins *enumpins = NULL;
    IPin *filepin = NULL, *avipin = NULL;
    HRESULT hr;
    HANDLE file = NULL;
    PIN_DIRECTION dir = PINDIR_OUTPUT;
    char buffer[13];
    DWORD readbytes;
    FILTER_STATE state;

    WCHAR *filename = load_resource(avifile);

    file = CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE,
        NULL, OPEN_EXISTING, 0, NULL);
    if (file == INVALID_HANDLE_VALUE)
    {
        skip("Could not read test file \"%s\", skipping test\n", wine_dbgstr_w(filename));
        DeleteFileW(filename);
        return;
    }

    memset(buffer, 0, 13);
    readbytes = 12;
    ReadFile(file, buffer, readbytes, &readbytes, NULL);
    CloseHandle(file);
    if (strncmp(buffer, "RIFF", 4) || strcmp(buffer + 8, "AVI "))
    {
        skip("%s is not an avi riff file, not doing the avi splitter test\n",
            wine_dbgstr_w(filename));
        DeleteFileW(filename);
        return;
    }

    hr = IUnknown_QueryInterface(pAviSplitter, &IID_IFileSourceFilter,
        (void **)&pfile);
    ok(hr == E_NOINTERFACE,
        "Avi splitter returns unexpected error: %08x\n", hr);
    if (pfile)
        IFileSourceFilter_Release(pfile);
    pfile = NULL;

    hr = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER,
        &IID_IBaseFilter, (LPVOID*)&preader);
    ok(hr == S_OK, "Could not create asynchronous reader: %08x\n", hr);
    if (hr != S_OK)
        goto fail;

    hr = IBaseFilter_QueryInterface(preader, &IID_IFileSourceFilter,
        (void**)&pfile);
    ok(hr == S_OK, "Could not get IFileSourceFilter: %08x\n", hr);
    if (hr != S_OK)
        goto fail;

    hr = IUnknown_QueryInterface(pAviSplitter, &IID_IBaseFilter,
        (void**)&pavi);
    ok(hr == S_OK, "Could not get base filter: %08x\n", hr);
    if (hr != S_OK)
        goto fail;

    hr = IFileSourceFilter_Load(pfile, filename, NULL);
    if (hr != S_OK)
    {
        trace("Could not load file: %08x\n", hr);
        goto fail;
    }

    hr = IBaseFilter_EnumPins(preader, &enumpins);
    ok(hr == S_OK, "No enumpins: %08x\n", hr);
    if (hr != S_OK)
        goto fail;

    hr = IEnumPins_Next(enumpins, 1, &filepin, NULL);
    ok(hr == S_OK, "No pin: %08x\n", hr);
    if (hr != S_OK)
        goto fail;

    IEnumPins_Release(enumpins);
    enumpins = NULL;

    hr = IBaseFilter_EnumPins(pavi, &enumpins);
    ok(hr == S_OK, "No enumpins: %08x\n", hr);
    if (hr != S_OK)
        goto fail;

    hr = IEnumPins_Next(enumpins, 1, &avipin, NULL);
    ok(hr == S_OK, "No pin: %08x\n", hr);
    if (hr != S_OK)
        goto fail;

    hr = IPin_Connect(filepin, avipin, NULL);
    ok(hr == S_OK, "Could not connect: %08x\n", hr);
    if (hr != S_OK)
        goto fail;

    IPin_Release(avipin);
    avipin = NULL;

    IEnumPins_Reset(enumpins);

    /* Windows puts the pins in the order: Outputpins - Inputpin,
     * wine does the reverse, just don't test it for now
     * Hate to admit it, but windows way makes more sense
     */
    while (IEnumPins_Next(enumpins, 1, &avipin, NULL) == S_OK)
    {
        IPin_QueryDirection(avipin, &dir);
        if (dir == PINDIR_OUTPUT)
        {
            /* Well, connect it to a null renderer! */
            IBaseFilter *pnull = NULL;
            IEnumPins *nullenum = NULL;
            IPin *nullpin = NULL;

            hr = CoCreateInstance(&CLSID_NullRenderer, NULL,
                CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&pnull);
            if (hr == REGDB_E_CLASSNOTREG)
            {
                win_skip("Null renderer not registered, skipping\n");
                break;
            }
            ok(hr == S_OK, "Could not create null renderer: %08x\n", hr);

            hr = IBaseFilter_EnumPins(pnull, &nullenum);
            ok(hr == S_OK, "Failed to enum pins, hr %#x.\n", hr);
            hr = IEnumPins_Next(nullenum, 1, &nullpin, NULL);
            ok(hr == S_OK, "Failed to get next pin, hr %#x.\n", hr);
            IEnumPins_Release(nullenum);
            IPin_QueryDirection(nullpin, &dir);

            hr = IPin_Connect(avipin, nullpin, NULL);
            ok(hr == S_OK, "Failed to connect output pin: %08x\n", hr);
            IPin_Release(nullpin);
            if (hr != S_OK)
            {
                IBaseFilter_Release(pnull);
                break;
            }
            IBaseFilter_Run(pnull, 0);
        }

        IPin_Release(avipin);
        avipin = NULL;
    }

    if (avipin)
        IPin_Release(avipin);
    avipin = NULL;

    if (hr != S_OK)
        goto fail2;
    /* At this point there is a minimalistic connected avi splitter that can
     * be used for all sorts of source filter tests. However that still needs
     * to be written at a later time.
     *
     * Interesting tests:
     * - Can you disconnect an output pin while running?
     *   Expecting: Yes
     * - Can you disconnect the pullpin while running?
     *   Expecting: No
     * - Is the reference count incremented during playback or when connected?
     *   Does this happen once for every output pin? Or is there something else
     *   going on.
     *   Expecting: You tell me
     */

    IBaseFilter_Run(preader, 0);
    IBaseFilter_Run(pavi, 0);
    IBaseFilter_GetState(pavi, INFINITE, &state);

    IBaseFilter_Pause(pavi);
    IBaseFilter_Pause(preader);
    IBaseFilter_Stop(pavi);
    IBaseFilter_Stop(preader);
    IBaseFilter_GetState(pavi, INFINITE, &state);
    IBaseFilter_GetState(preader, INFINITE, &state);

fail2:
    IEnumPins_Reset(enumpins);
    while (IEnumPins_Next(enumpins, 1, &avipin, NULL) == S_OK)
    {
        IPin *to = NULL;

        IPin_QueryDirection(avipin, &dir);
        IPin_ConnectedTo(avipin, &to);
        if (to)
        {
            IPin_Release(to);

            if (dir == PINDIR_OUTPUT)
            {
                PIN_INFO info;

                hr = IPin_QueryPinInfo(to, &info);
                ok(hr == S_OK, "Failed to query pin info, hr %#x.\n", hr);

                /* Release twice: Once normal, second from the
                 * previous while loop
                 */
                IBaseFilter_Stop(info.pFilter);
                IPin_Disconnect(to);
                IPin_Disconnect(avipin);
                IBaseFilter_Release(info.pFilter);
                IBaseFilter_Release(info.pFilter);
            }
            else
            {
                IPin_Disconnect(to);
                IPin_Disconnect(avipin);
            }
        }
        IPin_Release(avipin);
        avipin = NULL;
    }

fail:
    if (hr != S_OK)
        skip("Prerequisites not matched, skipping remainder of test\n");
    if (enumpins)
        IEnumPins_Release(enumpins);

    if (avipin)
        IPin_Release(avipin);
    if (filepin)
    {
        IPin *to = NULL;

        IPin_ConnectedTo(filepin, &to);
        if (to)
        {
            IPin_Disconnect(filepin);
            IPin_Disconnect(to);
        }
        IPin_Release(filepin);
    }

    if (preader)
        IBaseFilter_Release(preader);
    if (pavi)
        IBaseFilter_Release(pavi);
    if (pfile)
        IFileSourceFilter_Release(pfile);

    DeleteFileW(filename);
}
Example #24
0
bool lens_flare::init(const nya_scene::texture_proxy &color, const nya_scene::texture_proxy &depth)
{
    assert(depth.is_valid());

    nya_memory::tmp_buffer_scoped res(load_resource("PostProcess/LensParam.bin"));
    if (!res.get_data())
        return false;

    params::memory_reader reader(res.get_data(), res.get_size());

    for (int i = 0; i < 16; ++i)
    {
        lens[i].position = reader.read<float>();
        lens[i].radius = reader.read<float>();
        lens[i].color = reader.read_color3_uint();
    }

    star_radius = reader.read<float>();
    star_color = reader.read_color3_uint();

    glow_radius = reader.read<float>();
    glow_color = reader.read_color3_uint();

    ring_specular = reader.read<float>();
    ring_shiness = reader.read<float>();
    ring_radius = reader.read<float>();

    f_min = reader.read<float>();
    f_max = reader.read<float>();
    aberration = reader.read<float>();

    auto texture = shared::get_texture(shared::load_texture("PostProcess/lens.nut"));
    auto tex_data = texture.internal().get_shared_data();
    if (!tex_data.is_valid())
        return false;

    nya_render::texture tex = tex_data->tex;
    tex.set_wrap(nya_render::texture::wrap_repeat_mirror, nya_render::texture::wrap_repeat_mirror);
    auto &pass = m_material.get_pass(m_material.add_pass(nya_scene::material::default_pass));
    pass.set_shader(nya_scene::shader("shaders/lens_flare.nsh"));
    pass.get_state().set_cull_face(false);
    pass.get_state().set_blend(true, nya_render::blend::src_alpha, nya_render::blend::inv_src_alpha);
    //pass.get_state().set_blend(true, nya_render::blend::src_alpha, nya_render::blend::one);
    pass.get_state().zwrite=false;
    pass.get_state().depth_test=false;
    m_material.set_texture("diffuse", texture);
    m_material.set_texture("color", color);
    m_material.set_texture("depth", depth);

    struct vert
    {
        nya_math::vec2 pos;
        float dist;
        float radius;
        nya_math::vec3 color;
        float special;
    };

    vert verts[(16+1)*6];

    for (int i = 0; i < 16; ++i)
    {
        vert *v = &verts[i * 6];

        v[0].pos = nya_math::vec2( -1.0f, -1.0f );
        v[1].pos = nya_math::vec2( -1.0f,  1.0f );
        v[2].pos = nya_math::vec2(  1.0f,  1.0f );
        v[3].pos = nya_math::vec2( -1.0f, -1.0f );
        v[4].pos = nya_math::vec2(  1.0f,  1.0f );
        v[5].pos = nya_math::vec2(  1.0f, -1.0f );

        for (int t = 0; t < 6; ++t)
        {
            if (i>0)
            {
                auto &l = lens[i-1];
                v[t].dist = l.position;
                v[t].radius = l.radius;
                v[t].color = l.color;
                v[t].special = 0.0;
            }
            else
            {
                v[t].dist = 1.0;
                v[t].radius = 0.2;
                v[t].color = nya_math::vec3(1.0, 1.0, 1.0);
                v[t].special = 1.0;
            }
        }
    }

    if (!m_mesh.is_valid())
        m_mesh.create();

    m_mesh->set_vertex_data(verts, uint32_t(sizeof(vert)), uint32_t(sizeof(verts) / sizeof(verts[0])));
    m_mesh->set_vertices(0, 4);
    m_mesh->set_tc(0, 16, 4);

    if (!m_dir_alpha.is_valid())
        m_dir_alpha.create();
    m_material.set_param(m_material.get_param_idx("light dir"), m_dir_alpha);

    return true;
}
Example #25
0
uint STDCALL ge_load( pbuf in )
{
   pubyte   cur, end, ptemp;
   uint     size;
   pgehead  phead = ( pgehead )buf_ptr( in );

   // Проверка заголовка и целостности
   // Сравниваем с 'GE' с двумя нулями на конце

   if ( *( puint )phead != GE_STRING )//0x00004547 )
      msg( MNotGE | MSG_EXIT );
   if ( phead->crc != crc( ( pubyte )phead + 12, phead->size - 12, 0xFFFFFFFF ))
      msg( MCrcGE | MSG_EXIT );
   if ( phead->vermajor != GEVER_MAJOR || phead->verminor > GEVER_MINOR )
      msg( MVerGE | MSG_EXIT );

   _vm.loadmode = VMLOAD_GE;
   _vm.icnv = arr_count( &_vm.objtbl ) - KERNEL_COUNT;
//   print("icnv=%i\n", _vm.icnv );
   cur = ( pubyte )phead + phead->headsize;
   end = ( pubyte )phead + phead->size;
   while ( cur < end )
   {
      ptemp = cur + 5; // type + flag
      _vm.ipack = ( *( puint )( cur + 1 )) & GHCOM_PACK ? 1 : 0;

      size = load_bwd( &ptemp );
      ptemp = cur;
//      print("size=%i type=%i flag = %x\n", size, *cur, *( puint )( cur + 1 ) );
      switch ( *cur )
      {
         case OVM_NONE:
            load_none();
            break;
         case OVM_BYTECODE:
            load_bytecode( &cur, VMLOAD_GE );
            break;
         case OVM_EXFUNC:
            load_exfunc( &cur, 0 );
            _vm.loadmode = VMLOAD_GE;
            break;
        case OVM_TYPE:
            load_type( &cur );
            break;
        case OVM_GLOBAL:
            load_global( &cur );
            break;
        case OVM_DEFINE:
            load_define( &cur );
            break;
        case OVM_IMPORT:
            load_import( &cur );
            break;
         case OVM_RESOURCE:
            load_resource( &cur );
            break;
         case OVM_ALIAS:
            load_alias( &cur );
            break;
         default: 
            msg( MUnkGE | MSG_DVAL, cur - ( pubyte )phead );
      }
      cur = ptemp + size;
   }
   _vm.loadmode = VMLOAD_G;
   _vm.icnv  = 0;
   return 1;
}
Example #26
0
bool effect_clouds::load(const char *location_name, const location_params &params)
{
    if (!location_name)
        return false;

    const bool result = read_bdd((std::string("Effect/") + location_name + "/cloud_" + location_name + ".BDD").c_str(), m_clouds);
    if (!result)
        return false;

    std::vector<vert> verts;

    for (int i = 1; i <= 4; ++i)
    {
        if (i!=2) continue; //ToDo

        for (char j = 'A'; j <= 'E'; ++j)
        {
            m_obj_levels.resize(m_obj_levels.size() + 1);

            char buf[512];
            sprintf(buf, "Effect/%s/ObjCloud/Level%d_%c.BOC", location_name, i, j);

            nya_memory::tmp_buffer_scoped res(load_resource(buf));
            assert(res.get_size() > 0);
            nya_memory::memory_reader reader(res.get_data(), res.get_size());

            level_header header = reader.read<level_header>();
            auto &l = m_obj_levels.back();
            l.height = header.height;
            l.offset = (uint32_t)verts.size();
            l.count = header.count * 6;
            verts.resize(l.offset + l.count);
            for (int k = 0; k < header.count; ++k)
            {
                level_entry e = reader.read<level_entry>();
                m_obj_levels.back().entries.push_back(e);

                vert *v = &verts[l.offset + k * 6];

                v[0].dir = nya_math::vec2( -1.0f, -1.0f );
                v[1].dir = nya_math::vec2( -1.0f,  1.0f );
                v[2].dir = nya_math::vec2(  1.0f,  1.0f );
                v[3].dir = nya_math::vec2( -1.0f, -1.0f );
                v[4].dir = nya_math::vec2(  1.0f,  1.0f );
                v[5].dir = nya_math::vec2(  1.0f, -1.0f );

                for (int t = 0; t < 6; ++t)
                {
                    v[t].pos = e.pos;
                    v[t].size.x = e.size;// * 2.0f;
                    v[t].size.y = e.size;// * 2.0f;

                    auto tc=v[t].dir * 0.5f;
                    tc.x += 0.5f, tc.y += 0.5f;
                    tc.y = 1.0 - tc.y;

                    v[t].tc.x = tc.x * e.tc[2] + e.tc[0]; //main
                    v[t].tc.y = tc.y * e.tc[2] + e.tc[1];

                    const float weird_detail_tc_multiply = 0.01f;

                    v[t].tc.z = (tc.x * e.tc[5] + 0.5f) * weird_detail_tc_multiply + e.tc[3]; //detail
                    v[t].tc.w = (tc.y * e.tc[5] + 0.5f) * weird_detail_tc_multiply + e.tc[4];
                }
            }
        }
    }

    m_hi_flat_offset = (uint32_t)verts.size();
    m_hi_flat_count = int(m_clouds.hiflat_clouds.size()) * 6;
    verts.resize(m_hi_flat_offset+ m_hi_flat_count);
    for (int k = 0; k < int(m_clouds.hiflat_clouds.size()); ++k)
    {
        auto &p = m_clouds.hiflat_clouds[k];

        vert *v = &verts[m_hi_flat_offset + k * 6];

        v[0].dir = nya_math::vec2( -1.0f, -1.0f );
        v[1].dir = nya_math::vec2( -1.0f,  1.0f );
        v[2].dir = nya_math::vec2(  1.0f,  1.0f );
        v[3].dir = nya_math::vec2( -1.0f, -1.0f );
        v[4].dir = nya_math::vec2(  1.0f,  1.0f );
        v[5].dir = nya_math::vec2(  1.0f, -1.0f );

        for (int t = 0; t < 6; ++t)
        {
            v[t].pos.x = p.x;
            v[t].pos.z = p.y;

            auto tc=v[t].dir * 0.5f;
            tc.x += 0.5f, tc.y += 0.5f;
            //tc.y = 1.0 - tc.y;

            //ToDo

            nya_math::vec4 uv_param(0.0,0.75,0.25,0.25);

            v[t].tc.x = tc.x * uv_param.z + uv_param.x;
            v[t].tc.y = tc.y * uv_param.w + uv_param.y;

            v[t].tc.x += uv_param.z * (k % 4); //ToDo
        }
    }

    m_mesh.set_vertex_data(&verts[0], uint32_t(sizeof(verts[0])), uint32_t(verts.size()));
    m_mesh.set_vertices(0, 3);
    m_mesh.set_tc(0, 12, 4); //tc1, tc2
    m_mesh.set_tc(1, 12+16, 4); //dir, size

    m_shader_obj.load("shaders/clouds.nsh");
    m_shader_hi_flat.load("shaders/clouds_hi_flat.nsh");
    m_obj_tex = shared::get_texture(shared::load_texture((std::string("Effect/") + location_name + "/ObjCloud.nut").c_str()));
    m_flat_tex = shared::get_texture(shared::load_texture((std::string("Effect/") + location_name + "/FlatCloud.nut").c_str()));

    for (int i = 0; i < m_shader_obj.internal().get_uniforms_count(); ++i)
    {
        auto &name = m_shader_obj.internal().get_uniform(i).name;
        if (name == "pos")
            m_shader_pos = i;

        //else if (name == "fade_farnear")
        //    m_shader_obj.internal().set_uniform_value(i, params.cloud.far_fade_far, params.cloud.far_fade_near, 0.0f, 0.0f);
        else if (name == "obj upper lower")
            m_shader_obj.internal().set_uniform_value(i, params.cloud.ambient_obj_upper, params.cloud.ambient_obj_lower, 0.0f, 0.0f);
        else if (name == "amb low")
        {
            auto amb = params.cloud.ambient_lower_color / 255.0f * params.cloud.ambient_power * params.cloud.intensity;
            m_shader_obj.internal().set_uniform_value(i, amb.x, amb.y, amb.z, 0.0f);
        }
        else if (name == "amb up")
        {
            auto amb = params.cloud.ambient_upper_color / 255.0f * params.cloud.ambient_power * params.cloud.intensity;
            m_shader_obj.internal().set_uniform_value(i, amb.x, amb.y, amb.z, 0.0f);
        }
        else if (name == "diff")
        {
            auto diff = params.cloud.diffuse_color / 255.0f * params.cloud.diffuse_power * params.cloud.intensity;
            m_shader_obj.internal().set_uniform_value(i, diff.x, diff.y, diff.z, 0.0f);
        }
        else if (name == "diffuse min")
            m_shader_obj.internal().set_uniform_value(i, params.cloud.diffuse_min, 0.0f, 0.0f, 0.0f);
        else if(name == "sprite light dir")
            m_shader_obj.internal().set_uniform_value(i, -params.sky.sun_dir.x, -params.sky.sun_dir.y, -params.sky.sun_dir.z, 0.0f);
    }


    for (int i = 0; i < m_shader_hi_flat.internal().get_uniforms_count(); ++i)
    {
        auto &name = m_shader_hi_flat.internal().get_uniform(i).name;
        if (name == "color")
            m_shader_hi_flat.internal().set_uniform_value(i, 1.0f, 1.0f, 1.0f, params.cloud.highflat_alpha / 255.0f);
    }

    m_dist_sort.resize(m_clouds.obj_clouds.size());

    return true;
}