Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cpdf_pageimagecache_unittest.cpp
Go to the documentation of this file.
1// Copyright 2023 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "core/fpdfapi/page/cpdf_pageimagecache.h"
6
7#include <memory>
8#include <string>
9#include <utility>
10
11#include "core/fpdfapi/page/cpdf_docpagedata.h"
12#include "core/fpdfapi/page/cpdf_image.h"
13#include "core/fpdfapi/page/cpdf_imageobject.h"
14#include "core/fpdfapi/page/cpdf_page.h"
15#include "core/fpdfapi/page/cpdf_pagemodule.h"
16#include "core/fpdfapi/parser/cpdf_parser.h"
17#include "core/fpdfapi/render/cpdf_docrenderdata.h"
18#include "core/fxcrt/fx_stream.h"
19#include "testing/gtest/include/gtest/gtest.h"
20#include "testing/utils/path_service.h"
21
23 // If you render a page with a JPEG2000 image as a thumbnail (small picture)
24 // first, the image that gets cached has a low resolution. If you afterwards
25 // render it full-size, you should get a larger image - the image cache will
26 // be regenerate.
27
29 {
30 std::string file_path = PathService::GetTestFilePath("jpx_lzw.pdf");
31 ASSERT_FALSE(file_path.empty());
32 auto document =
33 std::make_unique<CPDF_Document>(std::make_unique<CPDF_DocRenderData>(),
34 std::make_unique<CPDF_DocPageData>());
35 ASSERT_EQ(document->LoadDoc(
37 nullptr),
39
40 RetainPtr<CPDF_Dictionary> page_dict =
41 document->GetMutablePageDictionary(0);
42 ASSERT_TRUE(page_dict);
43 auto page =
44 pdfium::MakeRetain<CPDF_Page>(document.get(), std::move(page_dict));
45 page->AddPageImageCache();
46 page->ParseContent();
47
48 CPDF_PageImageCache* page_image_cache = page->GetPageImageCache();
49 ASSERT_TRUE(page_image_cache);
50
51 CPDF_PageObject* page_obj = page->GetPageObjectByIndex(0);
52 ASSERT_TRUE(page_obj);
53 CPDF_ImageObject* image = page_obj->AsImage();
54 ASSERT_TRUE(image);
55
56 // Render with small scale.
57 bool should_continue = page_image_cache->StartGetCachedBitmap(
58 image->GetImage(), nullptr, page->GetMutablePageResources(), true,
60 while (should_continue)
61 should_continue = page_image_cache->Continue(nullptr);
62
63 RetainPtr<CFX_DIBBase> bitmap_small = page_image_cache->DetachCurBitmap();
64
65 // And render with large scale.
66 should_continue = page_image_cache->StartGetCachedBitmap(
67 image->GetImage(), nullptr, page->GetMutablePageResources(), true,
69 while (should_continue)
70 should_continue = page_image_cache->Continue(nullptr);
71
72 RetainPtr<CFX_DIBBase> bitmap_large = page_image_cache->DetachCurBitmap();
73
74 ASSERT_GT(bitmap_large->GetWidth(), bitmap_small->GetWidth());
75 ASSERT_GT(bitmap_large->GetHeight(), bitmap_small->GetHeight());
76
77 ASSERT_TRUE(page->AsPDFPage());
78 page->AsPDFPage()->ClearView();
79 }
81}
RetainPtr< CPDF_Image > GetImage() const
bool StartGetCachedBitmap(RetainPtr< CPDF_Image > pImage, const CPDF_Dictionary *pFormResources, const CPDF_Dictionary *pPageResources, bool bStdCS, CPDF_ColorSpace::Family eFamily, bool bLoadMask, const CFX_Size &max_size_required)
bool Continue(PauseIndicatorIface *pPause)
static void Destroy()
static void Create()
virtual CPDF_ImageObject * AsImage()
static RetainPtr< IFX_SeekableReadStream > CreateFromFilename(const char *filename)
Definition fx_stream.cpp:68
static std::string GetTestFilePath(const std::string &file_name)
TEST(FXCRYPT, MD5GenerateEmtpyData)