简体   繁体   English

SDL2 / SDL_Image加载objcopy文件

[英]SDL2/SDL_Image loading objcopy files

As stated on the topic, i'm using objcopy to load SDL_Image images with MinGW over Eclipse Helios for windows. 如主题所述,我正在使用objcopy在Windows的Eclipse Helios上通过MinGW加载SDL_Image图像。 I'm using the command: objcopy --input-target binary --output-target pei-i386 --binary-architecture i386 Lilothyn.jpg Lilothyn.o That results in the file: 我正在使用以下命令: objcopy --input-target binary --output-target pei-i386 --binary-architecture i386 Lilothyn.jpg Lilothyn.o生成文件:

Lilothyn.o:     file format pei-i386
Lilothyn.o
architecture: i386, flags 0x00000030:
HAS_SYMS, HAS_LOCALS
start address 0x00000000

Characteristics 0x305
        relocations stripped
        line numbers stripped
        32 bit words
        debugging information removed

Time/Date               Thu Jan 01 00:00:00 1970
Magic                   0000
MajorLinkerVersion      0
MinorLinkerVersion      0
SizeOfCode              00000000
SizeOfInitializedData   00000000
SizeOfUninitializedData 00000000
AddressOfEntryPoint     00000000
BaseOfCode              00000000
BaseOfData              00000000
ImageBase               00000000
SectionAlignment        00000000
FileAlignment           00000000
MajorOSystemVersion     0
MinorOSystemVersion     0
MajorImageVersion       0
MinorImageVersion       0
MajorSubsystemVersion   0
MinorSubsystemVersion   0
Win32Version            00000000
SizeOfImage             00000000
SizeOfHeaders           00000000
CheckSum                00000000
Subsystem               00000000        (unspecified)
DllCharacteristics      00000000
SizeOfStackReserve      00000000
SizeOfStackCommit       00000000
SizeOfHeapReserve       00000000
SizeOfHeapCommit        00000000
LoaderFlags             00000000
NumberOfRvaAndSizes     00000000

The Data Directory
Entry 0 00000000 00000000 Export Directory [.edata (or where ever we found it)]
Entry 1 00000000 00000000 Import Directory [parts of .idata]
Entry 2 00000000 00000000 Resource Directory [.rsrc]
Entry 3 00000000 00000000 Exception Directory [.pdata]
Entry 4 00000000 00000000 Security Directory
Entry 5 00000000 00000000 Base Relocation Directory [.reloc]
Entry 6 00000000 00000000 Debug Directory
Entry 7 00000000 00000000 Description Directory
Entry 8 00000000 00000000 Special Directory
Entry 9 00000000 00000000 Thread Storage Directory [.tls]
Entry a 00000000 00000000 Load Configuration Directory
Entry b 00000000 00000000 Bound Import Directory
Entry c 00000000 00000000 Import Address Table Directory
Entry d 00000000 00000000 Delay Import Directory
Entry e 00000000 00000000 CLR Runtime Header
Entry f 00000000 00000000 Reserved

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .data         000024fb  00000000  00000000  000000c0  2**0
                  CONTENTS, ALLOC, LOAD, DATA
