diff --git a/imanox-chroma-matting/main.cpp b/imanox-chroma-matting/main.cpp index b4392ec..ac9a93c 100644 --- a/imanox-chroma-matting/main.cpp +++ b/imanox-chroma-matting/main.cpp @@ -1,9 +1,70 @@ #include +#include using namespace std; int main() { + loadJpg("..\img\foregrounds\1.jpg") cout << "Hello world!" << endl; return 0; } + +int loadJpg(const char* Name) { + unsigned char a, r, g, b; + int width, height; + struct jpeg_decompress_struct cinfo; + struct jpeg_error_mgr jerr; + + FILE * infile; /* source file */ + JSAMPARRAY pJpegBuffer; /* Output row buffer */ + int row_stride; /* physical row width in output buffer */ + if ((infile = fopen(Name, "rb")) == NULL) { + fprintf(stderr, "can't open %s\n", Name); + return 0; + } + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_decompress(&cinfo); + jpeg_stdio_src(&cinfo, infile); + (void) jpeg_read_header(&cinfo, TRUE); + (void) jpeg_start_decompress(&cinfo); + width = cinfo.output_width; + height = cinfo.output_height; + + unsigned char * pDummy = new unsigned char [width*height*4]; + unsigned char * pTest = pDummy; + if (!pDummy) { + printf("NO MEM FOR JPEG CONVERT!\n"); + return 0; + } + row_stride = width * cinfo.output_components; + pJpegBuffer = (*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, pJpegBuffer, 1); + for (int x = 0; x < width; x++) { + a = 0; // alpha value is not supported on jpg + r = pJpegBuffer[0][cinfo.output_components * x]; + if (cinfo.output_components > 2) { + g = pJpegBuffer[0][cinfo.output_components * x + 1]; + b = pJpegBuffer[0][cinfo.output_components * x + 2]; + } else { + g = r; + b = r; + } + *(pDummy++) = b; + *(pDummy++) = g; + *(pDummy++) = r; + *(pDummy++) = a; + } + } + fclose(infile); + (void) jpeg_finish_decompress(&cinfo); + jpeg_destroy_decompress(&cinfo); + + BMap = (int*)pTest; + Height = height; + Width = width; + Depth = 32; +} diff --git a/img/foregrounds/1.jpg b/img/foregrounds/1.jpg new file mode 100644 index 0000000..dfd4d14 Binary files /dev/null and b/img/foregrounds/1.jpg differ