⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gxpportqt_immutableimage.cpp

📁 This is a resource based on j2me embedded,if you dont understand,you can connection with me .
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    immutableImage->qpixmap = NULL;    *newImmutableImagePtr = immutableImage;    *creationErrorPtr = IMG_NATIVE_IMAGE_NO_ERROR;}extern "C" void gxpport_render_immutableimage(gxpport_image_native_handle immutableImagePtr, gxpport_mutableimage_native_handle dstMutableImagePtr, const jshort *clip, jint x_dest, jint y_dest) {    _Platform_ImmutableImage* immutableImage =         (_Platform_ImmutableImage*)immutableImagePtr;    QPixmap *qpixmapDst =      gxpportqt_get_mutableimage_pixmap(dstMutableImagePtr);    if (NULL == immutableImage || immutableImage->qimage->isNull()) {        /* not a valid image should not happen, log this */        return;    }    MScreen * mscreen = qteapp_get_mscreen();    QPainter *gc = mscreen->setupGC(-1, -1, clip,                                     (QPaintDevice *)qpixmapDst,                                     0);    if (immutableImage->qimage->hasAlphaBuffer()) {        gc->drawImage(x_dest, y_dest, *immutableImage->qimage);        return;    }    gc->drawPixmap(x_dest, y_dest,        *(gxpportqt_get_immutableimage_pixmap(immutableImagePtr)));}extern "C" void gxpport_render_immutableregion(gxpport_image_native_handle immutableImagePtr, gxpport_mutableimage_native_handle dstMutableImagePtr, const jshort *clip, jint x_dest, jint y_dest,  jint width, jint height, jint x_src, jint y_src, jint transform) {    _Platform_ImmutableImage* immutableImage =         (_Platform_ImmutableImage*)immutableImagePtr;    QPixmap *qpixmapDst =    gxpportqt_get_mutableimage_pixmap(dstMutableImagePtr);    if (NULL == immutableImagePtr || immutableImage->qimage->isNull()) {      /* not a valid image should not happen, log this */        return;    }    MScreen * mscreen = qteapp_get_mscreen();    QPainter *gc = mscreen->setupGC(-1, -1, clip,                                     (QPaintDevice *)qpixmapDst,                                     0);    if (0 == transform) {        gc->drawImage(x_dest, y_dest,                      *immutableImage->qimage,                      x_src, y_src,                      width, height,                      0);        return;    }    QImage image = immutableImage->qimage->copy(x_src, y_src,                                                width, height);    transform_image(&image, transform);        if (!image.isNull()) {        gc->drawImage(x_dest, y_dest, image);    }}extern "C" void gxpport_get_immutable_argb(gxpport_image_native_handle immutableImagePtr, jint* rgbBuffer, int offset, int scanLength, int x, int y, int width, int height, img_native_error_codes* errorPtr) {    _Platform_ImmutableImage* immutableImage =         (_Platform_ImmutableImage*)immutableImagePtr;    if (NULL == immutableImage || immutableImage->qimage->isNull()) {      /* not a valid image should not happen, log this */      return ;    }    QImage   image;    int      curOffset = offset;      /* current offset in output array */    int      curX, curY;    unsigned int r,g,b;    QRgb     pixel;    if (IMAGE_DEPTH != immutableImage->qimage->depth()) {        image = immutableImage->qimage->convertDepth(IMAGE_DEPTH);    } else {        image = *immutableImage->qimage;    }    if (image.hasAlphaBuffer() == TRUE) {        for (curY = y; curY < y + height; curY++) {            for (curX = x; curX < x + width; curX++) {                                // Obtain the R,G,B                pixel = image.pixel(curX, curY);                                r = qRed(pixel) ;                g = qGreen(pixel);                b = qBlue(pixel);                            rgbBuffer[curOffset] = (qAlpha(pixel) << 24)                    | ((r & 0xff) << 16)                     | ((g & 0xff) << 8)                     |  (b & 0xff);                                curOffset++;            }            curOffset += (scanLength - width);        }            } else {                for (curY = y; curY < y + height; curY++) {            for (curX = x; curX < x + width; curX++) {                                // Obtain the R,G,B                pixel = image.pixel(curX, curY);                                r = qRed(pixel) ;                g = qGreen(pixel);                b = qBlue(pixel);                                rgbBuffer[curOffset] = (0xff << 24)                    | ((r & 0xff) << 16)                     | ((g & 0xff) << 8)                     |  (b & 0xff);                                curOffset++;            }                        curOffset += (scanLength - width);        }            }    *errorPtr = IMG_NATIVE_IMAGE_NO_ERROR;}extern "C"void gxpport_destroy_immutable(gxpport_image_native_handle imagePtr) {    _Platform_ImmutableImage* immutableImage =         (_Platform_ImmutableImage*)imagePtr;    if (NULL != immutableImage) {        if (NULL != immutableImage->qimage) {            int rscSize = ImgRscSize(immutableImage->qimage);            /* Update the resource count */            if (midpDecResourceCount(RSC_TYPE_IMAGE_IMMUT, rscSize) == 0) {                REPORT_ERROR(LC_LOWUI,"Error in updating resource limit for"                             " Immutable image");            }            delete immutableImage->qimage;        }        if (NULL != immutableImage->qpixmap) {            delete immutableImage->qpixmap;        }	midpFree(immutableImage);    }}extern "C" void gxpport_decodeimmutable_to_platformbuffer(unsigned char* srcBuffer, long length,  unsigned char** ret_dataBuffer, long* ret_length, img_native_error_codes* creationErrorPtr) {    imgdcd_image_format format;    MIDP_ERROR err;    unsigned int w, h;    err = imgdcd_image_get_info(srcBuffer, (unsigned int)length,			       &format, &w, &h);        switch (err) {    case MIDP_ERROR_NONE:	break; /* continue */    case MIDP_ERROR_IMAGE_CORRUPTED:	*creationErrorPtr = IMG_NATIVE_IMAGE_DECODING_ERROR;	return;        default:	*creationErrorPtr = IMG_NATIVE_IMAGE_UNSUPPORTED_FORMAT_ERROR;	return;    }		         switch (format) {    case IMGDCD_IMAGE_FORMAT_RAW:        /* already in RAW format. make a copy */	{	    unsigned char* dataBuffer = (unsigned char*) midpMalloc(length);            	    if (NULL == dataBuffer) {		*creationErrorPtr = IMG_NATIVE_IMAGE_OUT_OF_MEMORY_ERROR;	    } else {                		memcpy(dataBuffer, srcBuffer, length);                		*ret_dataBuffer = dataBuffer;		*ret_length = length;		*creationErrorPtr = IMG_NATIVE_IMAGE_NO_ERROR;	    }	}        break;    case IMGDCD_IMAGE_FORMAT_JPEG:    case IMGDCD_IMAGE_FORMAT_PNG:        {            QImage qimage;                        if (qimage.loadFromData((uchar*)srcBuffer,                                     (unsigned int)length)) {                int imgWidth  = qimage.width();                int imgHeight = qimage.height();                                if ((0 == imgWidth) || (0 == imgHeight)) {                    *creationErrorPtr = IMG_NATIVE_IMAGE_DECODING_ERROR;                } else {                    QImage image;                    if (IMAGE_DEPTH != qimage.depth()) {                        image = qimage.convertDepth(IMAGE_DEPTH);                    } else {                        image = qimage;                    }                                        *ret_length = offsetof(imgdcd_image_buffer_raw, data)				+ image.numBytes();                    imgdcd_image_buffer_raw *dataBuffer =			(imgdcd_image_buffer_raw *) midpMalloc(*ret_length);                                        if (NULL == dataBuffer) {                        *creationErrorPtr = IMG_NATIVE_IMAGE_OUT_OF_MEMORY_ERROR;                    } else {                        dataBuffer->width    = (unsigned int)imgWidth;                        dataBuffer->height   = (unsigned int)imgHeight;                        dataBuffer->hasAlpha = (unsigned int)image.hasAlphaBuffer();                                                memcpy(dataBuffer->header, imgdcd_raw_header, 4);                        memcpy(dataBuffer->data, image.bits(), image.numBytes());                                                *ret_dataBuffer = (unsigned char *)dataBuffer;                        *creationErrorPtr = IMG_NATIVE_IMAGE_NO_ERROR;                    }                }            } else {                *creationErrorPtr = IMG_NATIVE_IMAGE_DECODING_ERROR;            }        }        break;        default:        *creationErrorPtr = IMG_NATIVE_IMAGE_UNSUPPORTED_FORMAT_ERROR;        break;    } /* switch (format) */}extern "C" void gxpport_loadimmutable_from_platformbuffer(unsigned char* srcBuffer, int length, jboolean isStatic, int* ret_imgWidth, int* ret_imgHeight, gxpport_image_native_handle *newImmutableImagePtr, img_native_error_codes* creationErrorPtr) {    int rscSize;    imgdcd_image_buffer_raw* dataBuffer = (imgdcd_image_buffer_raw*)srcBuffer;    /* Check resource limit */    rscSize = ImgRegionRscSize(NULL, dataBuffer->width, dataBuffer->height);    if (midpCheckResourceLimit(RSC_TYPE_IMAGE_IMMUT, rscSize) == 0) {        /* Exceed Resource limit */        *creationErrorPtr = IMG_NATIVE_IMAGE_RESOURCE_LIMIT;        return;    }    _Platform_ImmutableImage* immutableImage =        (_Platform_ImmutableImage*)midpMalloc(sizeof(_Platform_ImmutableImage));    if (immutableImage == NULL) {        *creationErrorPtr = IMG_NATIVE_IMAGE_OUT_OF_MEMORY_ERROR;        return;    }    if (!load_raw(&immutableImage->qimage,                dataBuffer,                length, isStatic,                ret_imgWidth, ret_imgHeight)) {	midpFree(immutableImage);        *creationErrorPtr = IMG_NATIVE_IMAGE_DECODING_ERROR;        return;    }    /* Image creation succeeds */    if (midpIncResourceCount(RSC_TYPE_IMAGE_IMMUT, rscSize) == 0) {        REPORT_ERROR(LC_LOWUI, "Error in updating resource limit"                     " for Immutable image");    }                immutableImage->marker = 7;    immutableImage->qpixmap = NULL;    *newImmutableImagePtr = immutableImage;    *creationErrorPtr = IMG_NATIVE_IMAGE_NO_ERROR;}extern "C" QPixmap* gxpportqt_get_immutableimage_pixmap(gxpport_image_native_handle immutableImagePtr) {    _Platform_ImmutableImage* immutableImage =         (_Platform_ImmutableImage*)immutableImagePtr;    if (NULL == immutableImage || NULL == immutableImage->qimage ||        immutableImage->qimage->isNull()) {        return NULL;    }    if (NULL != immutableImage->qpixmap) {        return immutableImage->qpixmap;    }    immutableImage->qpixmap = new QPixmap();    if (NULL == immutableImage->qpixmap) {        return NULL;    }                immutableImage->qpixmap->convertFromImage(*immutableImage->qimage);    if (!immutableImage->qpixmap->isNull()) {        return immutableImage->qpixmap;    }    delete immutableImage->qpixmap;    immutableImage->qpixmap = NULL;    return NULL;}/* * loads a RAW image into a QImage  * * @param qimage pointer to destination QImage * @param rawImageBuffer source RAW image * @param length in bytes of the input image * @param isStatic true if the rawImageBuffer is static * @return ret_Width the width of the decoded image * @return ret_Height the height of the decoded image */static bool load_raw(QImage** qimage, imgdcd_image_buffer_raw* rawImageBuffer, 	      unsigned int length,             jboolean isStatic, int* ret_Width, int* ret_Height) {    bool retVal = FALSE;        /* Check buffer size */    if (offsetof(imgdcd_image_buffer_raw, data)	+ rawImageBuffer->width * rawImageBuffer->height * 4	== length) {	QImage* localQimage = new QImage(rawImageBuffer->data,                                    rawImageBuffer->width,				    rawImageBuffer->height,                                     IMAGE_DEPTH,                                    NULL, 0,                                     QImage::IgnoreEndian);    	if (localQimage != NULL) {            if (!localQimage->isNull()) {                localQimage->setAlphaBuffer(rawImageBuffer->hasAlpha);                if (isStatic) {                    *qimage = localQimage;                } else {                    *qimage = new QImage(localQimage->copy());                    delete localQimage;                }                if (*qimage != NULL) {                    *ret_Width  = (*qimage)->width();                    *ret_Height = (*qimage)->height();                    if ((0 != *ret_Width) && (0 != *ret_Height)) {                        retVal = TRUE;                    } else {                        delete *qimage;                    }                }            }	}    }         return retVal;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -