`load image` C++ Examples

60 C++ code examples are found related to "load image". You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
Example 1
Source File: reattachImageLoadCallback_tool.cpp    From manul with Apache License 2.0 6 votes vote down vote up
VOID DETACH_SESSION::ImageLoad(IMG img,  VOID *v)
{
    if ( IMG_IsMainExecutable(img))
    {
        RTN rtn = RTN_FindByName(img, "AfterAttach1");

        // relevent only in the attach scenario.
        if (RTN_Valid(rtn))
        {
            RTN_ReplaceProbed(rtn, AFUNPTR(afterAttachProbe));
        }
    }

    PIN_GetLock(&pinLock, PIN_GetTid());
    TraceFile <<"Load image " << IMG_Name(img) << "in iteration " << iteration << endl;
    PIN_ReleaseLock(&pinLock);
    size_t found;
    found= IMG_Name(img).find(FIRST_DLL_NAME);
    if ( found!=string::npos )
    {
		SessionControl()->StartDetach();
    }
} 
Example 2
Source File: insfetch_tool.cpp    From SHMA with GNU General Public License v2.0 6 votes vote down vote up
static VOID imageLoad(IMG img, VOID *v)
{
    // Just instrument the main image.
    if (!IMG_IsMainExecutable(img))
        return;

    for (SEC sec=IMG_SecHead(img); SEC_Valid(sec); sec=SEC_Next(sec))
    {
        for (RTN rtn=SEC_RtnHead(sec); RTN_Valid(rtn); rtn=RTN_Next(rtn))
        {
            RTN_Open(rtn);
            for (INS ins=RTN_InsHead(rtn); INS_Valid(ins); ins=INS_Next(ins))
            {
                INS_InsertCall(ins, IPOINT_BEFORE,
                               (AFUNPTR)incCount, IARG_END);
            }
            RTN_Close(rtn);
        }
    }
} 
Example 3
Source File: reattachImageLoadCallback_tool.cpp    From SHMA with GNU General Public License v2.0 6 votes vote down vote up
VOID DETACH_SESSION::ImageLoad(IMG img,  VOID *v)
{
    if ( IMG_IsMainExecutable(img))
    {
        RTN rtn = RTN_FindByName(img, "AfterAttach1");

        // relevent only in the attach scenario.
        if (RTN_Valid(rtn))
        {
            RTN_ReplaceProbed(rtn, AFUNPTR(afterAttachProbe));
        }
    }

    PIN_GetLock(&lock, PIN_GetTid());
    TraceFile <<"Load image " << IMG_Name(img) << "in iteration " << iteration << endl;
    PIN_ReleaseLock(&lock);
    size_t found;
    found= IMG_Name(img).find(FIRST_DLL_NAME);
    if ( found!=string::npos )
    {
		SessionControl()->StartDetach();
    }
} 
Example 4
Source File: callapp-flush.cpp    From SHMA with GNU General Public License v2.0 6 votes vote down vote up
static VOID ImageLoad(IMG img, VOID *)
{
    PROTO proto_malloc = PROTO_Allocate(PIN_PARG(void *), CALLINGSTD_DEFAULT,
        "malloc", PIN_PARG(size_t), PIN_PARG_END());

    RTN rtn = RTN_FindByName(img, "malloc");
    if (RTN_Valid(rtn))
    {
        std::cout << "Replacing malloc in " << IMG_Name(img) << endl;

        RTN_ReplaceSignature(rtn, AFUNPTR(MallocWrapper),
            IARG_PROTOTYPE, proto_malloc,
            IARG_CONST_CONTEXT,
            IARG_THREAD_ID,
            IARG_ORIG_FUNCPTR,
            IARG_FUNCARG_ENTRYPOINT_VALUE, 0,
            IARG_END);
    }
} 
Example 5
Source File: callapp8.cpp    From SHMA with GNU General Public License v2.0 6 votes vote down vote up
VOID ImageLoad(IMG img, VOID *v)
{
    PROTO protoBar = PROTO_Allocate( PIN_PARG(int), CALLINGSTD_DEFAULT,
                                      "Bar8", PIN_PARG(int), PIN_PARG(int),
                                      PIN_PARG(int), PIN_PARG_END() );
    
    RTN rtn = RTN_FindByName(img, "Bar8");
    if (RTN_Valid(rtn))
    {
        cout << " Replacing " << RTN_Name(rtn) << " in " << IMG_Name(img) << endl;

        RTN_ReplaceSignature(
            rtn, AFUNPTR(myBar),
            IARG_PROTOTYPE, protoBar,
            IARG_CONTEXT,
            IARG_ORIG_FUNCPTR,
            IARG_UINT32, 1,
            IARG_UINT32, 2,
            IARG_FUNCARG_ENTRYPOINT_VALUE, 2,
            IARG_END);
    }    

    PROTO_Free( protoBar );
} 
Example 6
Source File: spawntool.cpp    From SHMA with GNU General Public License v2.0 6 votes vote down vote up
static VOID ImageLoadCallback(IMG img, VOID *v)
{
    if (threadFunction == 0)
    {
        if (KnobVerbose)
            cerr << "Looking for doNothing in " << IMG_Name(img) << "\n";

        RTN rtn = RTN_FindByName (img, "doNothing");

        if (RTN_Valid(rtn))
        {
            threadFunction = RTN_Address(rtn);
            if (KnobVerbose)
                cerr << "'doNothing' at " << hex << threadFunction << dec << "\n";
        }            
    }
} 
Example 7
Source File: reattachImageLoadCallback_tool.cpp    From SHMA with GNU General Public License v2.0 6 votes vote down vote up
VOID REATTACH_SESSION::ImageLoad(IMG img,  VOID *v)
{
    if ( IMG_IsMainExecutable(img))
    {
        RTN rtn = RTN_FindByName(img, "AfterAttach2");
        if (RTN_Valid(rtn))
        {
            RTN_ReplaceProbed(rtn, AFUNPTR(afterAttachProbe));
        }
    }

    PIN_GetLock(&lock, PIN_GetTid());
    TraceFile <<"Load image " << IMG_Name(img) <<" in iteration" << iteration  <<endl;
    PIN_ReleaseLock(&lock);

    size_t found;
    found= IMG_Name(img).find(SECOND_DLL_NAME);
    if ( found!=string::npos )
    {
        SessionControl()->StartDetach();
    }
} 
Example 8
Source File: basisu_enc.cpp    From basis_universal with Apache License 2.0 6 votes vote down vote up
bool load_image(const char* pFilename, image& img)
	{
		std::string ext(string_get_extension(std::string(pFilename)));

		if (ext.length() == 0)
			return false;

		const char *pExt = ext.c_str();

		if (strcasecmp(pExt, "png") == 0)
			return load_png(pFilename, img);
		if (strcasecmp(pExt, "bmp") == 0)
			return load_bmp(pFilename, img);
		if (strcasecmp(pExt, "tga") == 0)
			return load_tga(pFilename, img);
		if ( (strcasecmp(pExt, "jpg") == 0) || (strcasecmp(pExt, "jfif") == 0) || (strcasecmp(pExt, "jpeg") == 0) )
			return load_jpg(pFilename, img);

		return false;
	} 
