X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/d732b430ccc1d1a78e666f16553b2e3c5dd131a8..31640ef495075cd82226f08ab961493fa9ff0554:/lib/gdi/picload.cpp diff --git a/lib/gdi/picload.cpp b/lib/gdi/picload.cpp index 2ef901f5..c162f89d 100644 --- a/lib/gdi/picload.cpp +++ b/lib/gdi/picload.cpp @@ -254,34 +254,33 @@ static unsigned char *bmp_load(const char *file, int *x, int *y) static unsigned char *png_load(const char *file, int *ox, int *oy) { - //static const png_color_16 my_background = {0, 0, 0, 0, 0}; - png_structp png_ptr; - png_infop info_ptr; + static const png_color_16 my_background = {0, 0, 0, 0, 0}; + png_uint_32 width, height; unsigned int i; int bit_depth, color_type, interlace_type; - int number_passes, pass; - png_byte * fbptr; - FILE * fh; + png_byte *fbptr; + FILE *fh; - if (!(fh = fopen(file, "rb"))) return NULL; + if (!(fh = fopen(file, "rb"))) + return NULL; - png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (png_ptr == NULL) return NULL; - info_ptr = png_create_info_struct(png_ptr); + png_infop info_ptr = png_create_info_struct(png_ptr); if (info_ptr == NULL) { png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL); - fclose(fh); + fclose(fh); return NULL; } if (setjmp(png_ptr->jmpbuf)) { png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); - fclose(fh); - return 0; + fclose(fh); + return NULL; } png_init_io(png_ptr, fh); @@ -296,33 +295,25 @@ static unsigned char *png_load(const char *file, int *ox, int *oy) if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_to_rgb(png_ptr); - number_passes = png_set_interlace_handling(png_ptr); + int number_passes = png_set_interlace_handling(png_ptr); png_read_update_info(png_ptr, info_ptr); - int bpp = png_get_rowbytes(png_ptr, info_ptr)/width; - if ((bpp !=4) && (bpp !=3)) + if (width * 3 != png_get_rowbytes(png_ptr, info_ptr)) { - eDebug("[PNG] Error processing"); - return 0; - } - - if (width * height > 1000000) // 1000x1000 or equiv. - { - eDebug("[png_load] image size is %d x %d, which is \"too large\".", (int)width, (int)height); - png_read_end(png_ptr, info_ptr); + eDebug("[Picload] Error processing"); png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); fclose(fh); - return 0; + return NULL; } - unsigned char *pic_buffer = new unsigned char[width * height * bpp]; + unsigned char *pic_buffer = new unsigned char[height * width * 3]; *ox=width; *oy=height; - for(pass = 0; pass < number_passes; pass++) + for(int pass = 0; pass < number_passes; pass++) { fbptr = (png_byte *)pic_buffer; - for (i = 0; i < height; i++, fbptr += width * bpp) + for (i = 0; i < height; i++, fbptr += width * 3) png_read_row(png_ptr, fbptr, NULL); } png_read_end(png_ptr, info_ptr); @@ -569,19 +560,29 @@ ePicLoad::ePicLoad() m_conf.thumbnailsize = 180; } -ePicLoad::~ePicLoad() +void ePicLoad::waitFinished() { msg_thread.send(Message(Message::quit)); kill(); +} +ePicLoad::~ePicLoad() +{ + if (threadrunning) + waitFinished(); if(m_filepara != NULL) delete m_filepara; } +void ePicLoad::thread_finished() +{ + threadrunning=false; +} void ePicLoad::thread() { hasStarted(); + threadrunning=true; nice(4); runLoop(); } @@ -759,7 +760,6 @@ void ePicLoad::gotMessage(const Message &msg) break; case Message::decode_finished: // called from main thread //eDebug("[Picload] decode finished... %s", m_filepara->file); - threadrunning=false; if(m_filepara->callback) { PictureData(m_filepara->picinfo.c_str()); @@ -778,9 +778,9 @@ void ePicLoad::gotMessage(const Message &msg) } } -int ePicLoad::startThread(int what, const char *file, int x, int y) +int ePicLoad::startThread(int what, const char *file, int x, int y, bool async) { - if(threadrunning && m_filepara != NULL) + if(async && threadrunning && m_filepara != NULL) { eDebug("[Picload] thread running"); m_filepara->callback = false; @@ -824,50 +824,28 @@ int ePicLoad::startThread(int what, const char *file, int x, int y) return 1; } - threadrunning=true; - if(what==1) - msg_thread.send(Message(Message::decode_Pic)); + if (async) { + if(what==1) + msg_thread.send(Message(Message::decode_Pic)); + else + msg_thread.send(Message(Message::decode_Thumb)); + run(); + } + else if (what == 1) + decodePic(); else - msg_thread.send(Message(Message::decode_Thumb)); - run(); + decodeThumb(); return 0; } -RESULT ePicLoad::startDecode(const char *file, int x, int y) +RESULT ePicLoad::startDecode(const char *file, int x, int y, bool async) { - return startThread(1, file, x, y); + return startThread(1, file, x, y, async); } -RESULT ePicLoad::getThumbnail(const char *file, int x, int y) +RESULT ePicLoad::getThumbnail(const char *file, int x, int y, bool async) { - return startThread(0, file, x, y); -} - -RESULT ePicLoad::setPara(PyObject *val) -{ - if (!PyList_Check(val)) - return 0; - if (PyList_Size(val) < 6) - return 0; - - m_conf.max_x = PyInt_AsLong( PyList_GET_ITEM(val, 0)); - m_conf.max_y = PyInt_AsLong( PyList_GET_ITEM(val, 1)); - m_conf.aspect_ratio = PyFloat_AsDouble( PyList_GET_ITEM(val, 2)); - m_conf.usecache = PyInt_AsLong( PyList_GET_ITEM(val, 3)); - m_conf.resizetype = PyInt_AsLong( PyList_GET_ITEM(val, 4)); - const char *bg_str = PyString_AsString( PyList_GET_ITEM(val, 5)); - - if(bg_str[0] == '#' && strlen(bg_str)==9) - { - int bg = strtoul(bg_str+1, NULL, 16); - m_conf.background[0] = bg&0xFF; //BB - m_conf.background[1] = (bg>>8)&0xFF; //GG - m_conf.background[2] = (bg>>16)&0xFF; //RR - m_conf.background[3] = bg>>24; //AA - } - - eDebug("[Picload] setPara max-X=%d max-Y=%d aspect_ratio=%lf cache=%d resize=%d bg=#%02X%02X%02X%02X", m_conf.max_x, m_conf.max_y, m_conf.aspect_ratio, (int)m_conf.usecache, (int)m_conf.resizetype, m_conf.background[3], m_conf.background[2], m_conf.background[1], m_conf.background[0]); - return 1; + return startThread(0, file, x, y, async); } PyObject *ePicLoad::getInfo(const char *filename) @@ -935,6 +913,7 @@ PyObject *ePicLoad::getInfo(const char *filename) int ePicLoad::getData(ePtr &result) { + result = 0; if(m_filepara->pic_buffer == NULL) return 0; m_filepara->pic_buffer = conv24to32(m_filepara->pic_buffer, m_filepara->ox * m_filepara->oy); @@ -1015,3 +994,69 @@ int ePicLoad::getData(ePtr &result) return 0; } + +RESULT ePicLoad::setPara(PyObject *val) +{ + if (!PySequence_Check(val)) + return 0; + if (PySequence_Size(val) < 7) + return 0; + else { + ePyObject fast = PySequence_Fast(val, ""); + m_conf.max_x = PyInt_AsLong( PySequence_Fast_GET_ITEM(fast, 0)); + m_conf.max_y = PyInt_AsLong( PySequence_Fast_GET_ITEM(fast, 1)); + m_conf.aspect_ratio = (double)PyInt_AsLong( PySequence_Fast_GET_ITEM(fast, 2)) / PyInt_AsLong(PySequence_Fast_GET_ITEM(fast, 3)); + m_conf.usecache = PyInt_AsLong( PySequence_Fast_GET_ITEM(fast, 4)); + m_conf.resizetype = PyInt_AsLong( PySequence_Fast_GET_ITEM(fast, 5)); + const char *bg_str = PyString_AsString( PySequence_Fast_GET_ITEM(fast, 6)); + + if(bg_str[0] == '#' && strlen(bg_str)==9) + { + int bg = strtoul(bg_str+1, NULL, 16); + m_conf.background[0] = bg&0xFF; //BB + m_conf.background[1] = (bg>>8)&0xFF; //GG + m_conf.background[2] = (bg>>16)&0xFF; //RR + m_conf.background[3] = bg>>24; //AA + } + eDebug("[Picload] setPara max-X=%d max-Y=%d aspect_ratio=%lf cache=%d resize=%d bg=#%02X%02X%02X%02X", m_conf.max_x, m_conf.max_y, m_conf.aspect_ratio, (int)m_conf.usecache, (int)m_conf.resizetype, m_conf.background[3], m_conf.background[2], m_conf.background[1], m_conf.background[0]); + } + return 1; +} + +//------------------------------------------------------------------------------------ + +//for old plugins +SWIG_VOID(int) loadPic(ePtr &result, std::string filename, int x, int y, int aspect, int resize_mode, int rotate, int background, std::string cachefile) +{ + long asp1, asp2; + result = 0; + eDebug("deprecated loadPic function used!!! please use the non blocking version! you can see demo code in Pictureplayer plugin... this function is removed in the near future!"); + ePicLoad mPL; + + switch(aspect) + { + case 1: asp1 = 16*576, asp2 = 9*720; break; //16:9 + case 2: asp1 = 16*576, asp2 = 10*720; break; //16:10 + case 3: asp1 = 5*576, asp2 = 4*720; break; //5:4 + default: asp1 = 4*576, asp2 = 3*720; break; //4:3 + } + + ePyObject tuple = PyTuple_New(7); + PyTuple_SET_ITEM(tuple, 0, PyLong_FromLong(x)); + PyTuple_SET_ITEM(tuple, 1, PyLong_FromLong(y)); + PyTuple_SET_ITEM(tuple, 2, PyLong_FromLong(asp1)); + PyTuple_SET_ITEM(tuple, 3, PyLong_FromLong(asp2)); + PyTuple_SET_ITEM(tuple, 4, PyLong_FromLong(0)); + PyTuple_SET_ITEM(tuple, 5, PyLong_FromLong(resize_mode)); + if(background) + PyTuple_SET_ITEM(tuple, 6, PyString_FromString("#ff000000")); + else + PyTuple_SET_ITEM(tuple, 6, PyString_FromString("#00000000")); + + mPL.setPara(tuple); + + if(!mPL.startDecode(filename.c_str(), 0, 0, false)) + mPL.getData(result); + + return 0; +}