bool UIImage::initWithContentsOfFile(const string &strPath, eImageFormat imageType)
{
	bool bRet = false;

	switch (imageType)
	{
	case kCCImageFormatPNG:
		// use libpng load image
		bRet =  loadPng(strPath.c_str());
		break;
	case kCCImageFormatJPG:
		bRet = loadJpg(strPath.c_str());
		break;
	default:
		// unsupported image type
		bRet = false;
		break;
	}

	if (!bRet && s_bPopupNotify)
	{
		// notify the loading error
		std::string strErr = "Load ";
		strErr += strPath;
		strErr += " failed!";
		std::wstring wsErr(strErr.length(), L'');
		std::copy(strErr.begin(), strErr.end(), wsErr.begin());
		MessageBox(NULL, wsErr.c_str(), L"cocos2d-x error", MB_OK);  
	}

	return bRet;
}
示例#2
0
void loadPng(GImage* pImage, const char* szFilename)
{
	size_t nSize;
	char* pRawData = GFile::loadFile(szFilename, &nSize);
	ArrayHolder<char> hRawData(pRawData);
	loadPng(pImage, (const unsigned char*)pRawData, nSize);
}
示例#3
0
std::unique_ptr<uint8[]> loadLdr(const Path &path, TexelConversion request, int &w, int &h, bool gammaCorrect)
{
    int channels;
    DeletablePixels img(makeVoidPixels());
    if (path.testExtension("png"))
        img = loadPng(path, w, h, channels);
    else
        img = loadStbi(path, w, h, channels);

    if (!img)
        return nullptr;

    int targetChannels = (request == TexelConversion::REQUEST_RGB) ? 4 : 1;

    std::unique_ptr<uint8[]> texels(new uint8[w*h*targetChannels]);
    if (targetChannels == 4) {
        std::memcpy(texels.get(), img.get(), w*h*targetChannels*sizeof(uint8));

        if (gammaCorrect)
            for (int i = 0; i < w*h; ++i)
                for (int t = 0; t < 3; ++t)
                    texels[i*4 + t] = GammaCorrection[texels[i*4 + t]];
    } else {
        for (int i = 0; i < w*h; ++i)
            texels[i] = convertToScalar(request, int(img[i*4]), int(img[i*4 + 1]), int(img[i*4 + 2]),
                int(img[i*4 + 3]), channels == 4);
    }

    return std::move(texels);
}
示例#4
0
void loadPngFromHex(GImage* pImage, const char* szHex)
{
	size_t len = strlen(szHex);
	unsigned char* pBuf = new unsigned char[len / 2];
	ArrayHolder<unsigned char> hBuf(pBuf);
	GBits::hexToBuffer(szHex, len, pBuf);
	loadPng(pImage, pBuf, len / 2);
}
示例#5
0
APNGDATA * LoadAPNG_from_file( const wchar_t * pszFileName )
{
    FILE *f = _wfopen(pszFileName,L"rb");
    if(!f) return NULL;
    IPngReader_File file(f);
    APNGDATA *pRet = loadPng(&file);
    fclose(f);
    return pRet;
}
示例#6
0
文件: png.c 项目: tversteeg/rogueliek
static int l_loadPng(lua_State *lua)
{
	const char *file = luaL_checkstring(lua, 1);
	const char *name = luaL_checkstring(lua, 2);
	
	loadPng(file, name);

	return 0;
}
示例#7
0
int main(int argc, char *argv[])
{
	HDRImage texture;
	HDRImage collision;
	std::cout<<"Loading images...";
	if(!loadPng("data/mariotexture.png", texture) ||
	   !loadPng("data/mariocollision.png", collision))
	{
		std::cerr<<"failed :("<<std::endl;
		return -1;
	}
	std::cout<<"done!"<<std::endl;

	// Create a lightbuffer and add an ambient light
	HDRImage lightbuffer(texture.width, texture.height);
	lightbuffer.clear(vec3(32.0f));

	// Simulate photon distribution into a lightbuffer
	int photonCount = 1000000;
	vec3 lightColor = vec3(1.0f, 0.9f, 0.9f);
	simulate(texture, collision, lightbuffer, photonCount, lightColor);

	// Multiplicatively blend texture with lightbuffer
	HDRImage result(texture.width, texture.height);
	for(int i = 0; i < texture.width * texture.height; ++i)
	{
		vec3 tex = texture.pixels[i];
		vec3 light = lightbuffer.pixels[i];
		result.pixels[i] = tex * light;
	}

	applyTonemap(result);
	//applyTonemap(lightbuffer);

	std::cout<<"Saving image...";
	savePng("data/texturepp.png", result);
	std::cout<<"done!\n";

	std::cin.get();
	return 0;
}
示例#8
0
bool loadPng(const wchar_t* pNameFile, ImageBase** ppImage)
{
	if (!(pNameFile && ppImage && !*ppImage)) return false;

	FILE* pFile = ::_wfopen(pNameFile, L"rb");
	if (!pFile) return false;

	bool result = loadPng(pFile, ppImage);
	::fclose(pFile);

	return result;
}
示例#9
0
int SliceMngr::loadSlice(const char *pFilename){
  if (loadPng(&(mImage.image), pFilename) == false){
    printf("failed to load\n");
    return -1;
  }else{
    vc_dispmanx_resource_write_data(mImage.resource,
                                    mImage.image.type,
                                    mImage.image.pitch,
                                    mImage.image.buffer,
                                    &(mImage.dstRect));
  }
  return 0;
}
示例#10
0
Image *ImageHelper::load(SDL_RWops *const rw)
{
    SDL_Surface *const tmpImage = loadPng(rw);
    if (!tmpImage)
    {
        logger->log("Error, image load failed: %s", IMG_GetError());
        return nullptr;
    }

    Image *const image = loadSurface(tmpImage);

    MSDL_FreeSurface(tmpImage);
    return image;
}
示例#11
0
文件: main.c 项目: nevik-xx/psl1ght
s32 main(s32 argc, const char* argv[])
{
	PadInfo padinfo;
	PadData paddata;
	int i;
	
	atexit(appCleanup);
	init_screen();
	ioPadInit(7);
	sysRegisterCallback(EVENT_SLOT0, eventHandle, NULL);

	// Load texture
	dice = loadPng(dice_bin);
	assert(realityAddressToOffset(dice.data, &tx_offset) == 0);

	//load_acid_texture((uint8_t *)tx_mem, 0);

	// install fragment shader in rsx memory
	u32 *frag_mem = rsxMemAlign(256, 256);
	printf("frag_mem = 0x%08lx\n", (u64) frag_mem);
	realityInstallFragmentProgram_old(context, &nv30_fp, frag_mem);

	long frame = 0; // To keep track of how many frames we have rendered.
	
	// Ok, everything is setup. Now for the main loop.
	while(1){
		// Check the pads.
		ioPadGetInfo(&padinfo);
		for(i=0; i<MAX_PADS; i++){
			if(padinfo.status[i]){
				ioPadGetData(i, &paddata);
				
				if(paddata.BTN_CROSS || paddata.BTN_START){
					return 0;
				}
			}
			
		}

		waitFlip(); // Wait for the last flip to finish, so we can draw to the old buffer
		drawFrame(currentBuffer, frame++); // Draw into the unused buffer
		flip(currentBuffer); // Flip buffer onto screen
		currentBuffer = !currentBuffer;
		sysCheckCallback();

	}
	
	return 0;
}
示例#12
0
Image *OpenGLImageHelper::load(SDL_RWops *const rw, Dye const &dye)
{
    SDL_Surface *const tmpImage = loadPng(rw);
    if (!tmpImage)
    {
        reportAlways("Error, image load failed: %s", IMG_GetError());
        return nullptr;
    }

    SDL_Surface *const surf = convertTo32Bit(tmpImage);
    MSDL_FreeSurface(tmpImage);
    if (!surf)
        return nullptr;

    uint32_t *pixels = static_cast<uint32_t *>(surf->pixels);
    const int type = dye.getType();

    switch (type)
    {
        case 1:
        {
            const DyePalette *const pal = dye.getSPalete();
            if (pal)
                pal->replaceSOGLColor(pixels, surf->w * surf->h);
            break;
        }
        case 2:
        {
            const DyePalette *const pal = dye.getAPalete();
            if (pal)
                pal->replaceAOGLColor(pixels, surf->w * surf->h);
            break;
        }
        case 0:
        default:
        {
            dye.normalOGLDye(pixels, surf->w * surf->h);
            break;
        }
    }

    Image *const image = loadSurface(surf);
    MSDL_FreeSurface(surf);
    return image;
}
示例#13
0
bool Bitmap::loadData(const uint8_t * data, size_t dataLen, const StrideFn &strideFn) {
	bool ret = false;
	if (isPng(data, dataLen)) {
#ifndef NOPNG
		if (loadPng(data, dataLen, _data, _color, _alpha, _width, _height, _stride, strideFn)) {
			ret = true;
		}
#endif
	} else if (isJpg(data, dataLen)) {
#ifndef NOJPEG
		if (loadJpg(data, dataLen, _data, _color, _alpha, _width, _height, _stride, strideFn)) {
			ret = true;
		}
#endif
	} /* else if (isWebp(data, dataLen)) {
		if (loadWebp(data, dataLen, _data, _color, _alpha, _width, _height)) {
			ret = true;
		}
	} */
	return ret;
}
示例#14
0
bool CTexture::Load(char *path){
	FILE* fp;
	fopen_s(&fp,path, "rb");
	if(!fp) {
		printf("ファイルが読み込めません[%s]",path);
		m_bufID=0;
		return false;
	}
	unsigned char crc[4];
	fread(crc,4,1,fp);
	if(crc[0]==0x42 && crc[1]==0x4D) {
		fclose(fp);
		return loadBmp(path);
	}else {
//	if(crc[1]==0x50 && crc[2]==0x4E && crc[3]==0x47) {
		fclose(fp);
		return loadPng(path);
	}
	
	
}
示例#15
0
int main(int argc, char *argv[])
{
    uint16_t background = 0x000F;
    int32_t layer = 1;
    uint32_t displayNumber = 0;
    int32_t xOffset = 0;
    int32_t yOffset = 0;
    uint32_t timeout = 0;
    bool xOffsetSet = false;
    bool yOffsetSet = false;
    bool interactive = true;

    program = basename(argv[0]);

    //---------------------------------------------------------------------

    int opt = 0;

    while ((opt = getopt(argc, argv, "b:d:l:x:y:t:n")) != -1)
    {
        switch(opt)
        {
        case 'b':

            background = strtol(optarg, NULL, 16);
            break;

        case 'd':

            displayNumber = strtol(optarg, NULL, 10);
            break;

        case 'l':

            layer = strtol(optarg, NULL, 10);
            break;

        case 'x':

            xOffset = strtol(optarg, NULL, 10);
            xOffsetSet = true;
            break;

        case 'y':

            yOffset = strtol(optarg, NULL, 10);
            yOffsetSet = true;
            break;
        
        case 't':

            timeout = atoi(optarg);
            break;

        case 'n':

            interactive = false;
            break;

        default:

            usage();
            break;
        }
    }

    //---------------------------------------------------------------------

    if (optind >= argc)
    {
        usage();
    }

    //---------------------------------------------------------------------

    IMAGE_LAYER_T imageLayer;

    const char *imagePath = argv[optind];

    if(strcmp(imagePath, "-") == 0)
    {
        // Use stdin
        if (loadPngFile(&(imageLayer.image), stdin) == false)
        {
            fprintf(stderr, "unable to load %s\n", imagePath);
            exit(EXIT_FAILURE);
        }
    }
    else
    {
        // Load image from path
        if (loadPng(&(imageLayer.image), imagePath) == false)
        {
            fprintf(stderr, "unable to load %s\n", imagePath);
            exit(EXIT_FAILURE);
        }
    }

    //---------------------------------------------------------------------

    if (signal(SIGINT, signalHandler) == SIG_ERR)
    {
        perror("installing SIGINT signal handler");
        exit(EXIT_FAILURE);
    }

    //---------------------------------------------------------------------

    if (signal(SIGTERM, signalHandler) == SIG_ERR)
    {
        perror("installing SIGTERM signal handler");
        exit(EXIT_FAILURE);
    }

    //---------------------------------------------------------------------

    bcm_host_init();

    //---------------------------------------------------------------------

    DISPMANX_DISPLAY_HANDLE_T display
        = vc_dispmanx_display_open(displayNumber);
    assert(display != 0);

    //---------------------------------------------------------------------

    DISPMANX_MODEINFO_T info;
    int result = vc_dispmanx_display_get_info(display, &info);
    assert(result == 0);

    //---------------------------------------------------------------------

    BACKGROUND_LAYER_T backgroundLayer;

    if (background > 0)
    {
        initBackgroundLayer(&backgroundLayer, background, 0);
    }

    createResourceImageLayer(&imageLayer, layer);

    //---------------------------------------------------------------------

    DISPMANX_UPDATE_HANDLE_T update = vc_dispmanx_update_start(0);
    assert(update != 0);

    if (background > 0)
    {
        addElementBackgroundLayer(&backgroundLayer, display, update);
    }

    if (xOffsetSet == false)
    {
        xOffset = (info.width - imageLayer.image.width) / 2;
    }

    if (yOffsetSet == false)
    {
        yOffset = (info.height - imageLayer.image.height) / 2;
    }

    addElementImageLayerOffset(&imageLayer,
                               xOffset,
                               yOffset,
                               display,
                               update);

    result = vc_dispmanx_update_submit_sync(update);
    assert(result == 0);

    //---------------------------------------------------------------------

    int32_t step = 1;
    uint32_t currentTime = 0;

    // Sleep for 10 milliseconds every run-loop
    const int sleepMilliseconds = 10;

    while (run)
    {
        int c = 0;
        if (interactive && keyPressed(&c))
        {
            c = tolower(c);

            bool moveLayer = false;

            switch (c)
            {
            case 27:

                run = false;
                break;

            case 'a':

                xOffset -= step;
                moveLayer = true;
                break;

            case 'd':

                xOffset += step;
                moveLayer = true;
                break;

            case 'w':

                yOffset -= step;
                moveLayer = true;
                break;

            case 's':

                yOffset += step;
                moveLayer = true;
                break;

            case '+':

                if (step == 1)
                {
                    step = 5;
                }
                else if (step == 5)
                {
                    step = 10;
                }
                else if (step == 10)
                {
                    step = 20;
                }
                break;

            case '-':

                if (step == 20)
                {
                    step = 10;
                }
                else if (step == 10)
                {
                    step = 5;
                }
                else if (step == 5)
                {
                    step = 1;
                }
                break;
            }

            if (moveLayer)
            {
                update = vc_dispmanx_update_start(0);
                assert(update != 0);

                moveImageLayer(&imageLayer, xOffset, yOffset, update);

                result = vc_dispmanx_update_submit_sync(update);
                assert(result == 0);
            }
        }

        //---------------------------------------------------------------------

        usleep(sleepMilliseconds * 1000);

        currentTime += sleepMilliseconds;
        if (timeout != 0 && currentTime >= timeout) {
            run = false;
        }
    }

    //---------------------------------------------------------------------

    keyboardReset();

    //---------------------------------------------------------------------

    if (background > 0)
    {
        destroyBackgroundLayer(&backgroundLayer);
    }

    destroyImageLayer(&imageLayer);

    //---------------------------------------------------------------------

    result = vc_dispmanx_display_close(display);
    assert(result == 0);

    //---------------------------------------------------------------------

    return 0;
}
示例#16
0
APNGDATA * LoadAPNG_from_memory(const char * pBuf, size_t nLen )
{
    IPngReader_Mem mem(pBuf,nLen);
    return loadPng(&mem);
}
示例#17
0
文件: main.c 项目: Darkhacker/DeadRSX
void loading() {
// where all are loading going be done :D
	sprite_image = loadPng(sprite_bin);
	assert(realityAddressToOffset(sprite_image.data, &sprite_offset) == 0); 
}
示例#18
0
    if (!tmpImage)
    {
        logger->log("Error, image load failed: %s", IMG_GetError());
        return nullptr;
    }

    Image *const image = loadSurface(tmpImage);

    MSDL_FreeSurface(tmpImage);
    return image;
}