Example 9
Source File: statdyn_tool.cpp    From SHMA with GNU General Public License v2.0 6 votes vote down vote up
VOID onImageLoad(IMG img, VOID *data)
{
    SYM sym;

    if (IMG_IsMainExecutable(img))
    {
        bool foundStatic = false;
        bool foundDynamic = false;
        for (sym = IMG_RegsymHead(img); SYM_Valid(sym); sym = SYM_Next(sym))
        {
            if (SYM_Name(sym).find("statdyn_app_staticFunction") != string::npos)
            {
                assert(SYM_Dynamic(sym) == false);
                foundStatic = true;
            }
            if (SYM_Name(sym).find("statdyn_app_dynamicFunction") != string::npos)
            {
                assert(SYM_Dynamic(sym) == true);
                foundDynamic = true;
            }
        }
        assert(foundStatic == true);
        assert(foundDynamic == true);
    }
} 
Example 10
Source File: FileHelper.cpp    From Windows-Machine-Learning with MIT License 6 votes vote down vote up
VideoFrame LoadImageFile(hstring filePath) {
    VideoFrame inputImage = nullptr;
    try {
      // open the file
      StorageFile file = StorageFile::GetFileFromPathAsync(filePath).get();
      // get a stream on it
      auto stream = file.OpenAsync(FileAccessMode::Read).get();
      // Create the decoder from the stream
      BitmapDecoder decoder = BitmapDecoder::CreateAsync(stream).get();
      // get the bitmap
      SoftwareBitmap softwareBitmap = decoder.GetSoftwareBitmapAsync().get();
      // load a videoframe from it
      inputImage = VideoFrame::CreateWithSoftwareBitmap(softwareBitmap);
    }
    catch (...) {
      printf("failed to load the image file, make sure you are using fully "
        "qualified paths\r\n");
      exit(EXIT_FAILURE);
    }
    // all done
    return inputImage;
  } 
Example 11
Source File: file_tools.cpp    From BabylonCpp with Apache License 2.0 6 votes vote down vote up
void FileTools::LoadImageFromUrl(
  std::string url, const std::function<void(const Image& img)>& onLoad,
  const std::function<void(const std::string& message, const std::string& exception)>& onError,
  bool flipVertically)
{
  url = FileTools::_CleanUrl(url);
  url = FileTools::PreprocessUrl(url);

  std::string filename = url;

  auto onArrayBufferReceived = [=](const ArrayBuffer& buffer) {
    auto image = ArrayBufferToImage(buffer, flipVertically);
    onLoad(image);
  };
  auto onErrorWrapper = [=](const std::string& errorMessage) { onError(errorMessage, ""); };

  asio::LoadAssetAsync_Binary(url, onArrayBufferReceived, onErrorWrapper);
} 
Example 12
Source File: data.cpp    From Darknet-On-OpenCL with MIT License 6 votes vote down vote up
matrix load_image_paths_gray(char **paths, int n, int w, int h)
{
    int i;
    matrix X;
    X.rows = n;
    X.vals = (float **)calloc(X.rows, sizeof(float*));
    X.cols = 0;

    for(i = 0; i < n; ++i){
        image im = load_image(paths[i], w, h, 3);

        image gray = grayscale_image(im);
        free_image(im);
        im = gray;

        X.vals[i] = im.data;
        X.cols = im.h*im.w*im.c;
    }
    return X;
} 
Example 13
Source File: CCTextureCache.cpp    From BrickGame with MIT License 6 votes vote down vote up
void TextureCache::loadImage()
{
    AsyncStruct *asyncStruct = nullptr;

    while (true)
    {
        std::queue<AsyncStruct*> *pQueue = _asyncStructQueue;
        _asyncStructQueueMutex.lock();
        if (pQueue->empty())
        {
            _asyncStructQueueMutex.unlock();
            if (_needQuit) {
                break;
            }
            else {
                std::unique_lock<std::mutex> lk(_sleepMutex);
                _sleepCondition.wait(lk);
                continue;
            }
        }
        else
        { 
Example 14
Source File: UIGifAnimEx.cpp    From DuiCEF with MIT License 6 votes vote down vote up
virtual void LoadGifImage()
		{
			CDuiString sImag = m_pOwer->GetBkImage();
			m_bLoadImg = true;
			m_pGifImage	=	CRenderEngine::LoadGifImageX(STRINGorID(sImag),0, 0);
			if ( NULL == m_pGifImage ) return;
			m_nFrameCount	=	m_pGifImage->GetNumFrames();
			m_nFramePosition = 0;
			m_nDelay = m_pGifImage->GetFrameDelay();
			if (m_nDelay <= 0 ) 
				m_nDelay = 100;
			if(!m_bAutoStart)
				m_bRealStop = true;
			if(m_bAutoStart && m_pOwer->IsVisible())
				StartAnim();
		} 
Example 15
Source File: simplelite.cc    From tflite_zynq with GNU General Public License v3.0 6 votes vote down vote up
LoadImageFromFile(char * image_path,
                                              int desired_image_width,
                                              int desired_image_height,
                                              int desired_image_channels)
{
  // Load the image
  auto img = imread(image_path);

  LOG(INFO) << "input image size: " << img.cols << "x" << img.rows << "x" << img.channels() << std::endl;

  auto newSize = Size(desired_image_width, desired_image_width);
  Mat reimg;
  resize(img, reimg, newSize);

  LOG(INFO) << "output image size: " << reimg.cols << "x" << reimg.rows << "x" << reimg.channels() << std::endl;

  std::vector<uint8_t> imgData(img.cols * img.rows * img.channels());

  if (reimg.isContinuous())
  {
    imgData.assign(reimg.datastart, reimg.dataend);
  }
  else
  {
    for 
Example 16
Source File: GLTFDom.cpp    From fury3d with MIT License 6 votes vote down vote up
bool GLTFDom::LoadImage(const void* wrapper, bool object)
	{
		if (object && !IsObject(wrapper))
		{
			FURYE << "Json node is not an object!";
			return false;
		}

		GLTFImage::Ptr imagePtr = std::make_shared<GLTFImage>();

		if (LoadMemberValue(wrapper, "uri", imagePtr->URI))
		{
			imagePtr->URISpecified = true;
		}
		else
		{
			if 
Example 17
Source File: ImageLoader.cpp    From DEADCELL-CSGO with MIT License 6 votes vote down vote up
ImageData LoadImage(const RawData &data)
	{
		std::vector<std::unique_ptr<Plugin>> plugins;
		plugins.emplace_back(new PluginBMP());
		plugins.emplace_back(new PluginJPEG());
		plugins.emplace_back(new PluginPNG());

		for (auto &plugin : plugins)
		{
			if (plugin->IsValidFormat(data))
			{
				auto image = plugin->Load(Stream(data));
				ConvertTo32Bits(image);
				FlipVertical(image);
				SwapRedBlue32(image);

				return image;
			}
		}

		throw;
	} 
Example 18
Source File: spawntool.cpp    From manul with Apache License 2.0 6 votes vote down vote up
static VOID ImageLoadCallback(IMG img, VOID *v)
{
    if (threadFunction == 0)
    {
        if (KnobVerbose)
            cerr << "Looking for doNothing in " << IMG_Name(img) << "\n";
#ifndef TARGET_MAC
        RTN rtn = RTN_FindByName (img, "doNothing");
#else
        RTN rtn = RTN_FindByName (img, "_doNothing");
#endif

        if (RTN_Valid(rtn))
        {
            threadFunction = RTN_Address(rtn);
            if (KnobVerbose)
                cerr << "'doNothing' at " << hex << threadFunction << dec << "\n";
        }            
    }
} 
Example 19
Source File: image.cpp    From recompiler with MIT License 6 votes vote down vote up
bool Import::Load(Binary* image, IBinaryFileReader& reader)
	{
		FileChunk chunk(reader, "Import");
		if (!chunk)
			return false;

		reader >> m_exportIndex;
		reader >> m_exportName;
		reader >> m_exportImageName;

		if (chunk.GetVersion() < 2)
		{
			uint32 temp;
			reader >> temp;
			m_tableAddress = temp;
			reader >> temp;
			m_entryAddress = temp;
		}
		else
		{ 
Example 20
Source File: image.cpp    From recompiler with MIT License 6 votes vote down vote up
bool Section::Load(Binary* image, IBinaryFileReader& reader)
	{
		FileChunk chunk(reader, "Section");
		if (!chunk) 
			return false;

		reader >> m_name;
		reader >> m_virtualOffset;
		reader >> m_virtualSize;
		reader >> m_physicalOffset;
		reader >> m_physicalSize;
		reader >> m_isReadable;
		reader >> m_isWritable;
		reader >> m_isExecutable;
		reader >> m_cpuName;

		m_image = image;
		return true;
	} 
Example 21
Source File: PEImage.cpp    From ScriptHookV with GNU General Public License v2.0 6 votes vote down vote up
bool PEImage::Load( const std::string & path ) 
	{
		filePath = path;

		std::ifstream inputFile( path, std::ios::binary );
		if ( inputFile.fail() ) 
		{
			return false;
		}
		std::vector<char> bufferTemp( ( std::istreambuf_iterator<char>( inputFile ) ), ( std::istreambuf_iterator<char>() ) );
		fileBuffer.swap( bufferTemp );

		bool parseSuccess = ParsePE();
		if ( !parseSuccess ) 
		{
			return false;
		}

		return true;
	} 
Example 22
Source File: ppm_io.cpp    From PhysIKA with GNU General Public License v2.0 6 votes vote down vote up
bool PPMIO::load(const std::string &filename, Image * image, Image::DataFormat data_format)
{
    if(ImageIO::checkFileNameAndImage(filename,string(".ppm"),image) == false)
        return false;

    fstream fp;
    fp.open(filename.c_str(),std::ios::in|std::ios::binary);
    if(!fp.is_open())
    {
        std::cerr<<"Couldn't opern .ppm file:"<<filename<<std::endl;
        return false;
    }
    string file_head;
    while(getline(fp, file_head))
    {
        file_head = FileUtilities::removeWhitespaces(file_head,1);
        if(file_head.at(0) == '#')
            continue;
        else
            break;
    } 
Example 23
Source File: imageloader.cpp    From c2gQtWS_x with The Unlicense 6 votes vote down vote up
void ImageLoader::loadSpeaker(QObject* dataObject)
{
    QNetworkAccessManager* netManager = new QNetworkAccessManager(this);

    const QUrl url(m_imageUrl);
    QNetworkRequest request(url);
    // stores the object so we can catch it later
    request.setOriginatingObject(dataObject);

    // QtCon redirects Speaker Images to https://
    // to avoid ssl errors:
    QSslConfiguration conf = request.sslConfiguration();
    conf.setPeerVerifyMode(QSslSocket::VerifyNone);
    request.setSslConfiguration(conf);

    QNetworkReply* reply = netManager->get(request);
    connect(reply, SIGNAL(finished()), this, SLOT(onReplyFinished()));
} 
Example 24
Source File: errorScreen.cpp    From TWiLightMenu with GNU General Public License v3.0 6 votes vote down vote up
void loadSdRemovedImage(void) {
	uint imageWidth, imageHeight;
	std::vector<unsigned char> image;

	lodepng::decode(image, imageWidth, imageHeight, "nitro:/graphics/sdRemovedError.png");

	for(uint i=0;i<image.size()/4;i++) {
		sdRemovedExtendedImage[i] = image[i*4]>>3 | (image[(i*4)+1]>>3)<<5 | (image[(i*4)+2]>>3)<<10 | BIT(15);
	}

	image.clear();
	lodepng::decode(image, imageWidth, imageHeight, "nitro:/graphics/sdRemoved.png");

	for(uint i=0;i<image.size()/4;i++) {
		sdRemovedImage[i] = image[i*4]>>3 | (image[(i*4)+1]>>3)<<5 | (image[(i*4)+2]>>3)<<10 | BIT(15);
	}
} 
Example 25
Source File: ImageLoader.cpp    From open_source_startalk with MIT License 6 votes vote down vote up
void ImageLoader::loadImage(const QString& url, QLabel* label, const QString& defaultPic, IDecorateInterface* scalePolicy)
{
    if (NULL == scalePolicy)
    {
        return loadImage(url,label,defaultPic);
    }

    if (NULL!=label)
    {
        // 先显示默认图片
        QPixmap defaultPixmap;
        defaultPixmap.load(defaultPic);
        scalePolicy->decorate(label,defaultPixmap);

        auto callback = mReceiver->createCallback<QPixmap>([this,label,scalePolicy](const QPixmap& pixmap){
           scalePolicy->decorate(label,pixmap);
        },[]{});

        loadPixmap(url,callback);
    }
} 
Example 26
Source File: ImageHelper.cpp    From open_source_startalk with MIT License 6 votes vote down vote up
QImage ImageHelper::loadImageFromPath( const QString& filepath )
    {
        QString format = getImageRealFormat (filepath);
        if (format.isEmpty ())
        {
            Log::e("load image error format is empty");
            return QImage();
        }
        QImage img;
        img.load(filepath, format.toStdString().c_str());
        if(!img.isNull()){
            return img;
        }

        img.load(filepath);
        return img;
    } 
Example 27
Source File: ImageLoader.cpp    From open_source_startalk with MIT License 6 votes vote down vote up
void ImageLoader::loadImage(const QString& url, IDrawableInterface* pDrawable,const QString& defaultPic)
{
    if (NULL!=pDrawable)
    {
        // 先显示默认图片
        pDrawable->drawDefault(defaultPic);
        pDrawable->preLoad();

        auto callback = mReceiver->createCallback<QString>([this,pDrawable,url](const QString& localpath){
            pDrawable->afterLoad();
           pDrawable->draw(localpath,url);
          
        },[]{});

        loadPixmapPath(url,callback);
    }
} 
Example 28
Source File: ImageLoader.cpp    From open_source_startalk with MIT License 6 votes vote down vote up
void ImageLoader::loadImage(const QString& url, QLabel* label, const QString& defaultPic)
{
    if (NULL!=label)
    {
        // 先显示默认图片
        QPixmap defaultPixmap;
        defaultPixmap.load(defaultPic);
        label->setPixmap(defaultPixmap);

        auto callback = mReceiver->createCallback<QPixmap>([this,label](const QPixmap& pixmap){
            if (!pixmap.isNull())
            {
                label->setPixmap(pixmap);
            }
        },[]{});
        
        loadPixmap(url,callback);
    }
} 
Example 29
Source File: record_imageload.cpp    From manul with Apache License 2.0 6 votes vote down vote up
static void ParseImageLoadLine(string &imageName,  ADDRINT *offset, REPLAY_IMAGE_TYPE* type)
{
    // Data was written like this :-
    // fprintf (imgLog, "L '%s' 0x%x\n", IMG_Name(img).c_str(), 
    //          IMG_LoadOffset(img), base, IMG_HighAddress(img));
    char imgNameBuffer[MAX_FILENAME_LENGTH];
    int typeInt = (int)REPLAY_IMAGE_TYPE_REGULAR;

    int itemsRead = fscanf(imgLog," '%[^']' %p %d\n",&imgNameBuffer[0], (void**)offset, &typeInt);
    if (itemsRead != 3)
    {
        fprintf (trace, "ParseImageLoadLine: Failed to parse; parsed %d expected to parse 3\n", itemsRead);
        exit(1);
    }
    imageName = imgNameBuffer;
    *type = (REPLAY_IMAGE_TYPE)typeInt;
} 
Example 30
Source File: object_detector.cpp    From android-face-landmarks with MIT License 6 votes vote down vote up
inline void load (
            const funny_image& img_
        )
        {
            const array2d<unsigned char>& img = img_.img;

            feat_image.set_size(img.nr(), img.nc());
            assign_all_pixels(feat_image,0);
            for (long r = 1; r+1 < img.nr(); ++r)
            {
                for (long c = 1; c+1 < img.nc(); ++c)
                {
                    unsigned char f = 0;
                    if (img[r][c])   f |= 0x1;
                    if (img[r][c+1]) f |= 0x2;
                    if (img[r][c-1]) f |= 0x4;
                    if (img[r+1][c]) f |= 0x8;
                    if (img[r-1][c]) f |= 0x10;

                    // Store the code value for the pattern of pixel values in the 4-connected
                    // neighborhood around this row and column.
                    feat_image[r][c] = f;
                }
            }
        } 
Example 31
Source File: PEImage.cpp    From OpenVHook with GNU General Public License v2.0 6 votes vote down vote up
bool PEImage::Load( const std::string & path ) {

		filePath = path;

		std::ifstream inputFile( path, std::ios::binary );
		if ( inputFile.fail() ) {
			return false;
		}
		std::vector<char> bufferTemp( ( std::istreambuf_iterator<char>( inputFile ) ), ( std::istreambuf_iterator<char>() ) );
		fileBuffer.swap( bufferTemp );

		bool parseSuccess = ParsePE();
		if ( !parseSuccess ) {
			return false;
		}

		return true;
	} 
Example 32
Source File: i_video.c    From kubedoom with GNU General Public License v3.0 6 votes vote down vote up
static void LoadDiskImage(void)
{
    patch_t *disk;
    char *disk_name;
    int y;
    int xoffset = SCREENWIDTH - LOADING_DISK_W;
    int yoffset = SCREENHEIGHT - LOADING_DISK_H;
    char buf[20];

    SDL_VideoDriverName(buf, 15);

    if (!strcmp(buf, "Quartz"))
    {
        // MacOS Quartz gives us pageflipped graphics that screw up the 
        // display when we use the loading disk.  Disable it.
        // This is a gross hack.

        return;
    }

    if (M_CheckParm("-cdrom") > 0)
        disk_name = DEH_String("STCDROM");
    else 
Example 33
Source File: image_loader_stb.c    From awtk with GNU Lesser General Public License v2.1 6 votes vote down vote up
ret_t stb_load_image(int32_t subtype, const uint8_t* buff, uint32_t buff_size, bitmap_t* image,
                     bool_t require_bgra, bool_t enable_bgr565, bool_t enable_rgb565) {
  int w = 0;
  int h = 0;
  int n = 0;
  ret_t ret = RET_FAIL;

  if (subtype != ASSET_TYPE_IMAGE_GIF) {
    uint8_t* data = NULL;
    uint8_t* stb_data = stbi_load_from_memory(buff, buff_size, &w, &h, &n, 0);
    return_value_if_fail(stb_data != NULL, RET_FAIL);

    if (n == 2) {
      n = 4;
      data = convert_2_to_4(stb_data, w, h);
    } else {
      data = stb_data;
    }
#ifdef WITH_LCD_MONO
    ret = bitmap_init_from_rgba(image, w, h, BITMAP_FMT_MONO, data, n);
#else
    if (enable_bgr565 && rgba_data_is_opaque(data, w, h, n)) {
      ret = bitmap_init_from_rgba(image, w, h, BITMAP_FMT_BGR565, data, n);
    } else if 
Example 34
Source File: svg_image.c    From awtk with GNU Lesser General Public License v2.1 6 votes vote down vote up
static ret_t svg_image_load_bsvg(widget_t* widget) {
  svg_image_t* svg_image = SVG_IMAGE(widget);
  image_base_t* image_base = IMAGE_BASE(widget);
  return_value_if_fail(svg_image != NULL && image_base != NULL, RET_BAD_PARAMS);

  if (svg_image->bsvg_asset != NULL) {
    widget_unload_asset(widget, svg_image->bsvg_asset);
    svg_image->bsvg_asset = NULL;
  }

  svg_image->bsvg_asset = widget_load_asset(widget, ASSET_TYPE_IMAGE, image_base->image);
  return_value_if_fail(svg_image->bsvg_asset != NULL, RET_NOT_FOUND);

  if (svg_image->bsvg_asset->subtype != ASSET_TYPE_IMAGE_BSVG) {
    widget_unload_asset(widget, svg_image->bsvg_asset);
    log_debug("invalid bsvg asset: %s\n", image_base->image);
    svg_image->bsvg_asset = NULL;
  }

  return RET_OK;
} 
Example 35
Source File: image_loader_stb_test.cc    From awtk with GNU Lesser General Public License v2.1 6 votes vote down vote up
static ret_t load_image(const char* filename, bitmap_t* image) {
  ret_t ret = RET_OK;
  image_loader_t* loader = image_loader_stb();
  uint32_t size = file_get_size(filename);
  asset_info_t* info = (asset_info_t*)TKMEM_ALLOC(sizeof(asset_info_t) + size);
  return_value_if_fail(info != NULL, RET_OOM);

  memset(info, 0x00, sizeof(asset_info_t));
  info->size = size;
  info->type = ASSET_TYPE_IMAGE;
  info->subtype = ASSET_TYPE_IMAGE_PNG;
  info->refcount = 1;
  info->is_in_rom = FALSE;
  strncpy(info->name, "name", TK_NAME_LEN);

  ENSURE(file_read_part(filename, info->data, size, 0) == size);
  ret = image_loader_load(loader, info, image);
  TKMEM_FREE(info);

  return ret;
} 
Example 36
Source File: ResourceManager.cpp    From PolyEngine with MIT License 6 votes vote down vote up
float* Poly::LoadImageHDR(const String& path, int* width, int* height, int* fileChannels)
{
	if (!stbi_is_hdr(path.GetCStr()))
	{
		gConsole.LogWarning("Poly::LoadImageHDR LDR file spotted, scalling to HDR and gamma change may appear!");
	}

	stbi_set_flip_vertically_on_load(true);
	float *data = stbi_loadf(path.GetCStr(), width, height, fileChannels, 0);
	if (!data)
	{
		gConsole.LogInfo("Poly::LoadImageHDR Failed to load: {}, reason: {}", path, stbi_failure_reason());
	}
	
	return data;
} 
Example 37
Source File: ResourceManager.cpp    From PolyEngine with MIT License 6 votes vote down vote up
unsigned char* Poly::LoadImage(const String& path, int* width, int* height, int* fileChannels, int desiredChannels)
{
	if (stbi_is_hdr(path.GetCStr()))
	{
		gConsole.LogWarning("Poly::LoadImageHDR HDR file spotted, scalling to LDR and gamma change may appear!");
	}

	stbi_set_flip_vertically_on_load(true);
	unsigned char *data = stbi_load(path.GetCStr(), width, height, fileChannels, desiredChannels);
	if (!data)
	{
	 gConsole.LogInfo("Poly::LoadImage Failed to load: {}, reason: {}", path, stbi_failure_reason());
	}
	
	return data;
} 
Example 38
Source File: texture.cpp    From OpenGL-Build-High-Performance-Graphics with MIT License 6 votes vote down vote up
GLuint loadImageToTexture(const char * imagepath, int *width, int *height){
	int channels;
	GLuint textureID=0;

	//Load the images and convert them to RGBA format
	unsigned char* image =
		SOIL_load_image(imagepath, width, height, &channels, SOIL_LOAD_RGBA);

	if(!image){
		printf("Failed to load image %s\n", imagepath);
		return textureID;
	}
	printf("Loaded Image: %d x %d - %d channels\n", *width, *height, channels);

	textureID=initializeTexture(image, *width, *height, GL_RGBA); 

	SOIL_free_image_data(image);
	return textureID;
} 
Example 39
Source File: UIImageView.cpp    From DouDiZhu with Apache License 2.0 6 votes vote down vote up
void ImageView::loadTexture(const std::string& fileName, TextureResType texType)
{
    if (fileName.empty())
    {
        return;
    }
    _textureFile = fileName;
    _imageTexType = texType;
    switch (_imageTexType)
    {
        case TextureResType::LOCAL:
            _imageRenderer->initWithFile(fileName);
            break;
        case TextureResType::PLIST:
            _imageRenderer->initWithSpriteFrameName(fileName);
            break;
        default:
            break;
    }
    //FIXME: https://github.com/cocos2d/cocos2d-x/issues/12249
    if (!_ignoreSize && _customSize.equals(Size::ZERO)) {
        _customSize = _imageRenderer->getContentSize();
    }
    this->setupTexture();
} 
Example 40
Source File: moduledll.cpp    From BAS with MIT License 6 votes vote down vote up
void ImageProcessingLoad(char *InputJson, ResizeFunction AllocateSpace, void* AllocateData, void* DllData, void* ThreadData, unsigned int ThreadId, bool *NeedToStop, bool* WasError)
    {
        ImageData * data = (ImageData *)ThreadData;

        int Id =  qrand() % 1000000;
        QByteArray IdString = QString::number(Id).toUtf8();
        QByteArray Array = QByteArray::fromBase64(InputJson);
        QBuffer buffer(&Array);
        buffer.open( QIODevice::ReadOnly );
        QImageReader reader(&buffer);
        Image i;
        i.Format = QString::fromUtf8(reader.format());

        QImage *image = new QImage(reader.read());

        buffer.close();

        i.Data = image;

        data->insert(Id,i);

        char * ResMemory = AllocateSpace(IdString.size(),AllocateData);
        memcpy(ResMemory, IdString.data(), IdString.size() );
    } 
Example 41
Source File: main.cpp    From FileSignatureHijack with MIT License 6 votes vote down vote up
BOOL RtlLoadPeHeaders(PIMAGE_DOS_HEADER *Dos, PIMAGE_NT_HEADERS *Nt, PIMAGE_FILE_HEADER *File, PIMAGE_OPTIONAL_HEADER *Optional, PIMAGE_SECTION_HEADER *Section, PBYTE *ImageBase)
{
	*Dos = (PIMAGE_DOS_HEADER)*ImageBase;
	if ((*Dos)->e_magic != IMAGE_DOS_SIGNATURE)
		return FALSE;

	*Nt = (PIMAGE_NT_HEADERS)((PBYTE)*Dos + (*Dos)->e_lfanew);
	if ((*Nt)->Signature != IMAGE_NT_SIGNATURE)
		return FALSE;

	*File = (PIMAGE_FILE_HEADER)(*ImageBase + (*Dos)->e_lfanew + sizeof(DWORD));
	*Optional = (PIMAGE_OPTIONAL_HEADER)((PBYTE)*File + sizeof(IMAGE_FILE_HEADER));

	*Section = (PIMAGE_SECTION_HEADER)((PBYTE)*ImageBase + (*Dos)->e_lfanew + sizeof(IMAGE_NT_HEADERS));

	return TRUE;
} 
Example 42
Source File: art_helpers.cpp    From foo_spider_monkey_panel with MIT License 6 votes vote down vote up
ExtractBitmap( album_art_extractor_instance_v2::ptr extractor, const GUID& artTypeGuid, bool no_load, std::u8string* pImagePath, abort_callback& abort )
{
    album_art_data_ptr data = extractor->query( artTypeGuid, abort );
    std::unique_ptr<Gdiplus::Bitmap> bitmap;

    if ( !no_load )
    {
        bitmap = GetBitmapFromAlbumArtData( data );
    }

    if ( pImagePath && ( no_load || bitmap ) )
    {
        auto pathlist = extractor->query_paths( artTypeGuid, abort );
        if ( pathlist->get_count() )
        {
            *pImagePath = file_path_display( pathlist->get_path( 0 ) );
        }
    }

    return bitmap;
} 
Example 43
Source File: art_helpers.cpp    From foo_spider_monkey_panel with MIT License 6 votes vote down vote up
GetBitmapFromMetadbOrEmbed( const metadb_handle_ptr& handle, uint32_t art_id, bool need_stub, bool only_embed, bool no_load, std::u8string* pImagePath )
{
    assert( handle.is_valid() );

    std::u8string imagePath;
    std::unique_ptr<Gdiplus::Bitmap> bitmap;

    try
    {
        if ( only_embed )
        {
            bitmap = GetBitmapFromEmbeddedData( handle->get_path(), art_id );
            if ( bitmap )
            {
                imagePath = handle->get_path();
            }
        }
        else
        {
            bitmap = GetBitmapFromMetadb( handle, art_id, need_stub, no_load, &imagePath );
        }
    } 
Example 44
Source File: image_helpers.cpp    From foo_spider_monkey_panel with MIT License 6 votes vote down vote up
LoadImage( const std::wstring& imagePath )
{
    // Gdiplus::Bitmap(path) locks file, thus using IStream instead to prevent it.
    IStreamPtr pStream;
    HRESULT hr = SHCreateStreamOnFileEx( imagePath.c_str(), STGM_READ | STGM_SHARE_DENY_WRITE, GENERIC_READ, FALSE, nullptr, &pStream );
    if ( FAILED( hr ) )
    {
        return nullptr;
    }

    std::unique_ptr<Gdiplus::Bitmap> img( new Gdiplus::Bitmap( static_cast<IStream*>( pStream ), TRUE ) );
    if ( !gdi::IsGdiPlusObjectValid( img ) )
    {
        return nullptr;
    }

    return img;
} 
Example 45
Source File: syscalls_and_locks_tool.cpp    From manul with Apache License 2.0 6 votes vote down vote up
VOID ImageLoad(IMG img, void *v)
{
    if(IMG_IsMainExecutable(img))
    {
        RTN rtn = RTN_Invalid();
 
        rtn = RTN_FindByName(img, "WaitThread2AcquireLock");
        if (RTN_Valid(rtn))
        {
            RTN_ReplaceProbed(rtn, AFUNPTR(Replacement_WaitThread2AcquireLock));
        }

        rtn = RTN_FindByName(img, "WaitUntilLockAcquiredAndReleased");
        if (RTN_Valid(rtn))
        {
            RTN_ReplaceProbed(rtn, AFUNPTR(Replacement_AcquireAndReleaseLock));
        }
    }
} 
Example 46
Source File: test-drishti-face.cpp    From drishti with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
cv::Mat loadImage(const std::string& filename)
    {
        assert(!filename.empty());
        cv::Mat image = cv::imread(filename, cv::IMREAD_COLOR);

        cv::Mat Irgb;
        cv::cvtColor(image, Irgb, cv::COLOR_BGR2RGB);    

        cv::Mat It = Irgb.t(), Itf;
        It.convertTo(Itf, CV_32FC3, 1.0f / 255.f);
        Ip = MatP(Itf);

        cv::Mat green;
        cv::extractChannel(image, green, 1);
        Ib = drishti::face::FaceDetector::PaddedImage(green, { { 0, 0 }, green.size() });
        
        return image;
    } 
Example 47
Source File: reattachImageLoadCallback_tool.cpp    From manul with Apache License 2.0 6 votes vote down vote up
VOID REATTACH_SESSION::ImageLoad(IMG img,  VOID *v)
{
    if ( IMG_IsMainExecutable(img))
    {
        RTN rtn = RTN_FindByName(img, "AfterAttach2");
        if (RTN_Valid(rtn))
        {
            RTN_ReplaceProbed(rtn, AFUNPTR(afterAttachProbe));
        }
    }

    PIN_GetLock(&pinLock, PIN_GetTid());
    TraceFile <<"Load image " << IMG_Name(img) <<" in iteration" << iteration  <<endl;
    PIN_ReleaseLock(&pinLock);

    size_t found;
    found= IMG_Name(img).find(SECOND_DLL_NAME);
    if ( found!=string::npos )
    {
        SessionControl()->StartDetach();
    }
} 
Example 48
Source File: ITKFileIO.cxx    From quicksilver with Apache License 2.0 6 votes vote down vote up
void ITKFileIO::LoadImage(Image3D& image, const char* name)
{
    GridInfo grid;
    ComponentType type;

    std::cerr << "Loading " << name << "...";

    ReadHeader(grid, type, name);
    if(type != itk::ImageIOBase::FLOAT){
       std::cerr << "converting from " 
		 << itk::ImageIOBase::GetComponentTypeAsString(type)
		 << " to float.";
    }
    // if (type != itk::ImageIOBase::FLOAT) {
    //     throw PyCAException(__FILE__,__LINE__,"We do not support type other than float at this time");
    // }

    size_t nVox = grid.nVox();
    Image3D temp(grid, image.memType());
    if (image.memType() != MEM_DEVICE) {
        CopyFromITKBuffer<float, float>(name, temp.get(), nVox);
    } else { 
Example 49
Source File: An8Image.cpp    From N64-Tools with The Unlicense 6 votes vote down vote up
bool An8Image::Load(AN8XPARSER*p_parser)
{
	int elementStart = p_parser->IndexOf(1,"image");
	if(elementStart<0) return false;

	int elementEnd = p_parser->IndexOf(1,"}");
	while(p_parser->Length()!=1+LINERETURN && elementStart != elementEnd)
	{
		if(p_parser->FindWord("size {"))
		{
			p_parser->CutLine("{",2);
			string element = p_parser->SubStr(""," ");
			Size.Width = atoi( element.c_str());

			p_parser->CutLine(" ",1);
			element = p_parser->SubStr(""," ");
			Size.Height = atoi( element.c_str());
		}

		p_parser->ReadLine();
		elementEnd =p_parser->IndexOf(1,"}");
	}
	return true;
} 
Example 50
Source File: XTiffImage.cpp    From avitab with GNU Affero General Public License v3.0 6 votes vote down vote up
void XTiffImage::loadFullImage() {
    if (fullImageLoaded) {
        return;
    }

    resize(fullWidth, fullHeight, 0);
    if (!TIFFReadRGBAImageOriented(tif, fullWidth, fullHeight, getPixels(), ORIENTATION_TOPLEFT, 0)) {
        throw std::runtime_error("Couldn't read TIFF");
    }

    uint8_t *data = (uint8_t *) getPixels();

    // libtiff actually loads ARGB and there is no easy way to change that
    for (int y = 0; y < fullHeight; y++) {
        for (int x = 0; x < fullWidth; x++) {
            int g = data[4 * x + 2];
            data[4 * x + 2] = data[4 * x + 0];
            data[4 * x + 0] = g;
        }
        data += 4 * fullWidth;
    }

    fullImageLoaded = true;
}