SYMBOL TABLE:
[  0](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 _binary_Lilothyn_jpg_start
[  1](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x000024fb _binary_Lilothyn_jpg_end
[  2](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x000024fb _binary_Lilothyn_jpg_size

... and the other: ... 和另一个:

Tommy.o:     file format pei-i386
Tommy.o
architecture: i386, flags 0x00000030:
HAS_SYMS, HAS_LOCALS
start address 0x00000000

Characteristics 0x305
        relocations stripped
        line numbers stripped
        32 bit words
        debugging information removed

Time/Date               Thu Jan 01 00:00:00 1970
Magic                   0000
MajorLinkerVersion      0
MinorLinkerVersion      0
SizeOfCode              00000000
SizeOfInitializedData   00000000
SizeOfUninitializedData 00000000
AddressOfEntryPoint     00000000
BaseOfCode              00000000
BaseOfData              00000000
ImageBase               00000000
SectionAlignment        00000000
FileAlignment           00000000
MajorOSystemVersion     0
MinorOSystemVersion     0
MajorImageVersion       0
MinorImageVersion       0
MajorSubsystemVersion   0
MinorSubsystemVersion   0
Win32Version            00000000
SizeOfImage             00000000
SizeOfHeaders           00000000
CheckSum                00000000
Subsystem               00000000        (unspecified)
DllCharacteristics      00000000
SizeOfStackReserve      00000000
SizeOfStackCommit       00000000
SizeOfHeapReserve       00000000
SizeOfHeapCommit        00000000
LoaderFlags             00000000
NumberOfRvaAndSizes     00000000

The Data Directory
Entry 0 00000000 00000000 Export Directory [.edata (or where ever we found it)]
Entry 1 00000000 00000000 Import Directory [parts of .idata]
Entry 2 00000000 00000000 Resource Directory [.rsrc]
Entry 3 00000000 00000000 Exception Directory [.pdata]
Entry 4 00000000 00000000 Security Directory
Entry 5 00000000 00000000 Base Relocation Directory [.reloc]
Entry 6 00000000 00000000 Debug Directory
Entry 7 00000000 00000000 Description Directory
Entry 8 00000000 00000000 Special Directory
Entry 9 00000000 00000000 Thread Storage Directory [.tls]
Entry a 00000000 00000000 Load Configuration Directory
Entry b 00000000 00000000 Bound Import Directory
Entry c 00000000 00000000 Import Address Table Directory
Entry d 00000000 00000000 Delay Import Directory
Entry e 00000000 00000000 CLR Runtime Header
Entry f 00000000 00000000 Reserved

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .data         000834fe  00000000  00000000  000000c0  2**0
                  CONTENTS, ALLOC, LOAD, DATA
SYMBOL TABLE:
[  0](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 _binary_Tommy_jpg_start
[  1](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x000834fe _binary_Tommy_jpg_end
[  2](sec -1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x000834fe _binary_Tommy_jpg_size

The problem is that this last file (Tommy.o) loads properly, while the 1st file (Lilothyn.o) doesn't. 问题在于,最后一个文件(Tommy.o)正确加载,而第一个文件(Lilothyn.o)无法正确加载。 As you can see the two are seemingly similar. 如您所见,两者看起来很相似。

My code is extensive so i'll post the relevant parts only. 我的代码很广泛,所以我只发布相关部分。

Source.cpp: Source.cpp:

int displayFillThread(SDL_Renderer *renderer, SDL_Window *window, bool *_end) throw()
{
    std::cout << "Thread initializing..." << std::endl;
    SDL_Texture *texture = getTextureFromStream(&binary_Lilothyn_jpg_start, binary_Lilothyn_jpg_size, window, renderer);

    if (texture == NULL)
    {
        std::cout << "Thread: Failed to load image - " << SDL_GetError() << std::endl;
        return 1;
    }

    std::cout << "Thread initialized!" << std::endl;

    for(int i= 10; !*_end && i < 400; i+= 100)
        for(int j= 10; !*_end && j < 400; j+= 100)
        {
            SDL_Delay(100);
            AddTextureToRederer(renderer, texture, i, j, 100, 100);
            SDL_RenderPresent(renderer);
        }
    return 0;
}


SDL_Texture *getTextureFromStream(char binary[], unsigned int binary_size, SDL_Window *window, SDL_Renderer *renderer) throw()
{
    std::cout << "Starting getTextureFromJPEGStream!" << std::endl;
//  char* st = loadFileObject(binary_start, binary_end);

    SDL_RWops *rw = SDL_RWFromConstMem(binary, binary_size);

    std::cout << "rw loaded!" << std::endl;

    SDL_Surface *tmpSurf = IMG_Load_RW(rw, 0);
    //SDL_Surface *tmpSurf = SDL_CreateRGBSurfaceFrom(Lilothyn_jpg, 123, 102, 24, 96, 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
    if (tmpSurf != NULL)
    {
        SDL_Surface *surf = SDL_ConvertSurfaceFormat(tmpSurf, SDL_GetWindowPixelFormat(window), 0);
        if (surf != NULL)
        {
            SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surf);

            SDL_FreeSurface(surf);

            std::cout << "tmpSurf loaded!" << std::endl;

            return texture;
        }//*/

//      SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, tmpSurf);

        SDL_FreeSurface(tmpSurf);

        std::cout << "surf load failed!" << std::endl;

        return NULL;
    }

    std::cout << "tmpSurf load failed!" << std::endl;

    return NULL;
}

int main(int argc, char** argv)
{
    if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
    {
        std::cout << "SDL init Error: " << SDL_GetError() << std::endl;
        exit(1);
    }

    SDL_Window *window = SDL_CreateWindow("SDL_Test", 0, 0, _SCREEN_WIDTH_, _SCREEN_HEIGHT_, SDL_WINDOW_OPENGL | SDL_RENDERER_ACCELERATED);  //  SDL_WINDOW_FULLSCREEN |
    if (window == NULL)
    {
        std::cout << "Window init Error: " << SDL_GetError() << std::endl;
        exit(1);
    }

    SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0);

    if (renderer == NULL)
    {
        SDL_ShowSimpleMessageBox(0, "Renderer init error", SDL_GetError(), window);
    }

    //SDL_Texture *texture = getTextureFromJPEGStream(binary_Tommy_jpg_start, binary_Tommy_jpg_end, binary_Tommy_jpg_size, window, renderer);

    SDL_Texture *texture = getTextureFromStream(&binary_Tommy_jpg_start, binary_Tommy_jpg_size, window, renderer);
            //getTextureFromImage("Resources/Tommy.jpg", window, renderer);
    if (texture == NULL)
    {
        SDL_ShowSimpleMessageBox(0, "Background Texture init error", SDL_GetError(), window);
        return 1;
    }

    SDL_RenderCopy(renderer, texture, NULL, NULL);
    //AddTextureToRederer(renderer, FTex, 10, 10, 100, 100);

    SDL_RenderPresent(renderer);

    SDL_Event event;
    bool _end = false;

    std::cout << "Starting Thread!" << std::endl;
    std::thread thread1;
    try
    {
        thread1 = std::thread(displayFillThread, renderer, window, &_end);
        std::cout << "Thread loaded!" << std::endl;
    }
    catch(std::exception& e)
    {
        std::cout << "Thread load failed: " << e.what() << std::endl;
        return 1;
    }

    std::cout << "main while starting!" << std::endl;
    while(!_end)
    {
//...

Source.h: Source.h:

#ifndef SOURCE_H_
#define SOURCE_H_

static int _SCREEN_WIDTH_ = 1024;
static int _SCREEN_HEIGHT_ = 800;

extern char binary_Tommy_jpg_start;
extern unsigned int binary_Tommy_jpg_size;
extern char binary_Lilothyn_jpg_start;
extern unsigned int binary_Lilothyn_jpg_size;


int displayFillThread(SDL_Renderer *renderer, SDL_Window *window, bool *_end) throw();

SDL_Texture *getTextureFromStream(char binary[], unsigned int binary_size, SDL_Window *window, SDL_Renderer *renderer) throw();
//...

And the output: 并输出:

Starting getTextureFromJPEGStream!
rw loaded!
tmpSurf loaded!
Starting Thread!
Thread loaded!
Thread initializing...
main while starting!

Note that it didn't write the second "getTextureFromJPEGStream!" 请注意,它没有写第二个“ getTextureFromJPEGStream!”。 neither did it appear to have thrown an exception. 它似乎也没有引发异常。 It compiles with no problems whatsoever so, is it possible that the Lilothyn.o file is being created corrupted? 它可以毫无问题地进行编译,是否可能已损坏Lilothyn.o文件? (I have rebuilt it more than once) And/or maybe the linker isn't linking correctly? (我已经多次重建了它)和/或链接器未正确链接? While executing, the program simple stops responding after loading the 1st image, while trying to load the 2nd. 在执行过程中,该程序简单地在加载第一个图像后停止响应,而尝试加载第二个图像。 Thank you for the replies. 感谢您的答复。

I've solved this now, the problem was the types used on the .o file. 我现在已经解决了这个问题,问题是.o文件上使用的类型。 New code is as follows. 新代码如下。

Source.h: Source.h:

extern uint8_t binary_Lilothyn_jpg_start[];
extern uint8_t binary_Lilothyn_jpg_size[];

Source.cpp Source.cpp

SDL_Texture *getTextureFromStream(uint8_t binary[], uint8_t binary_size[], SDL_Window *window, SDL_Renderer *renderer) throw()
{
    size_t converted_size = (size_t)((void *)binary_size);
    SDL_Surface *tmpSurf = IMG_Load_RW(SDL_RWFromConstMem(binary, converted_size), 0);
    if (tmpSurf != NULL)
    {
//...

Thanks to all the viewers, I hope this helps! 感谢所有观众,希望对您有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM