TEST_F(ImageDocumentTest, LargeImageScalesDown) { createDocument(25, 30); EXPECT_EQ(25, imageWidth()); EXPECT_EQ(25, imageHeight()); createDocument(35, 20); EXPECT_EQ(20, imageWidth()); EXPECT_EQ(20, imageHeight()); }
TEST_F(ImageDocumentTest, InitialZoomDoesNotAffectScreenFit) { createDocumentWithoutLoadingImage(20, 10); setPageZoom(2.f); loadImage(); EXPECT_EQ(10, imageWidth()); EXPECT_EQ(10, imageHeight()); document().imageClicked(4, 4); EXPECT_EQ(50, imageWidth()); EXPECT_EQ(50, imageHeight()); }
TEST_F(ImageDocumentTest, ZoomingDoesNotChangeRelativeSize) { createDocument(75, 75); setPageZoom(0.5f); document().windowSizeChanged(); EXPECT_EQ(50, imageWidth()); EXPECT_EQ(50, imageHeight()); setPageZoom(2.f); document().windowSizeChanged(); EXPECT_EQ(50, imageWidth()); EXPECT_EQ(50, imageHeight()); }
TEST_F(ImageDocumentTest, ImageScalesDownWithDsf) { createDocumentWithoutLoadingImage(20, 30); setWindowToViewportScalingFactor(2.f); loadImage(); EXPECT_EQ(10, imageWidth()); EXPECT_EQ(10, imageHeight()); }
void AdeniumRender::renderPerspective(BaseCamera * camera, BvhTriangleSystem * tri) { float camp[2]; camp[0] = camera->frameWidth(); camp[1] = camera->aspectRatio(); adetrace::setCameraProp(camp); void * internalNodeChildIndex = tri->internalNodeChildIndices(); void * internalNodeAabbs = tri->internalNodeAabbs(); void * indirection = tri->primitiveHash(); void * pix = m_deviceRgbzPix->map(); void * vertices = tri->deviceTretradhedronIndices(); void * points = tri->deviceX(); adetrace::renderImage((float4 *)pix, imageWidth(), imageHeight(), (int2 *)internalNodeChildIndex, (Aabb *)internalNodeAabbs, (KeyValuePair *)indirection, (int4 *)vertices, (float3 *)points, 0); CudaBase::CheckCudaError(" render persp image"); m_deviceRgbzPix->unmap(); }
void QvisOpacitySlider::paintEvent(QPaintEvent *) { QPainter p(this); int mid = thickness()/2 + sliderLength() / 8; // Draw the gradient pixmap. if(gradientImage == 0) createGradientImage(); p.drawImage(0, tickOffset, *gradientImage); // Draw the groove on which the slider slides. drawSliderGroove(&p, 0, tickOffset, imageWidth(), thickness(), mid); // Figure out the interval between the tick marks. int interval = tickInt; if(interval <= 0) { interval = singleStep(); if(positionFromValue(interval) - positionFromValue(0) < 3) interval = pageStep(); } // Draw the tick marks. p.fillRect(0, 0, imageWidth(), tickOffset, palette().brush(QPalette::Background)); p.fillRect(0, tickOffset + thickness(), imageWidth(), height(), palette().brush(QPalette::Background)); drawTicks(&p, palette(), 0, tickOffset - 2, interval); // Draw the slider paintSlider(&p, palette(), sliderRect()); // Draw the value text. paintValueText(&p, palette(), imageWidth(), height()); // If this widget has focus, draw the focus rectangle. if(hasFocus()) { QStyleOptionFocusRect so; so.initFrom(this); style()->drawPrimitive(QStyle::PE_FrameFocusRect, &so, &p); } }
void AdeniumRender::reset() { m_deviceRgbzPix->create(numPixels() * 16); int imgs[2]; imgs[0] = imageWidth(); imgs[1] = imageHeight(); adetrace::setImageSize(imgs); void * pix = m_deviceRgbzPix->map(); adetrace::resetImage((float4 *)pix, (uint)numPixels()); CudaBase::CheckCudaError(" reset image"); m_deviceRgbzPix->unmap(); }
void QvisOpacitySlider::createGradientImage() { // Create the pixmap. int w = imageWidth(); int h = height() - tickOffset; gradientImage = new QImage(w, h, QImage::Format_RGB32); QBrush brush(palette().window()); QPainter paint(gradientImage); if(!brush.textureImage().isNull()) { // Paint the background into the pixmap. paint.fillRect(0, 0, w, h, brush); for(int i = 0; i < w; ++i) { float t = float(i) / float(w - 1); float omt = 1.f - t; int rc, gc, bc; for(int j = 0; j < h; ++j) { // Alpha blend with the pixel that's there already. QRgb p = gradientImage->pixel(i, j); rc = int(omt * float(qRed(p)) + t * float(gradientColor.red())); rc = (rc > 255) ? 255 : rc; gc = int(omt * float(qGreen(p)) + t * float(gradientColor.green())); gc = (gc > 255) ? 255 : gc; bc = int(omt * float(qBlue(p)) + t * float(gradientColor.blue())); bc = (bc > 255) ? 255 : bc; gradientImage->setPixel(i, j, qRgb(rc, gc, bc)); } } } else { QLinearGradient grad(QPointF(0.,0.), QPointF(1.,0.)); grad.setCoordinateMode(QGradient::ObjectBoundingMode); grad.setColorAt(0., palette().color(QPalette::Background)); grad.setColorAt(1., gradientColor); QBrush gradBrush(grad); paint.fillRect(0, 0, w, h, gradBrush); } // If the widget is disabled then draw a checkerboard over it. if(!isEnabled()) { QBrush brush2(palette().window()); brush2.setStyle(Qt::Dense6Pattern); paint.fillRect(rect(), brush2); } }
QRect Canvas::calcSelectedArea() const { int x = 0, y = 0, w = 0, h = 0; if (d->rubber && d->rubber->isVisible()) { QRect r(d->rubber->boundingRect().toRect()); if (r.isValid()) { r.translate((int)d->rubber->x(), (int)d->rubber->y()); x = (int)((double)r.x() / layout()->zoomFactor()); y = (int)((double)r.y() / layout()->zoomFactor()); w = (int)((double)r.width() / layout()->zoomFactor()); h = (int)((double)r.height() / layout()->zoomFactor()); x = qMin(imageWidth(), qMax(x, 0)); y = qMin(imageHeight(), qMax(y, 0)); w = qMin(imageWidth(), qMax(w, 0)); h = qMin(imageHeight(), qMax(h, 0)); // Avoid empty selection by rubberband - at least mark one pixel // At high zoom factors, the rubberband may operate at subpixel level! if (w == 0) { w = 1; } if (h == 0) { h = 1; } } } return QRect(x, y, w, h); }
const unsigned char *V4LCamera::getFrame() { unsigned char *ret; if (!isOK()) return testpattern(); if (use_mmap_) { if (0) printf("VIDIOCSYNC frame %u\n", mmap_nextframe_); if (ioctl(fd_, VIDIOCSYNC, &mmap_nextframe_) == -1) { failed_ = true; perror("VIDIOSYNC failed"); } ret = frameptrs_[mmap_nextframe_]; mmap_nextframe_ = (mmap_nextframe_ + 1) % mmap_frames_; struct video_mmap vidmmap; vidmmap.frame = mmap_nextframe_; vidmmap.height = imageHeight(); vidmmap.width = imageWidth(); vidmmap.format = VIDEO_PALETTE_YUV420P; if (0) printf("vidmmap.frame=%u height=%d width=%d format=%u\n", vidmmap.frame, vidmmap.height, vidmmap.width, vidmmap.format); if (ioctl(fd_, VIDIOCMCAPTURE, &vidmmap) == -1) { perror("VIDIOCMCAPTURE failed - reverting to read"); use_mmap_ = false; buf_ = new unsigned char[imageSize()]; } } else { int r = read(fd_, buf_, imageSize()); if (r != imageSize()) failed_ = true; ret = buf_; } if (recfd_ != -1) writeFrame(ret); return ret; }
void ZLGtkPaintContext::drawImage(int x, int y, const ZLImageData &image, int width, int height, ScalingType type) { GdkPixbuf *imageRef = ((const ZLGtkImageData&)image).pixbuf(); if (imageRef == 0) { return; } const int realWidth = imageWidth(image, width, height, type); const int realHeight = imageHeight(image, width, height, type); GdkPixbuf *scaled = gdk_pixbuf_scale_simple(imageRef, realWidth, realHeight, GDK_INTERP_BILINEAR); if (imageRef != 0) { gdk_pixbuf_render_to_drawable( scaled, myPixmap, 0, 0, 0, x, y - realHeight, realWidth, realHeight, GDK_RGB_DITHER_NONE, 0, 0 ); } gdk_pixbuf_unref(scaled); }
void QvisOpacitySlider::reallyMoveSlider(int newPos) { QRect oldR = sliderRect(); sliderPos = newPos; QRect newR = sliderRect(); // Since sliderRect isn't virtual, I know that oldR and newR // are the same size. if(oldR.left() < newR.left()) oldR.setRight(qMin(oldR.right(), newR.left())); else oldR.setLeft(qMax(oldR.left(), newR.right())); // If we're moving the slider, we have to update the text. int pmw = imageWidth(); QRegion newTextR(pmw, 0, width() - pmw, height()); update(QRegion(oldR) + QRegion(newR) + newTextR); }
void microbit_display_show(microbit_display_obj_t *display, microbit_image_obj_t *image) { mp_int_t w = min(imageWidth(image), 5); mp_int_t h = min(imageHeight(image), 5); mp_int_t x = 0; mp_int_t brightnesses = 0; for (; x < w; ++x) { mp_int_t y = 0; for (; y < h; ++y) { uint8_t pix = imageGetPixelValue(image, x, y); display->image_buffer[x][y] = pix; brightnesses |= (1 << pix); } for (; y < 5; ++y) { display->image_buffer[x][y] = 0; } } for (; x < 5; ++x) { for (mp_int_t y = 0; y < 5; ++y) { display->image_buffer[x][y] = 0; } } display->brightnesses = brightnesses; }
bool JP2KLoader::load(const QString& filePath, DImgLoaderObserver* observer) { readMetadata(filePath, DImg::JPEG); FILE* file = fopen(QFile::encodeName(filePath), "rb"); if (!file) { loadingFailed(); return false; } unsigned char header[9]; if (fread(&header, 9, 1, file) != 1) { fclose(file); loadingFailed(); return false; } unsigned char jp2ID[5] = { 0x6A, 0x50, 0x20, 0x20, 0x0D, }; unsigned char jpcID[2] = { 0xFF, 0x4F }; if (memcmp(&header[4], &jp2ID, 5) != 0 && memcmp(&header, &jpcID, 2) != 0) { // not a jpeg2000 file fclose(file); loadingFailed(); return false; } fclose(file); imageSetAttribute("format", "JP2K"); if (!(m_loadFlags & LoadImageData) && !(m_loadFlags & LoadICCData)) { // libjasper will load the full image in memory already when calling jas_image_decode. // This is bad when scanning. See bugs 215458 and 195583. //FIXME: Use Exiv2 or OpenJPEG to extract this info DMetadata metadata(filePath); QSize size = metadata.getImageDimensions(); if (size.isValid()) { imageWidth() = size.width(); imageHeight() = size.height(); } return true; } // ------------------------------------------------------------------- // Initialize JPEG 2000 API. register long i, x, y; int components[4]; unsigned int maximum_component_depth, scale[4], x_step[4], y_step[4]; unsigned long number_components; jas_image_t* jp2_image = 0; jas_stream_t* jp2_stream = 0; jas_matrix_t* pixels[4]; int init = jas_init(); if (init != 0) { kDebug() << "Unable to init JPEG2000 decoder"; loadingFailed(); return false; } jp2_stream = jas_stream_fopen(QFile::encodeName(filePath), "rb"); if (jp2_stream == 0) { kDebug() << "Unable to open JPEG2000 stream"; loadingFailed(); return false; } jp2_image = jas_image_decode(jp2_stream, -1, 0); if (jp2_image == 0) { jas_stream_close(jp2_stream); kDebug() << "Unable to decode JPEG2000 image"; loadingFailed(); return false; } jas_stream_close(jp2_stream); // some pseudo-progress if (observer) { observer->progressInfo(m_image, 0.1F); } // ------------------------------------------------------------------- // Check color space. int colorModel; switch (jas_clrspc_fam(jas_image_clrspc(jp2_image))) { case JAS_CLRSPC_FAM_RGB: { components[0] = jas_image_getcmptbytype(jp2_image, JAS_IMAGE_CT_RGB_R); components[1] = jas_image_getcmptbytype(jp2_image, JAS_IMAGE_CT_RGB_G); components[2] = jas_image_getcmptbytype(jp2_image, JAS_IMAGE_CT_RGB_B); if ((components[0] < 0) || (components[1] < 0) || (components[2] < 0)) { jas_image_destroy(jp2_image); kDebug() << "Error parsing JPEG2000 image : Missing Image Channel"; loadingFailed(); return false; } number_components = 3; components[3] = jas_image_getcmptbytype(jp2_image, 3); if (components[3] > 0) { m_hasAlpha = true; ++number_components; } colorModel = DImg::RGB; break; } case JAS_CLRSPC_FAM_GRAY: { components[0] = jas_image_getcmptbytype(jp2_image, JAS_IMAGE_CT_GRAY_Y); if (components[0] < 0) { jas_image_destroy(jp2_image); kDebug() << "Error parsing JP2000 image : Missing Image Channel"; loadingFailed(); return false; } number_components = 1; colorModel = DImg::GRAYSCALE; break; } case JAS_CLRSPC_FAM_YCBCR: { components[0] = jas_image_getcmptbytype(jp2_image, JAS_IMAGE_CT_YCBCR_Y); components[1] = jas_image_getcmptbytype(jp2_image, JAS_IMAGE_CT_YCBCR_CB); components[2] = jas_image_getcmptbytype(jp2_image, JAS_IMAGE_CT_YCBCR_CR); if ((components[0] < 0) || (components[1] < 0) || (components[2] < 0)) { jas_image_destroy(jp2_image); kDebug() << "Error parsing JP2000 image : Missing Image Channel"; loadingFailed(); return false; } number_components = 3; components[3] = jas_image_getcmptbytype(jp2_image, JAS_IMAGE_CT_UNKNOWN); if (components[3] > 0) { m_hasAlpha = true; ++number_components; } // FIXME : image->colorspace=YCbCrColorspace; colorModel = DImg::YCBCR; break; } default: { jas_image_destroy(jp2_image); kDebug() << "Error parsing JP2000 image : Colorspace Model Is Not Supported"; loadingFailed(); return false; } } // ------------------------------------------------------------------- // Check image geometry. imageWidth() = jas_image_width(jp2_image); imageHeight() = jas_image_height(jp2_image); for (i = 0; i < (long)number_components; ++i) { if ((((jas_image_cmptwidth(jp2_image, components[i])* jas_image_cmpthstep(jp2_image, components[i])) != (long)imageWidth())) || (((jas_image_cmptheight(jp2_image, components[i])* jas_image_cmptvstep(jp2_image, components[i])) != (long)imageHeight())) || (jas_image_cmpttlx(jp2_image, components[i]) != 0) || (jas_image_cmpttly(jp2_image, components[i]) != 0) || (jas_image_cmptsgnd(jp2_image, components[i]) != false)) { jas_image_destroy(jp2_image); kDebug() << "Error parsing JPEG2000 image : Irregular Channel Geometry Not Supported"; loadingFailed(); return false; } x_step[i] = jas_image_cmpthstep(jp2_image, components[i]); y_step[i] = jas_image_cmptvstep(jp2_image, components[i]); } // ------------------------------------------------------------------- // Get image format. m_hasAlpha = number_components > 3; maximum_component_depth = 0; for (i = 0; i < (long)number_components; ++i) { maximum_component_depth = qMax((long)jas_image_cmptprec(jp2_image,components[i]), (long)maximum_component_depth); pixels[i] = jas_matrix_create(1, ((unsigned int)imageWidth())/x_step[i]); if (!pixels[i]) { jas_image_destroy(jp2_image); kDebug() << "Error decoding JPEG2000 image data : Memory Allocation Failed"; loadingFailed(); return false; } } if (maximum_component_depth > 8) { m_sixteenBit = true; } for (i = 0 ; i < (long)number_components ; ++i) { scale[i] = 1; int prec = jas_image_cmptprec(jp2_image, components[i]); if (m_sixteenBit && prec < 16) { scale[i] = (1 << (16 - jas_image_cmptprec(jp2_image, components[i]))); } } // ------------------------------------------------------------------- // Get image data. uchar* data = 0; if (m_loadFlags & LoadImageData) { if (m_sixteenBit) // 16 bits image. { data = new_failureTolerant(imageWidth()*imageHeight()*8); } else { data = new_failureTolerant(imageWidth()*imageHeight()*4); } if (!data) { kDebug() << "Error decoding JPEG2000 image data : Memory Allocation Failed"; jas_image_destroy(jp2_image); for (i = 0 ; i < (long)number_components ; ++i) { jas_matrix_destroy(pixels[i]); } jas_cleanup(); loadingFailed(); return false; } uint checkPoint = 0; uchar* dst = data; unsigned short* dst16 = (unsigned short*)data; for (y = 0 ; y < (long)imageHeight() ; ++y) { for (i = 0 ; i < (long)number_components; ++i) { int ret = jas_image_readcmpt(jp2_image, (short)components[i], 0, ((unsigned int) y) / y_step[i], ((unsigned int) imageWidth()) / x_step[i], 1, pixels[i]); if (ret != 0) { kDebug() << "Error decoding JPEG2000 image data"; delete [] data; jas_image_destroy(jp2_image); for (i = 0 ; i < (long)number_components ; ++i) { jas_matrix_destroy(pixels[i]); } jas_cleanup(); loadingFailed(); return false; } } switch (number_components) { case 1: // Grayscale. { for (x = 0 ; x < (long)imageWidth() ; ++x) { dst[0] = (uchar)(scale[0]*jas_matrix_getv(pixels[0], x/x_step[0])); dst[1] = dst[0]; dst[2] = dst[0]; dst[3] = 0xFF; dst += 4; } break; } case 3: // RGB. { if (!m_sixteenBit) // 8 bits image. { for (x = 0 ; x < (long)imageWidth() ; ++x) { // Blue dst[0] = (uchar)(scale[2]*jas_matrix_getv(pixels[2], x/x_step[2])); // Green dst[1] = (uchar)(scale[1]*jas_matrix_getv(pixels[1], x/x_step[1])); // Red dst[2] = (uchar)(scale[0]*jas_matrix_getv(pixels[0], x/x_step[0])); // Alpha dst[3] = 0xFF; dst += 4; } } else // 16 bits image. { for (x = 0 ; x < (long)imageWidth() ; ++x) { // Blue dst16[0] = (unsigned short)(scale[2]*jas_matrix_getv(pixels[2], x/x_step[2])); // Green dst16[1] = (unsigned short)(scale[1]*jas_matrix_getv(pixels[1], x/x_step[1])); // Red dst16[2] = (unsigned short)(scale[0]*jas_matrix_getv(pixels[0], x/x_step[0])); // Alpha dst16[3] = 0xFFFF; dst16 += 4; } } break; } case 4: // RGBA. { if (!m_sixteenBit) // 8 bits image. { for (x = 0 ; x < (long)imageWidth() ; ++x) { // Blue dst[0] = (uchar)(scale[2] * jas_matrix_getv(pixels[2], x/x_step[2])); // Green dst[1] = (uchar)(scale[1] * jas_matrix_getv(pixels[1], x/x_step[1])); // Red dst[2] = (uchar)(scale[0] * jas_matrix_getv(pixels[0], x/x_step[0])); // Alpha dst[3] = (uchar)(scale[3] * jas_matrix_getv(pixels[3], x/x_step[3])); dst += 4; } } else // 16 bits image. { for (x = 0 ; x < (long)imageWidth() ; ++x) { // Blue dst16[0] = (unsigned short)(scale[2]*jas_matrix_getv(pixels[2], x/x_step[2])); // Green dst16[1] = (unsigned short)(scale[1]*jas_matrix_getv(pixels[1], x/x_step[1])); // Red dst16[2] = (unsigned short)(scale[0]*jas_matrix_getv(pixels[0], x/x_step[0])); // Alpha dst16[3] = (unsigned short)(scale[3]*jas_matrix_getv(pixels[3], x/x_step[3])); dst16 += 4; } } break; } } // use 0-10% and 90-100% for pseudo-progress if (observer && y >= (long)checkPoint) { checkPoint += granularity(observer, y, 0.8F); if (!observer->continueQuery(m_image)) { delete [] data; jas_image_destroy(jp2_image); for (i = 0 ; i < (long)number_components ; ++i) { jas_matrix_destroy(pixels[i]); } jas_cleanup(); loadingFailed(); return false; } observer->progressInfo(m_image, 0.1 + (0.8 * ( ((float)y)/((float)imageHeight()) ))); } } } // ------------------------------------------------------------------- // Get ICC color profile. if (m_loadFlags & LoadICCData) { jas_iccprof_t* icc_profile = 0; jas_stream_t* icc_stream = 0; jas_cmprof_t* cm_profile = 0; cm_profile = jas_image_cmprof(jp2_image); if (cm_profile != 0) { icc_profile = jas_iccprof_createfromcmprof(cm_profile); } if (icc_profile != 0) { icc_stream = jas_stream_memopen(NULL, 0); if (icc_stream != 0) { if (jas_iccprof_save(icc_profile, icc_stream) == 0) { if (jas_stream_flush(icc_stream) == 0) { jas_stream_memobj_t* blob = (jas_stream_memobj_t*) icc_stream->obj_; QByteArray profile_rawdata; profile_rawdata.resize(blob->len_); memcpy(profile_rawdata.data(), blob->buf_, blob->len_); imageSetIccProfile(profile_rawdata); jas_stream_close(icc_stream); } } } } } if (observer) { observer->progressInfo(m_image, 1.0); } imageData() = data; imageSetAttribute("format", "JP2K"); imageSetAttribute("originalColorModel", colorModel); imageSetAttribute("originalBitDepth", maximum_component_depth); imageSetAttribute("originalSize", QSize(imageWidth(), imageHeight())); jas_image_destroy(jp2_image); for (i = 0 ; i < (long)number_components ; ++i) { jas_matrix_destroy(pixels[i]); } jas_cleanup(); return true; }
bool PGFLoader::save(const QString& filePath, DImgLoaderObserver* const observer) { m_observer = observer; #ifdef WIN32 #ifdef UNICODE HANDLE fd = CreateFile((LPCWSTR)(QFile::encodeName(filePath).constData()), GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0); #else HANDLE fd = CreateFile(QFile::encodeName(filePath).constData(), GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0); #endif if (fd == INVALID_HANDLE_VALUE) { qCWarning(DIGIKAM_DIMG_LOG_PGF) << "Error: Could not open destination file."; return false; } #elif defined(__POSIX__) int fd = open(QFile::encodeName(filePath).constData(), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (fd == -1) { qCWarning(DIGIKAM_DIMG_LOG_PGF) << "Error: Could not open destination file."; return false; } #endif try { QVariant qualityAttr = imageGetAttribute(QLatin1String("quality")); int quality = qualityAttr.isValid() ? qualityAttr.toInt() : 3; qCDebug(DIGIKAM_DIMG_LOG_PGF) << "PGF quality: " << quality; CPGFFileStream stream(fd); CPGFImage pgf; PGFHeader header; header.width = imageWidth(); header.height = imageHeight(); header.quality = quality; if (imageHasAlpha()) { if (imageSixteenBit()) { // NOTE : there is no PGF color mode in 16 bits with alpha. header.channels = 3; header.bpp = 48; header.mode = ImageModeRGB48; } else { header.channels = 4; header.bpp = 32; header.mode = ImageModeRGBA; } } else { if (imageSixteenBit()) { header.channels = 3; header.bpp = 48; header.mode = ImageModeRGB48; } else { header.channels = 3; header.bpp = 24; header.mode = ImageModeRGBColor; } } #ifdef PGFCodecVersionID # if PGFCodecVersionID < 0x061142 header.background.rgbtBlue = 0; header.background.rgbtGreen = 0; header.background.rgbtRed = 0; # endif #endif pgf.SetHeader(header); // NOTE: see bug #273765 : Loading PGF thumbs with OpenMP support through a separated thread do not work properlly with libppgf 6.11.24 pgf.ConfigureEncoder(false); pgf.ImportBitmap(4 * imageWidth() * (imageSixteenBit() ? 2 : 1), (UINT8*)imageData(), imageBitsDepth() * 4, NULL, CallbackForLibPGF, this); UINT32 nWrittenBytes = 0; #ifdef PGFCodecVersionID # if PGFCodecVersionID >= 0x061124 pgf.Write(&stream, &nWrittenBytes, CallbackForLibPGF, this); # endif #else pgf.Write(&stream, 0, CallbackForLibPGF, &nWrittenBytes, this); #endif qCDebug(DIGIKAM_DIMG_LOG_PGF) << "PGF width = " << header.width; qCDebug(DIGIKAM_DIMG_LOG_PGF) << "PGF height = " << header.height; qCDebug(DIGIKAM_DIMG_LOG_PGF) << "PGF bbp = " << header.bpp; qCDebug(DIGIKAM_DIMG_LOG_PGF) << "PGF channels = " << header.channels; qCDebug(DIGIKAM_DIMG_LOG_PGF) << "PGF quality = " << header.quality; qCDebug(DIGIKAM_DIMG_LOG_PGF) << "PGF mode = " << header.mode; qCDebug(DIGIKAM_DIMG_LOG_PGF) << "Bytes Written = " << nWrittenBytes; #ifdef WIN32 CloseHandle(fd); #else close(fd); #endif // TODO: Store ICC profile in an appropriate place in the image storeColorProfileInMetadata(); if (observer) { observer->progressInfo(m_image, 1.0); } imageSetAttribute(QLatin1String("savedformat"), QLatin1String("PGF")); saveMetadata(filePath); return true; } catch (IOException& e) { int err = e.error; if (err >= AppError) { err -= AppError; } qCWarning(DIGIKAM_DIMG_LOG_PGF) << "Error: Opening and saving PGF image failed (" << err << ")!"; #ifdef WIN32 CloseHandle(fd); #else close(fd); #endif return false; } return true; }
bool PGFLoader::load(const QString& filePath, DImgLoaderObserver* const observer) { m_observer = observer; readMetadata(filePath, DImg::PGF); FILE* file = fopen(QFile::encodeName(filePath).constData(), "rb"); if (!file) { qCWarning(DIGIKAM_DIMG_LOG_PGF) << "Error: Could not open source file."; loadingFailed(); return false; } unsigned char header[3]; if (fread(&header, 3, 1, file) != 1) { fclose(file); loadingFailed(); return false; } unsigned char pgfID[3] = { 0x50, 0x47, 0x46 }; if (memcmp(&header[0], &pgfID, 3) != 0) { // not a PGF file fclose(file); loadingFailed(); return false; } fclose(file); // ------------------------------------------------------------------- // Initialize PGF API. #ifdef WIN32 #ifdef UNICODE HANDLE fd = CreateFile((LPCWSTR)(QFile::encodeName(filePath).constData()), GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0); #else HANDLE fd = CreateFile(QFile::encodeName(filePath).constData(), GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0); #endif if (fd == INVALID_HANDLE_VALUE) { loadingFailed(); return false; } #else int fd = open(QFile::encodeName(filePath).constData(), O_RDONLY); if (fd == -1) { loadingFailed(); return false; } #endif CPGFFileStream stream(fd); CPGFImage pgf; int colorModel = DImg::COLORMODELUNKNOWN; try { // open pgf image pgf.Open(&stream); switch (pgf.Mode()) { case ImageModeRGBColor: case ImageModeRGB48: m_hasAlpha = false; colorModel = DImg::RGB; break; case ImageModeRGBA: m_hasAlpha = true; colorModel = DImg::RGB; break; default: qCWarning(DIGIKAM_DIMG_LOG_PGF) << "Cannot load PGF image: color mode not supported (" << pgf.Mode() << ")"; loadingFailed(); return false; break; } switch (pgf.Channels()) { case 3: case 4: break; default: qCWarning(DIGIKAM_DIMG_LOG_PGF) << "Cannot load PGF image: color channels number not supported (" << pgf.Channels() << ")"; loadingFailed(); return false; break; } int bitDepth = pgf.BPP(); switch (bitDepth) { case 24: // RGB 8 bits. case 32: // RGBA 8 bits. m_sixteenBit = false; break; case 48: // RGB 16 bits. case 64: // RGBA 16 bits. m_sixteenBit = true; break; default: qCWarning(DIGIKAM_DIMG_LOG_PGF) << "Cannot load PGF image: color bits depth not supported (" << bitDepth << ")"; loadingFailed(); return false; break; } if(DIGIKAM_DIMG_LOG_PGF().isDebugEnabled()) { const PGFHeader* header = pgf.GetHeader(); qCDebug(DIGIKAM_DIMG_LOG_PGF) << "PGF width = " << header->width; qCDebug(DIGIKAM_DIMG_LOG_PGF) << "PGF height = " << header->height; qCDebug(DIGIKAM_DIMG_LOG_PGF) << "PGF bbp = " << header->bpp; qCDebug(DIGIKAM_DIMG_LOG_PGF) << "PGF channels = " << header->channels; qCDebug(DIGIKAM_DIMG_LOG_PGF) << "PGF quality = " << header->quality; qCDebug(DIGIKAM_DIMG_LOG_PGF) << "PGF mode = " << header->mode; qCDebug(DIGIKAM_DIMG_LOG_PGF) << "Has Alpha = " << m_hasAlpha; qCDebug(DIGIKAM_DIMG_LOG_PGF) << "Is 16 bits = " << m_sixteenBit; } // NOTE: see bug #273765 : Loading PGF thumbs with OpenMP support through a separated thread do not work properlly with libppgf 6.11.24 pgf.ConfigureDecoder(false); int width = pgf.Width(); int height = pgf.Height(); uchar* data = 0; QSize originalSize(width, height); if (m_loadFlags & LoadImageData) { // ------------------------------------------------------------------- // Find out if we do the fast-track loading with reduced size. PGF specific. int level = 0; QVariant attribute = imageGetAttribute(QLatin1String("scaledLoadingSize")); if (attribute.isValid() && pgf.Levels() > 0) { int scaledLoadingSize = attribute.toInt(); int i, w, h; for (i = pgf.Levels() - 1 ; i >= 0 ; --i) { w = pgf.Width(i); h = pgf.Height(i); if (qMin(w, h) >= scaledLoadingSize) { break; } } if (i >= 0) { width = w; height = h; level = i; qCDebug(DIGIKAM_DIMG_LOG_PGF) << "Loading PGF scaled version at level " << i << " (" << w << " x " << h << ") for size " << scaledLoadingSize; } } if (m_sixteenBit) { data = new_failureTolerant(width, height, 8); // 16 bits/color/pixel } else { data = new_failureTolerant(width, height, 4); // 8 bits/color/pixel } // Fill all with 255 including alpha channel. memset(data, 0xFF, width * height * (m_sixteenBit ? 8 : 4)); pgf.Read(level, CallbackForLibPGF, this); pgf.GetBitmap(m_sixteenBit ? width * 8 : width * 4, (UINT8*)data, m_sixteenBit ? 64 : 32, NULL, CallbackForLibPGF, this); if (observer) { observer->progressInfo(m_image, 1.0); } } // ------------------------------------------------------------------- // Get ICC color profile. if (m_loadFlags & LoadICCData) { // TODO: Implement proper storage in PGF for color profiles checkExifWorkingColorSpace(); } imageWidth() = width; imageHeight() = height; imageData() = data; imageSetAttribute(QLatin1String("format"), QLatin1String("PGF")); imageSetAttribute(QLatin1String("originalColorModel"), colorModel); imageSetAttribute(QLatin1String("originalBitDepth"), bitDepth); imageSetAttribute(QLatin1String("originalSize"), originalSize); #ifdef WIN32 CloseHandle(fd); #else close(fd); #endif return true; } catch (IOException& e) { int err = e.error; if (err >= AppError) { err -= AppError; } qCWarning(DIGIKAM_DIMG_LOG_PGF) << "Error: Opening and reading PGF image failed (" << err << ")!"; #ifdef WIN32 CloseHandle(fd); #else close(fd); #endif loadingFailed(); return false; } catch (std::bad_alloc& e) { qCWarning(DIGIKAM_DIMG_LOG_PGF) << "Failed to allocate memory for loading" << filePath << e.what(); #ifdef WIN32 CloseHandle(fd); #else close(fd); #endif loadingFailed(); return false; } return true; }
bool PPMLoader::load(const QString& filePath, DImgLoaderObserver* observer) { //TODO: progress information int width, height, rgbmax; char nl; FILE* file = fopen(QFile::encodeName(filePath), "rb"); if (!file) { kDebug() << "Cannot open image file."; loadingFailed(); return false; } ushort header; if (fread(&header, 2, 1, file) != 1) { kDebug() << "Cannot read header of file."; fclose(file); loadingFailed(); return false; } uchar* c = (uchar*) &header; if (*c != 'P') { kDebug() << "Not a PPM file."; fclose(file); loadingFailed(); return false; } ++c; if (*c != '6') { kDebug() << "Not a PPM file."; fclose(file); loadingFailed(); return false; } rewind(file); if (fscanf (file, "P6 %d %d %d%c", &width, &height, &rgbmax, &nl) != 4) { kDebug() << "Corrupted PPM file."; fclose (file); loadingFailed(); return false; } if (rgbmax <= 255) { kDebug() << "Not a 16 bits per color per pixel PPM file."; fclose (file); loadingFailed(); return false; } if (observer) { observer->progressInfo(m_image, 0.1F); } unsigned short* data = 0; if (m_loadFlags & LoadImageData) { data = new_short_failureTolerant(width*height*4); if (!data) { kDebug() << "Failed to allocate memory for loading" << filePath; fclose(file); loadingFailed(); return false; } unsigned short* dst = data; uchar src[6]; float fac = 65535.0 / rgbmax; int checkpoint = 0; #ifdef ENABLE_DEBUG_MESSAGES kDebug() << "rgbmax=" << rgbmax << " fac=" << fac; #endif for (int h = 0; h < height; ++h) { if (observer && h == checkpoint) { checkpoint += granularity(observer, height, 0.9F); if (!observer->continueQuery(m_image)) { delete [] data; fclose( file ); loadingFailed(); return false; } observer->progressInfo(m_image, 0.1 + (0.9 * ( ((float)h)/((float)height) ))); } for (int w = 0; w < width; ++w) { fread (src, 6 *sizeof(unsigned char), 1, file); dst[0] = (unsigned short)((src[4]*256 + src[5]) * fac); // Blue dst[1] = (unsigned short)((src[2]*256 + src[3]) * fac); // Green dst[2] = (unsigned short)((src[0]*256 + src[1]) * fac); // Red dst[3] = 0xFFFF; dst += 4; } } } fclose( file ); //---------------------------------------------------------- imageWidth() = width; imageHeight() = height; imageData() = (uchar*)data; imageSetAttribute("format", "PPM"); imageSetAttribute("originalColorFormat", DImg::RGB); imageSetAttribute("originalBitDepth", 8); imageSetAttribute("originalSize", QSize(width, height)); return true; }
// Function allocates and init a Game static game_p gameNew(engine_p engine, board_p board) { game_p game = NULL; context_p screen = NULL; int hd = 0; ASSERT(NULL != board, "gameNew"); game = (game_p)objectCreate( sizeof(game_t), (destructor_f)gameDestroy); game->board = boardRetain(board); screen = engineScreen(engine); game->width = contextWidth(screen); game->height = contextHeight(screen); game->padding = (game->width < game->height ? game->width : game->height) / 64; hd = engineHDSupported(engine); game->regular = fontRetain( fontLoad(hd ? fontNameRegularHD : fontNameRegularSD)); game->bold = fontRetain(fontLoad( hd ? fontNameBoldHD : fontNameBoldSD)); game->status_line = MAX(fontLine(game->regular), fontLine(game->bold)); game->images[0] = imageRetain( imageLoad(hd ? imageNameEmptyHD : imageNameEmptySD)); game->images[1] = imageRetain(imageLoad( hd ? imageName2HD : imageName2SD)); game->images[2] = imageRetain(imageLoad( hd ? imageName4HD : imageName4SD)); game->images[3] = imageRetain(imageLoad( hd ? imageName8HD : imageName8SD)); game->images[4] = imageRetain(imageLoad( hd ? imageName16HD : imageName16SD)); game->images[5] = imageRetain(imageLoad( hd ? imageName32HD : imageName32SD)); game->images[6] = imageRetain(imageLoad( hd ? imageName64HD : imageName64SD)); game->images[7] = imageRetain(imageLoad( hd ? imageName128HD : imageName128SD)); game->images[8] = imageRetain(imageLoad( hd ? imageName256HD : imageName256SD)); game->images[9] = imageRetain(imageLoad( hd ? imageName512HD : imageName512SD)); game->images[10] = imageRetain(imageLoad( hd ? imageName1024HD : imageName1024SD)); game->images[11] = imageRetain(imageLoad( hd ? imageName2048HD : imageName2048SD)); game->images[12] = imageRetain(imageLoad( hd ? imageName4096HD : imageName4096SD)); game->images[13] = imageRetain(imageLoad( hd ? imageName8192HD : imageName8192SD)); game->images[14] = imageRetain( imageLoad(hd ? imageName16384HD : imageName16384SD)); game->images[15] = imageRetain( imageLoad(hd ? imageName32768HD : imageName32768SD)); game->images[16] = imageRetain( imageLoad(hd ? imageName65536HD : imageName65536SD)); game->images[17] = imageRetain( imageLoad(hd ? imageName131072HD : imageName131072SD)); game->cell = MIN(imageWidth(game->images[0]), imageHeight(game->images[0])); game->board_back = rgbColor(0xBB, 0xAD, 0xA0); return game; };
bool JP2KLoader::save(const QString& filePath, DImgLoaderObserver* observer) { FILE* file = fopen(QFile::encodeName(filePath), "wb"); if (!file) { return false; } fclose(file); // ------------------------------------------------------------------- // Initialize JPEG 2000 API. register long i, x, y; unsigned long number_components; jas_image_t* jp2_image = 0; jas_stream_t* jp2_stream = 0; jas_matrix_t* pixels[4]; jas_image_cmptparm_t component_info[4]; int init = jas_init(); if (init != 0) { kDebug() << "Unable to init JPEG2000 decoder"; return false; } jp2_stream = jas_stream_fopen(QFile::encodeName(filePath), "wb"); if (jp2_stream == 0) { kDebug() << "Unable to open JPEG2000 stream"; return false; } number_components = imageHasAlpha() ? 4 : 3; for (i = 0 ; i < (long)number_components ; ++i) { component_info[i].tlx = 0; component_info[i].tly = 0; component_info[i].hstep = 1; component_info[i].vstep = 1; component_info[i].width = imageWidth(); component_info[i].height = imageHeight(); component_info[i].prec = imageBitsDepth(); component_info[i].sgnd = false; } jp2_image = jas_image_create(number_components, component_info, JAS_CLRSPC_UNKNOWN); if (jp2_image == 0) { jas_stream_close(jp2_stream); kDebug() << "Unable to create JPEG2000 image"; return false; } if (observer) { observer->progressInfo(m_image, 0.1F); } // ------------------------------------------------------------------- // Check color space. if (number_components >= 3 ) // RGB & RGBA { // Alpha Channel if (number_components == 4 ) { jas_image_setcmpttype(jp2_image, 3, JAS_IMAGE_CT_OPACITY); } jas_image_setclrspc(jp2_image, JAS_CLRSPC_SRGB); jas_image_setcmpttype(jp2_image, 0, JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_R)); jas_image_setcmpttype(jp2_image, 1, JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_G)); jas_image_setcmpttype(jp2_image, 2, JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_B)); } // ------------------------------------------------------------------- // Set ICC color profile. // FIXME : doesn't work yet! jas_cmprof_t* cm_profile = 0; jas_iccprof_t* icc_profile = 0; QByteArray profile_rawdata = m_image->getIccProfile().data(); icc_profile = jas_iccprof_createfrombuf((uchar*)profile_rawdata.data(), profile_rawdata.size()); if (icc_profile != 0) { cm_profile = jas_cmprof_createfromiccprof(icc_profile); if (cm_profile != 0) { jas_image_setcmprof(jp2_image, cm_profile); } } // ------------------------------------------------------------------- // Convert to JPEG 2000 pixels. for (i = 0 ; i < (long)number_components ; ++i) { pixels[i] = jas_matrix_create(1, (unsigned int)imageWidth()); if (pixels[i] == 0) { for (x = 0 ; x < i ; ++x) { jas_matrix_destroy(pixels[x]); } jas_image_destroy(jp2_image); kDebug() << "Error encoding JPEG2000 image data : Memory Allocation Failed"; return false; } } unsigned char* data = imageData(); unsigned char* pixel; unsigned short r, g, b, a=0; uint checkpoint = 0; for (y = 0 ; y < (long)imageHeight() ; ++y) { if (observer && y == (long)checkpoint) { checkpoint += granularity(observer, imageHeight(), 0.8F); if (!observer->continueQuery(m_image)) { jas_image_destroy(jp2_image); for (i = 0 ; i < (long)number_components ; ++i) { jas_matrix_destroy(pixels[i]); } jas_cleanup(); return false; } observer->progressInfo(m_image, 0.1 + (0.8 * ( ((float)y)/((float)imageHeight()) ))); } for (x = 0 ; x < (long)imageWidth() ; ++x) { pixel = &data[((y * imageWidth()) + x) * imageBytesDepth()]; if ( imageSixteenBit() ) // 16 bits image. { b = (unsigned short)(pixel[0]+256*pixel[1]); g = (unsigned short)(pixel[2]+256*pixel[3]); r = (unsigned short)(pixel[4]+256*pixel[5]); if (imageHasAlpha()) { a = (unsigned short)(pixel[6]+256*pixel[7]); } } else // 8 bits image. { b = (unsigned short)pixel[0]; g = (unsigned short)pixel[1]; r = (unsigned short)pixel[2]; if (imageHasAlpha()) { a = (unsigned short)(pixel[3]); } } jas_matrix_setv(pixels[0], x, r); jas_matrix_setv(pixels[1], x, g); jas_matrix_setv(pixels[2], x, b); if (number_components > 3) { jas_matrix_setv(pixels[3], x, a); } } for (i = 0 ; i < (long)number_components ; ++i) { int ret = jas_image_writecmpt(jp2_image, (short) i, 0, (unsigned int)y, (unsigned int)imageWidth(), 1, pixels[i]); if (ret != 0) { kDebug() << "Error encoding JPEG2000 image data"; jas_image_destroy(jp2_image); for (i = 0 ; i < (long)number_components ; ++i) { jas_matrix_destroy(pixels[i]); } jas_cleanup(); return false; } } } QVariant qualityAttr = imageGetAttribute("quality"); int quality = qualityAttr.isValid() ? qualityAttr.toInt() : 90; if (quality < 0) { quality = 90; } if (quality > 100) { quality = 100; } QString rate; QTextStream ts( &rate, QIODevice::WriteOnly ); // NOTE: to have a lossless compression use quality=100. // jp2_encode()::optstr: // - rate=#B => the resulting file size is about # bytes // - rate=0.0 .. 1.0 => the resulting file size is about the factor times // the uncompressed size ts << "rate=" << ( quality / 100.0F ); kDebug() << "JPEG2000 quality: " << quality; kDebug() << "JPEG2000 " << rate; int ret = jp2_encode(jp2_image, jp2_stream, rate.toUtf8().data()); if (ret != 0) { kDebug() << "Unable to encode JPEG2000 image"; jas_image_destroy(jp2_image); jas_stream_close(jp2_stream); for (i = 0 ; i < (long)number_components ; ++i) { jas_matrix_destroy(pixels[i]); } jas_cleanup(); return false; } if (observer) { observer->progressInfo(m_image, 1.0); } imageSetAttribute("savedformat", "JP2K"); saveMetadata(filePath); jas_image_destroy(jp2_image); jas_stream_close(jp2_stream); for (i = 0 ; i < (long)number_components ; ++i) { jas_matrix_destroy(pixels[i]); } jas_cleanup(); return true; }
void EpipolarGeometryDisplay::addEpipolarLine ( const Vector& epipolarLine ) { CoordT<double> start; CoordT<double> end; bool startOK = false; bool endOK = false; if ( isZero ( epipolarLine[1], 1e-20 ) ) { double x = -epipolarLine[2] / epipolarLine[0]; if ( x >= 0.0 && x <= imageWidth() - 1.0 ) { start.x = ( x / imageWidth() ); start.y = ( 1.0 ); startOK = true; end.x = ( x / imageWidth() ); end.y = ( 0.0 ); endOK = true; } } else { double x1 = - epipolarLine[2] / epipolarLine[0]; double x2 = - epipolarLine[1] / epipolarLine[0] * imageHeight() + x1; double y1 = - epipolarLine[2] / epipolarLine[1]; double y2 = - epipolarLine[0] / epipolarLine[1] * imageWidth() + y1; if ( x1 >= 0.0 && x1 <= imageWidth() ) { if ( !startOK ) { start.x = ( x1 / imageWidth() ); start.y = ( 1.0 ); startOK = true; } else if ( !endOK ) { end.x = ( x1 / imageWidth() ); end.y = ( 1.0 ); endOK = true; } } if ( x2 >= 0.0 && x2 <= imageWidth() ) { if ( !startOK ) { start.x = ( x2 / imageWidth() ); start.y = ( 0.0 ); startOK = true; } else if ( !endOK ) { end.x = ( x2 / imageWidth() ); end.y = ( 0.0 ); endOK = true; } } if ( y1 >= 0.0 && y1 <= imageHeight() ) { if ( !startOK ) { start.x = ( 0.0 ); start.y = ( 1.0f - y1 / imageHeight() ); startOK = true; } else if ( !endOK ) { end.x = ( 0.0 ); end.y = ( 1.0f - y1 / imageHeight() ); endOK = true; } } if ( y2 >= 0.0 && y2 <= imageHeight() ) { if ( !startOK ) { start.x = ( 1.0 ); start.y = ( 1.0f - y2 / imageHeight() ); startOK = true; } else if ( !endOK ) { end.x = ( 1.0 ); end.y = ( 1.0f - y2 / imageHeight() ); endOK = true; } } } if ( startOK && endOK ) m_epipolarLines->push_back ( std::pair<CoordT<double> , CoordT<double> > ( start, end ) ); }
bool V4LCamera::start() { struct video_capability caps; struct video_picture pict; struct video_window win; failed_ = true; fd_ = open("/dev/video0", O_RDONLY); if (fd_ == -1) { perror("can't open camera"); return false; } if (ioctl(fd_, VIDIOCGCAP, &caps) == -1) { perror("VIDIOGCAP failed"); return false; } if (ioctl(fd_, VIDIOCGPICT, &pict) == -1) { perror("VIDIOGPICT failed"); return false; } pict.palette = VIDEO_PALETTE_YUV420P; // XXX add converters if (ioctl(fd_, VIDIOCSPICT, &pict) == -1) { perror("VIDIOSPICT failed"); return false; } if (ioctl(fd_, VIDIOCGWIN, &win) == -1) { perror("VIDIOGWIN failed"); return false; } win.width = sizeinfo_[size_].width; win.height = sizeinfo_[size_].height; win.flags &= ~0x00ff0000; win.flags |= rate_ << 16; if (ioctl(fd_, VIDIOCSWIN, &win) == -1) { perror("VIDIOSWIN failed"); return false; } struct video_mbuf vidmbuf; if (ioctl(fd_, VIDIOCGMBUF, &vidmbuf) != -1) { printf("video mbufs: %d frames, %d bytes\n", vidmbuf.frames, vidmbuf.size); mmap_frames_ = vidmbuf.frames; mmap_nextframe_ = 0; mmap_size_ = vidmbuf.size; buf_ = (unsigned char *)mmap(0, mmap_size_, PROT_READ, MAP_SHARED, fd_, 0); for(unsigned i = 0; i < mmap_frames_; i++) { printf(" offset %u = %d\n", i, vidmbuf.offsets[i]); frameptrs_[i] = buf_ + vidmbuf.offsets[i]; } struct video_mmap vidmmap; vidmmap.frame = mmap_nextframe_; vidmmap.height = imageHeight(); vidmmap.width = imageWidth(); vidmmap.format = VIDEO_PALETTE_YUV420P; printf("vidmmap.frame=%u height=%d width=%d format=%u\n", vidmmap.frame, vidmmap.height, vidmmap.width, vidmmap.format); if (ioctl(fd_, VIDIOCMCAPTURE, &vidmmap) == 0) { printf("using mmap interface\n"); use_mmap_ = true; } } else buf_ = new unsigned char[imageSize()]; failed_ = false; return isOK(); }
bool QImageLoader::load(const QString& filePath, DImgLoaderObserver* const observer) { // Loading is opaque to us. No support for stopping from observer, // progress info are only pseudo values QImage image(filePath); if (observer) { observer->progressInfo(m_image, 0.9F); } if (image.isNull()) { kDebug() << "Can not load \"" << filePath << "\" using DImg::QImageLoader!"; loadingFailed(); return false; } int colorModel = DImg::COLORMODELUNKNOWN; int originalDepth = 0; switch (image.format()) { case QImage::Format_Invalid: default: colorModel = DImg::COLORMODELUNKNOWN; originalDepth = 0; break; case QImage::Format_Mono: case QImage::Format_MonoLSB: colorModel = DImg::MONOCHROME; originalDepth = 1; break; case QImage::Format_Indexed8: colorModel = DImg::INDEXED; originalDepth = 0; break; case QImage::Format_RGB32: colorModel = DImg::RGB; originalDepth = 8; break; case QImage::Format_ARGB32: case QImage::Format_ARGB32_Premultiplied: colorModel = DImg::RGB; originalDepth = 8; break; } m_hasAlpha = image.hasAlphaChannel(); QImage target = image.convertToFormat(QImage::Format_ARGB32); uint w = target.width(); uint h = target.height(); uchar* const data = new_failureTolerant(w, h, 4); if (!data) { kDebug() << "Failed to allocate memory for loading" << filePath; loadingFailed(); return false; } uint* sptr = reinterpret_cast<uint*>(target.bits()); uchar* dptr = data; for (uint i = 0 ; i < w * h ; ++i) { dptr[0] = qBlue(*sptr); dptr[1] = qGreen(*sptr); dptr[2] = qRed(*sptr); dptr[3] = qAlpha(*sptr); dptr += 4; sptr++; } if (observer) { observer->progressInfo(m_image, 1.0); } imageWidth() = w; imageHeight() = h; imageData() = data; // We considering that PNG is the most representative format of an image loaded by Qt imageSetAttribute("format", "PNG"); imageSetAttribute("originalColorModel", colorModel); imageSetAttribute("originalBitDepth", originalDepth); imageSetAttribute("originalSize", QSize(w, h)); return true; }
TEST_F(ImageDocumentTest, ImageLoad) { createDocument(50, 50); EXPECT_EQ(50, imageWidth()); EXPECT_EQ(50, imageHeight()); }
#include "Kirana.h" /****************************************************************************** * Function: Kirana * Inputs: * Returns: * Description: Default constructor ******************************************************************************/ Kirana::Kirana(std::string fileNameParam="K:\Kirana Videos\2018\180215\KirImage_0001.SVF"): magicNumber(0), // magic Number to read at begining ("SVF") imageNum(0), // number of images imageWidth(0), // width of image in pixels imageHeight(0), // height of image in pixels frameZeroSize(0), // Size of frame 0 frameZeroOffset(0), // Frame 0 offset headerSize(0), // size of header in bytes metaDataSize(0), // size of meta data block (images) imageInfoSize(0), // size of image info structure imageSeqSize(0), // Size of image sequence offsetBytes(0), // number of bytes offset for the file setupDataSize(0), // Size of xml setup block versionNum(0), // Version number cropRowLow(0), // The crop row value on the bottom cropRowHigh(0), // The crop row value in the top cropColHigh(0), // The crop value on the far right cropColLow(0), // The crop value on the far left metaData(0), // Offset of meta data block setupData(0), // Offset of xml setup block imageInfo(0), // Offset of image info structure
int QvisOpacitySlider::available() const { return imageWidth() - sliderLength(); }
void ZLMirroredPaintContext::drawImage(int x, int y, const ZLImageData &image, int width, int height, ScalingType type) { myBase.drawImage(mirroredX(x) - imageWidth(image, width, height, type), y, image, width, height, type); }
TEST_F(ImageDocumentTest, RestoreImageOnClick) { createDocument(30, 40); document().imageClicked(4, 4); EXPECT_EQ(50, imageWidth()); EXPECT_EQ(50, imageHeight()); }