• soft reboot


    makefile 中加上-o2 ,程序居然重启!!!!
    过度优化的副作用!
    过度优化导致指令乱序!

    // 这些和错误处理有关,不用管
    struct my_error_mgr {
        struct jpeg_error_mgr pub;  /* "public" fields */
     
        jmp_buf setjmp_buffer;  /* for return to caller */
    };
     
    typedef struct my_error_mgr * my_error_ptr;
     
    METHODDEF(void) my_error_exit(j_common_ptr cinfo)
    {
        my_error_ptr myerr = (my_error_ptr)cinfo->err;
        (*cinfo->err->output_message) (cinfo);
        longjmp(myerr->setjmp_buffer, 1);
    }
     
    // 读取图像的函数
    // 我添加了一个参数,是我库里的zMatrix类对象,用于保存读取的图片数据
    GLOBAL(int) read_JPEG_file(char * filename, z::Matrix8u & img)
    {
        struct jpeg_decompress_struct cinfo;
        struct my_error_mgr jerr;
        FILE * infile;      
        JSAMPARRAY buffer;      
        int row_stride; 
     
        if ((infile = fopen(filename, "rb")) == NULL) {
            fprintf(stderr, "can't open %s\n", filename);
            return 0;
        }
        cinfo.err = jpeg_std_error(&jerr.pub);
        jerr.pub.error_exit = my_error_exit;
        if (setjmp(jerr.setjmp_buffer)) {
            jpeg_destroy_decompress(&cinfo);
            fclose(infile);
            return 0;
        }
        jpeg_create_decompress(&cinfo);
     
        jpeg_stdio_src(&cinfo, infile);
     
        // 这个函数获取了读取图片的信息,包括图片的高和宽
        (void)jpeg_read_header(&cinfo, TRUE);
        // 在这里添加你自己的代码,获取或用户到图像信息
        img.create(cinfo.image_height, cinfo.image_width, 3);
     
        (void)jpeg_start_decompress(&cinfo);
     
        row_stride = cinfo.output_width * cinfo.output_components;
        buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr)&cinfo, JPOOL_IMAGE, row_stride, 1);
     
        while (cinfo.output_scanline < cinfo.output_height) {
            // 一行一行的读取
            (void)jpeg_read_scanlines(&cinfo, buffer, 1);
     
            // 在这里添加代码获取到图片的像素数据
            // buffer保存了读取的当前行的数据,保存顺序是RGB
            // output_scanline是已经读取过的行数
            for (int i = 0; i < img.cols; ++i) {
                img[cinfo.output_scanline - 1][i * 3 + 2] = buffer[0][i * 3 + 0];
                img[cinfo.output_scanline - 1][i * 3 + 1] = buffer[0][i * 3 + 1];
                img[cinfo.output_scanline - 1][i * 3 + 0] = buffer[0][i * 3 + 2];
            }
        }
     
        (void)jpeg_finish_decompress(&cinfo);
        jpeg_destroy_decompress(&cinfo);
        fclose(infile);
        return 1;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
  • 相关阅读:
    通过数组的指针获得数组个数
    《中华人民共和国网络安全法》
    XSS攻击
    被问到: http 协议和 https 协议的区别怎么办?别慌,这篇文章给你答案
    运维工程师面试总结(含答案)
    C++单例模式
    JAVA学习第十课:java事件处理
    十一、DHT11 温湿度检测(OLED显示)
    jenkins声明式流水线pipline深入学习
    Tomcat的安装和使用
  • 原文地址:https://blog.csdn.net/a379039233/article/details/125510206