1/* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import image from "@ohos.multimedia.image"; 17import fileio from "@ohos.fileio"; 18import colorSpaceManager from "@ohos.graphics.colorSpaceManager"; 19import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium"; 20import { testImg } from "./testImg"; 21import { testP3 } from "./testImg2"; 22import featureAbility from "@ohos.ability.featureAbility"; 23export default function ImageP3() { 24 describe("ImageP3", function () { 25 const COLORSPACENAME = 5; 26 let filePath; 27 let fdNumber; 28 let globalpixelmap; 29 let globalImagesource; 30 async function getFd(fileName) { 31 let context = await featureAbility.getContext(); 32 await context.getFilesDir().then((data) => { 33 filePath = data + "/" + fileName; 34 console.info("image case filePath is " + filePath); 35 }); 36 await fileio 37 .open(filePath) 38 .then((data) => { 39 fdNumber = data; 40 console.info("image case open fd success " + fdNumber); 41 }) 42 .catch((err) => { 43 console.info("image case open fd err " + err); 44 }); 45 } 46 47 beforeAll(async function () { 48 console.info("beforeAll case"); 49 }); 50 51 beforeEach(function () { 52 console.info("beforeEach case"); 53 }); 54 55 afterEach(async function () { 56 if (globalpixelmap != undefined) { 57 console.info("globalpixelmap release start"); 58 try { 59 await globalpixelmap.release(); 60 } catch (error) { 61 console.info("globalpixelmap release fail"); 62 } 63 } 64 if (globalImagesource != undefined) { 65 console.info("globalImagesource release start"); 66 try { 67 await globalImagesource.release(); 68 } catch (error) { 69 console.info("globalImagesource release fail"); 70 } 71 } 72 console.info("afterEach case"); 73 }); 74 75 afterAll(async function () { 76 console.info("afterAll case"); 77 }); 78 79 function GenPicSource(org) { 80 var data; 81 data = org.buffer; 82 return image.createImageSource(data); 83 } 84 85 function Logger(caseName) { 86 return { 87 myName: caseName, 88 log: function (msg) { 89 console.info(this.myName + " " + msg); 90 }, 91 }; 92 } 93 async function setColor(done, testNum, imageSource, colorSpaceName) { 94 let logger = Logger(testNum); 95 try { 96 logger.log("ImageSource " + (imageSource != undefined)); 97 if (imageSource != undefined) { 98 globalImagesource = imageSource; 99 let pixelMap = await imageSource.createPixelMap(); 100 globalpixelmap = pixelMap; 101 logger.log("PixelMap " + pixelMap); 102 var csm = colorSpaceManager.create(colorSpaceName); 103 logger.log("colorSpaceManager.ColorSpace: " + colorSpaceName); 104 pixelMap.setColorSpace(csm); 105 var csm1 = pixelMap.getColorSpace(); 106 logger.log("getColorSpace " + csm1); 107 var csmn = csm1.getColorSpaceName(); 108 logger.log("getColorSpaceName " + csmn); 109 expect(csmn == colorSpaceName).assertTrue(); 110 done(); 111 } else { 112 logger.log("createimageSource fail"); 113 expect(false).assertTrue(); 114 done(); 115 } 116 } catch (error) { 117 expect(false).assertTrue(); 118 logger.log("failed " + error); 119 done(); 120 } 121 } 122 123 /** 124 * @tc.number : SUB_GRAPHIC_IMAGE_GETCOLORSPACE_0100 125 * @tc.name : SUB_GRAPHIC_IMAGE_GETCOLORSPACE_0100 126 * @tc.desc : 1.create imagesource 127 * 2.createPixelMap 128 * 3.getColorSpace and getColorSpaceName 129 * @tc.size : MEDIUM 130 * @tc.type : Functional 131 * @tc.level : Level 0 132 */ 133 it("SUB_GRAPHIC_IMAGE_GETCOLORSPACE_0100", 0, async function (done) { 134 let logger = Logger("SUB_GRAPHIC_IMAGE_GETCOLORSPACE_0100"); 135 try { 136 let imageSource = GenPicSource(testImg); 137 if (imageSource != undefined) { 138 globalImagesource = imageSource; 139 let pixelMap = await imageSource.createPixelMap(); 140 globalpixelmap = pixelMap; 141 var csm = pixelMap.getColorSpace(); 142 logger.log("getColorSpace csm " + csm); 143 var csmn = csm.getColorSpaceName(); 144 logger.log("getColorSpaceName " + csmn); 145 expect(csmn == COLORSPACENAME).assertTrue(); 146 done(); 147 } else { 148 logger.log("createimageSource fail"); 149 expect(false).assertTrue(); 150 done(); 151 } 152 } catch (error) { 153 expect(false).assertTrue(); 154 logger.log("failed " + error); 155 done(); 156 } 157 }); 158 159 /** 160 * @tc.number : SUB_GRAPHIC_IMAGE_SETCOLORSPACE_0100 161 * @tc.name : SUB_GRAPHIC_IMAGE_SETCOLORSPACE_0100 162 * @tc.desc : 1.create imagesource 163 * 2.createPixelMap 164 * 3.setColorSpace 165 * 4.getColorSpace and getColorSpaceName 166 * @tc.size : MEDIUM 167 * @tc.type : Functional 168 * @tc.level : Level 0 169 */ 170 it("SUB_GRAPHIC_IMAGE_SETCOLORSPACE_0100", 0, function (done) { 171 let imageSource = image.createImageSource(testP3.buffer); 172 setColor( 173 done, 174 "SUB_GRAPHIC_IMAGE_SETCOLORSPACE_0100", 175 imageSource, 176 colorSpaceManager.ColorSpace.SRGB 177 ); 178 }); 179 180 /** 181 * @tc.number : SUB_GRAPHIC_IMAGE_SETCOLORSPACE_0200 182 * @tc.name : SUB_GRAPHIC_IMAGE_SETCOLORSPACE_0200 183 * @tc.desc : 1.create imagesource 184 * 2.createPixelMap 185 * 3.setColorSpace 186 * 4.getColorSpace and getColorSpaceName 187 * @tc.size : MEDIUM 188 * @tc.type : Functional 189 * @tc.level : Level 1 190 */ 191 it("SUB_GRAPHIC_IMAGE_SETCOLORSPACE_0200", 1, function (done) { 192 let imageSource = image.createImageSource(testImg.buffer); 193 setColor( 194 done, 195 "SUB_GRAPHIC_IMAGE_SETCOLORSPACE_0200", 196 imageSource, 197 colorSpaceManager.ColorSpace.DISPLAY_P3 198 ); 199 }); 200 201 /** 202 * @tc.number : SUB_GRAPHIC_IMAGE_SETCOLORSPACE_0300 203 * @tc.name : SUB_GRAPHIC_IMAGE_SETCOLORSPACE_0300 204 * @tc.desc : 1.create imagesource 205 * 2.createPixelMap 206 * 3.setColorSpace 207 * 4.getColorSpace and getColorSpaceName 208 * @tc.size : MEDIUM 209 * @tc.type : Functional 210 * @tc.level : Level 1 211 */ 212 it("SUB_GRAPHIC_IMAGE_SETCOLORSPACE_0300", 1, async function (done) { 213 await getFd("colorspace.jpg"); 214 let imageSource = image.createImageSource(fdNumber); 215 setColor( 216 done, 217 "SUB_GRAPHIC_IMAGE_SETCOLORSPACE_0300", 218 imageSource, 219 colorSpaceManager.ColorSpace.DISPLAY_P3 220 ); 221 }); 222 223 /** 224 * @tc.number : SUB_GRAPHIC_IMAGE_SETCOLORSPACE_0400 225 * @tc.name : SUB_GRAPHIC_IMAGE_SETCOLORSPACE_0400 226 * @tc.desc : 1.create imagesource 227 * 2.createPixelMap 228 * 3.setColorSpace 229 * 4.getColorSpace and getColorSpaceName 230 * @tc.size : MEDIUM 231 * @tc.type : Functional 232 * @tc.level : Level 1 233 */ 234 it("SUB_GRAPHIC_IMAGE_SETCOLORSPACE_0400", 1, async function (done) { 235 await getFd("DisplayP3.png"); 236 let imageSource = image.createImageSource(fdNumber); 237 setColor( 238 done, 239 "SUB_GRAPHIC_IMAGE_SETCOLORSPACE_0400", 240 imageSource, 241 colorSpaceManager.ColorSpace.SRGB 242 ); 243 }); 244 }); 245} 246