Image *ImageHelper::load(SDL_RWops *const rw, Dye const &dye)
{
    BLOCK_START("ImageHelper::load")
    SDL_Surface *const tmpImage = loadPng(rw);
    if (!tmpImage)
    {
        logger->log("Error, image load failed: %s", IMG_GetError());
        BLOCK_END("ImageHelper::load")
        return nullptr;
    }

    SDL_PixelFormat rgba;
    rgba.palette = nullptr;
    rgba.BitsPerPixel = 32;
    rgba.BytesPerPixel = 4;

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    rgba.Rmask = 0x000000FF;
    rgba.Gmask = 0x0000FF00;
示例#19
0
bool UrlValue::loadImg(UrlValue_Img &img) const {
  return loadPng(img) || loadJpeg(img);
}
示例#20
0
void
rsxgltest_init(int argc,const char ** argv)
{
  tcp_printf("%s\n",__PRETTY_FUNCTION__);

  // Set up us the program:
  shaders[0] = glCreateShader(GL_VERTEX_SHADER);
  shaders[1] = glCreateShader(GL_FRAGMENT_SHADER);

  program = glCreateProgram();

  glAttachShader(program,shaders[0]);
  glAttachShader(program,shaders[1]);

  // Supply shader binaries:
  glShaderBinary(1,shaders,0,textures_vpo,textures_vpo_size);
  glShaderBinary(1,shaders + 1,0,textures_fpo,textures_fpo_size);

  // Link the program for real:
  glLinkProgram(program);
  glValidateProgram(program);

  GLint
    vertex_location = glGetAttribLocation(program,"vertex"),
    texcoord_location = glGetAttribLocation(program,"texcoord");
  tcp_printf("vertex_location: %i\n",vertex_location);
  tcp_printf("texcoord_location: %i\n",texcoord_location);

  ProjMatrix_location = glGetUniformLocation(program,"ProjMatrix");
  TransMatrix_location = glGetUniformLocation(program,"TransMatrix");
  c_location = glGetUniformLocation(program,"c");
  texture_location = glGetUniformLocation(program,"texture");
  tcp_printf("ProjMatrix_location: %i TransMatrix_location: %i c_location: %i texture_location: %i\n",
	     ProjMatrix_location,TransMatrix_location,c_location,texture_location);

  // Report on attributes:
  {
    GLint num_attribs = 0, attrib_name_length = 0;
    glGetProgramiv(program,GL_ACTIVE_ATTRIBUTES,&num_attribs);
    glGetProgramiv(program,GL_ACTIVE_ATTRIBUTE_MAX_LENGTH,&attrib_name_length);
    tcp_printf("%u attribs, name max length: %u\n",num_attribs,attrib_name_length);
    char szName[attrib_name_length + 1];

    for(size_t i = 0;i < num_attribs;++i) {
      GLint size = 0;
      GLenum type = 0;
      GLint location = 0;
      glGetActiveAttrib(program,i,attrib_name_length + 1,0,&size,&type,szName);
      location = glGetAttribLocation(program,szName);
      tcp_printf("\t%u: %s %u %u %u\n",i,szName,(unsigned int)location,(unsigned int)size,(unsigned int)type);
    }
  }

  // Report on uniforms:
  {
    GLint num_uniforms = 0, uniform_name_length = 0;
    glGetProgramiv(program,GL_ACTIVE_UNIFORMS,&num_uniforms);
    glGetProgramiv(program,GL_ACTIVE_UNIFORM_MAX_LENGTH,&uniform_name_length);
    tcp_printf("%u uniforms, name max length: %u\n",num_uniforms,uniform_name_length);
    char szName[uniform_name_length + 1];

    for(size_t i = 0;i < num_uniforms;++i) {
      GLint size = 0;
      GLenum type = 0;
      GLint location = 0;
      glGetActiveUniform(program,i,uniform_name_length + 1,0,&size,&type,szName);
      location = glGetUniformLocation(program,szName);
      tcp_printf("\t%u: %s %u %u %u\n",i,szName,(unsigned int)location,(unsigned int)size,(unsigned int)type);
    }
  }

  glUseProgram(program);

  const float identity[4][4] = { {1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1} };
  glUniformMatrix4fv(ProjMatrix_location,1,GL_FALSE,(const GLfloat *)identity);
  glUniformMatrix4fv(TransMatrix_location,1,GL_FALSE,(const GLfloat *)identity);

  glUniform1i(texture_location,0);

  // Set up us the vertex data:
  float geometry[] = {
    0, 0, 0, 1,
    0,0,

    1.0, 0, 0, 1,
    1,0,

    0.0, 1.0, 0, 1,
    0,1,

    1.0, 0, 0, 1,
    1,0,

    1.0, 1.0, 0, 1,
    1,1,

    0.0, 1.0, 0, 1,
    0,1
  };

  glGenBuffers(1,&buffer);
  glBindBuffer(GL_ARRAY_BUFFER,buffer);
  glBufferData(GL_ARRAY_BUFFER,sizeof(float) * 6 * 6,geometry,GL_STATIC_DRAW);
  glEnableVertexAttribArray(vertex_location);
  glEnableVertexAttribArray(texcoord_location);
  glVertexAttribPointer(vertex_location,4,GL_FLOAT,GL_FALSE,sizeof(float) * 6,0);
  glVertexAttribPointer(texcoord_location,2,GL_FLOAT,GL_FALSE,sizeof(float) * 6,(const GLvoid *)(sizeof(float) * 4));

  glBindBuffer(GL_ARRAY_BUFFER,0);

  // Textures:
  dice = loadPng(dice_bin);
  tcp_printf("dice size: %u %u\n",dice.width,dice.height);
  GLuint dice_buffer = 0;
  glGenBuffers(1,&dice_buffer);
  glBindBuffer(GL_PIXEL_UNPACK_BUFFER,dice_buffer);
  glBufferData(GL_PIXEL_UNPACK_BUFFER,4 * dice.width * dice.height,dice.data,GL_STATIC_DRAW);
  glBindBuffer(GL_PIXEL_UNPACK_BUFFER,0);

  uint8_t checkerboard_bgra[] = {
    255,0,0,255, 0,255,0,255,
    0,0,255,255, 255,255,255,255
  };

  uint8_t test_bgra[] = {
    192,128,64,255, 192,128,64,255,
    192,128,64,255, 192,128,64,255
  };

  glActiveTexture(GL_TEXTURE0);

  glGenTextures(1,&texture);
  glBindTexture(GL_TEXTURE_2D,texture);
  tcp_printf("texture name: %u\n",texture);

  //glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,2,2,0,GL_BGRA,GL_UNSIGNED_BYTE,checkerboard_bgra);
  //glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,2,2,0,GL_BGRA,GL_UNSIGNED_BYTE,0);
  //glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,dice.width,dice.height,0,GL_BGRA,GL_UNSIGNED_BYTE,dice.data);
  //glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,dice.width,dice.height,0,GL_BGRA,GL_UNSIGNED_BYTE,0);

  glTexStorage2D(GL_TEXTURE_2D,1,GL_RGBA,dice.width,dice.height);

  //glTexSubImage2D(GL_TEXTURE_2D,0,0,0,dice.width,dice.height,GL_BGRA,GL_UNSIGNED_BYTE,dice.data);

  glBindBuffer(GL_PIXEL_UNPACK_BUFFER,dice_buffer);
  glTexSubImage2D(GL_TEXTURE_2D,0,0,0,dice.width,dice.height,GL_BGRA,GL_UNSIGNED_BYTE,0);
  glBindBuffer(GL_PIXEL_UNPACK_BUFFER,0);

  report_glerror("glTexImage2D");

  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}