1/* 2 * Copyright (c) 2022 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 { paramMock } from "../utils" 17 18const SizeMock = { 19 height: "[PC Preview] unknow height", 20 width: "[PC Preview] unknow width" 21} 22const ImageInfoMock = { 23 size: SizeMock 24} 25 26export const PixelMapMock = { 27 isEditable: "[PC Preview] unknow isEditable", 28 readPixelsToBuffer: function (...args) { 29 console.warn("PixelMap.readPixelsToBuffer interface mocked in the Previewer. How this interface works on the Previewer" + 30 " may be different from that on a real device.") 31 const len = args.length 32 if (typeof args[len - 1] === 'function') { 33 args[len - 1].call(this, paramMock.businessErrorMock); 34 } else { 35 return new Promise((resolve, reject) => { 36 resolve(); 37 }) 38 } 39 }, 40 readPixels: function (...args) { 41 console.warn("PixelMap.readPixels interface mocked in the Previewer. How this interface works on the Previewer" + 42 " may be different from that on a real device.") 43 const len = args.length 44 if (typeof args[len - 1] === 'function') { 45 args[len - 1].call(this, paramMock.businessErrorMock); 46 } else { 47 return new Promise((resolve, reject) => { 48 resolve(); 49 }) 50 } 51 }, 52 writePixels: function (...args) { 53 console.warn("PixelMap.writePixels interface mocked in the Previewer. How this interface works on the Previewer" + 54 " may be different from that on a real device.") 55 const len = args.length 56 if (typeof args[len - 1] === 'function') { 57 args[len - 1].call(this, paramMock.businessErrorMock); 58 } else { 59 return new Promise((resolve, reject) => { 60 resolve(); 61 }) 62 } 63 }, 64 writeBufferToPixels: function (...args) { 65 console.warn("PixelMap.writeBufferToPixels interface mocked in the Previewer. How this interface works on the Previewer" + 66 " may be different from that on a real device.") 67 const len = args.length 68 if (typeof args[len - 1] === 'function') { 69 args[len - 1].call(this, paramMock.businessErrorMock); 70 } else { 71 return new Promise((resolve, reject) => { 72 resolve(); 73 }) 74 } 75 }, 76 getImageInfo: function (...args) { 77 console.warn("PixelMap.getImageInfo interface mocked in the Previewer. How this interface works on the Previewer" + 78 " may be different from that on a real device.") 79 const len = args.length 80 if (len > 0 && typeof args[len - 1] === 'function') { 81 args[len - 1].call(this, paramMock.businessErrorMock, ImageInfoMock); 82 } else { 83 return new Promise((resolve, reject) => { 84 resolve(ImageInfoMock); 85 }) 86 } 87 }, 88 getBytesNumberPerRow: function (...args) { 89 console.warn("PixelMap.getBytesNumberPerRow interface mocked in the Previewer. How this interface works on the Previewer" + 90 " may be different from that on a real device.") 91 return paramMock.paramNumberMock 92 }, 93 getPixelBytesNumber: function (...args) { 94 console.warn("PixelMap.getPixelBytesNumber interface mocked in the Previewer. How this interface works on the Previewer" + 95 " may be different from that on a real device.") 96 return paramMock.paramNumberMock 97 }, 98 getDensity: function (...args) { 99 console.warn("PixelMap.getDensity interface mocked in the Previewer. How this interface works on the Previewer" + 100 " may be different from that on a real device.") 101 return paramMock.paramNumberMock 102 }, 103 opacity: function (...args) { 104 console.warn("PixelMap.opacity interface mocked in the Previewer. How this interface works on the Previewer" + 105 " may be different from that on a real device.") 106 const len = args.length 107 if (len > 0 && typeof args[len - 1] === 'function') { 108 args[len - 1].call(this, paramMock.businessErrorMock); 109 } else { 110 return new Promise((resolve, reject) => { 111 resolve(); 112 }) 113 } 114 }, 115 createAlphaPixelmap: function (...args) { 116 console.warn("PixelMap.createAlphaPixelmap interface mocked in the Previewer. How this interface works on the Previewer" + 117 " may be different from that on a real device.") 118 const len = args.length 119 if (len > 0 && typeof args[len - 1] === 'function') { 120 args[len - 1].call(this, paramMock.businessErrorMock,PixelMapMock); 121 } else { 122 return new Promise((resolve, reject) => { 123 resolve(PixelMapMock); 124 }) 125 } 126 }, 127 scale: function (...args) { 128 console.warn("PixelMap.scale interface mocked in the Previewer. How this interface works on the Previewer" + 129 " may be different from that on a real device.") 130 const len = args.length 131 if (len > 0 && typeof args[len - 1] === 'function') { 132 args[len - 1].call(this, paramMock.businessErrorMock); 133 } else { 134 return new Promise((resolve, reject) => { 135 resolve(); 136 }) 137 } 138 }, 139 translate: function (...args) { 140 console.warn("PixelMap.translate interface mocked in the Previewer. How this interface works on the Previewer" + 141 " may be different from that on a real device.") 142 const len = args.length 143 if (len > 0 && typeof args[len - 1] === 'function') { 144 args[len - 1].call(this, paramMock.businessErrorMock); 145 } else { 146 return new Promise((resolve, reject) => { 147 resolve(); 148 }) 149 } 150 }, 151 rotate: function (...args) { 152 console.warn("PixelMap.rotate interface mocked in the Previewer. How this interface works on the Previewer" + 153 " may be different from that on a real device.") 154 const len = args.length 155 if (len > 0 && typeof args[len - 1] === 'function') { 156 args[len - 1].call(this, paramMock.businessErrorMock); 157 } else { 158 return new Promise((resolve, reject) => { 159 resolve(); 160 }) 161 } 162 }, 163 flip: function (...args) { 164 console.warn("PixelMap.flip interface mocked in the Previewer. How this interface works on the Previewer" + 165 " may be different from that on a real device.") 166 const len = args.length 167 if (len > 0 && typeof args[len - 1] === 'function') { 168 args[len - 1].call(this, paramMock.businessErrorMock); 169 } else { 170 return new Promise((resolve, reject) => { 171 resolve(); 172 }) 173 } 174 }, 175 crop: function (...args) { 176 console.warn("PixelMap.flip interface mocked in the Previewer. How this interface works on the Previewer" + 177 " may be different from that on a real device.") 178 const len = args.length 179 if (len > 0 && typeof args[len - 1] === 'function') { 180 args[len - 1].call(this, paramMock.businessErrorMock); 181 } else { 182 return new Promise((resolve, reject) => { 183 resolve(); 184 }) 185 } 186 }, 187 release: function (...args) { 188 console.warn("PixelMap.release interface mocked in the Previewer. How this interface works on the Previewer" + 189 " may be different from that on a real device.") 190 const len = args.length 191 if (len > 0 && typeof args[len - 1] === 'function') { 192 args[len - 1].call(this, paramMock.businessErrorMock); 193 } else { 194 return new Promise((resolve, reject) => { 195 resolve(); 196 }) 197 } 198 } 199} 200 201export function mockMultimediaImage() { 202 const RegionMock = { 203 size: SizeMock, 204 x: "[PC Preview] unknow x", 205 y: "[PC Preview] unknow y" 206 } 207 const PositionAreaMock = { 208 pixels: "[PC Preview] unknow pixels", 209 offset: "[PC Preview] unknow offset", 210 stride: "[PC Preview] unknow stride", 211 region: RegionMock 212 } 213 const PackingOptionMock = { 214 format: "[PC Preview] unknow format", 215 quality: "[PC Preview] unknow quality" 216 } 217 const GetImagePropertyOptionsMock = { 218 index: "[PC Preview] unknow index", 219 defaultValue: "[PC Preview] unknow defaultValue" 220 } 221 const DecodingOptionsMock = { 222 index: "[PC Preview] unknow index", 223 sampleSize: "[PC Preview] unknow sampleSize", 224 rotate: "[PC Preview] unknow rotate", 225 editable: "[PC Preview] unknow editable", 226 desiredSize: SizeMock, 227 desiredRegion: RegionMock, 228 desiredPixelFormat: "[PC Preview] unknow desiredPixelFormat" 229 } 230 const ComponentMock = { 231 componentType: "[PC Preview] unknow componentType", 232 rowStride: "[PC Preview] unknow rowStride", 233 pixelStride: "[PC Preview] unknow pixelStride", 234 byteBuffer: "[PC Preview] unknow pixelStride" 235 } 236 const InitializationOptionsMock = { 237 size: SizeMock, 238 pixelFormat: "[PC Preview] unknow pixelFormat", 239 editable: "[PC Preview] unknow editable", 240 alphaType: "[PC Preview] unknow alphaType", 241 scaleMode: "[PC Preview] unknow scaleMode" 242 } 243 const SourceOptionsMock = { 244 sourceDensity:"[PC Preview] unknow sourceDensity", 245 sourcePixelFormat:"[PC Preview] unknow sourcePixelFormat", 246 sourceSize:SizeMock 247 } 248 249 const ImageSourceMock = { 250 getImageInfo: function (...args) { 251 console.warn("ImageSource.getImageInfo interface mocked in the Previewer. How this interface works on the" + 252 " Previewer may be different from that on a real device.") 253 const len = args.length 254 if (typeof args[len - 1] === 'function') { 255 args[len - 1].call(this, paramMock.businessErrorMock, ImageInfoMock); 256 } else { 257 return new Promise((resolve, reject) => { 258 resolve(ImageInfoMock); 259 }) 260 } 261 }, 262 release: function (...args) { 263 console.warn("ImageSource.release interface mocked in the Previewer. How this interface works on the Previewer" + 264 " may be different from that on a real device.") 265 const len = args.length 266 if (len > 0 && typeof args[len - 1] === 'function') { 267 args[len - 1].call(this, paramMock.businessErrorMock); 268 } else { 269 return new Promise((resolve, reject) => { 270 resolve(); 271 }) 272 } 273 }, 274 createPixelMap: function (...args) { 275 console.warn("ImageSource.createPixelMap interface mocked in the Previewer. How this interface works on the Previewer" + 276 " may be different from that on a real device.") 277 const len = args.length 278 if (len > 0 && typeof args[len - 1] === 'function') { 279 args[len - 1].call(this, paramMock.businessErrorMock, PixelMapMock); 280 } else { 281 return new Promise((resolve, reject) => { 282 resolve(PixelMapMock); 283 }) 284 } 285 }, 286 getImageProperty: function (...args) { 287 console.warn("ImageSource.getImageProperty interface mocked in the Previewer. How this interface works on the Previewer" + 288 " may be different from that on a real device.") 289 const len = args.length 290 if (len > 0 && typeof args[len - 1] === 'function') { 291 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 292 } else { 293 return new Promise((resolve, reject) => { 294 resolve(paramMock.paramStringMock); 295 }) 296 } 297 }, 298 modifyImageProperty: function (...args) { 299 console.warn("ImageSource.modifyImageProperty interface mocked in the Previewer. How this interface works on the Previewer" + 300 " may be different from that on a real device.") 301 const len = args.length 302 if (len > 0 && typeof args[len - 1] === 'function') { 303 args[len - 1].call(this, paramMock.businessErrorMock); 304 } else { 305 return new Promise((resolve, reject) => { 306 resolve(); 307 }) 308 } 309 }, 310 updateData: function (...args) { 311 console.warn("ImageSource.updateData interface mocked in the Previewer. How this interface works on the Previewer" + 312 " may be different from that on a real device.") 313 const len = args.length 314 if (len > 0 && typeof args[len - 1] === 'function') { 315 args[len - 1].call(this, paramMock.businessErrorMock); 316 } else { 317 return new Promise((resolve, reject) => { 318 resolve(); 319 }) 320 } 321 }, 322 release: function (...args) { 323 console.warn("ImageSource.release interface mocked in the Previewer. How this interface works on the Previewer" + 324 " may be different from that on a real device.") 325 const len = args.length 326 if (len > 0 && typeof args[len - 1] === 'function') { 327 args[len - 1].call(this, paramMock.businessErrorMock); 328 } else { 329 return new Promise((resolve, reject) => { 330 resolve(); 331 }) 332 } 333 }, 334 supportedFormats: "[PC Preview] unknow supportedFormats" 335 } 336 const ImagePackerMock = { 337 packing: function (...args) { 338 console.warn("ImagePacker.packing interface mocked in the Previewer. How this interface works on the Previewer" + 339 " may be different from that on a real device.") 340 const len = args.length 341 if (typeof args[len - 1] === 'function') { 342 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramArrayMock); 343 } else { 344 return new Promise((resolve, reject) => { 345 resolve(paramMock.paramArrayMock); 346 }) 347 } 348 }, 349 release: function (...args) { 350 console.warn("ImagePacker.release interface mocked in the Previewer. How this interface works on the Previewer" + 351 " may be different from that on a real device.") 352 const len = args.length 353 if (typeof args[len - 1] === 'function') { 354 args[len - 1].call(this, paramMock.businessErrorMock); 355 } else { 356 return new Promise((resolve, reject) => { 357 resolve(); 358 }) 359 } 360 }, 361 supportedFormats: "[PC Preview] unknow supportedFormats" 362 } 363 const ImageMock = { 364 clipRect: RegionMock, 365 size: SizeMock, 366 format: "[PC Preview] unknow format", 367 getComponent: function (...args) { 368 console.warn("Image.getComponent interface mocked in the Previewer. How this interface works on the Previewer" + 369 " may be different from that on a real device.") 370 const len = args.length 371 if (typeof args[len - 1] === 'function') { 372 args[len - 1].call(this, paramMock.businessErrorMock,ComponentMock); 373 } else { 374 return new Promise((resolve, reject) => { 375 resolve(ComponentMock); 376 }) 377 } 378 }, 379 release: function (...args) { 380 console.warn("Image.release interface mocked in the Previewer. How this interface works on the Previewer" + 381 " may be different from that on a real device.") 382 const len = args.length 383 if (typeof args[len - 1] === 'function') { 384 args[len - 1].call(this, paramMock.businessErrorMock); 385 } else { 386 return new Promise((resolve, reject) => { 387 resolve(); 388 }) 389 } 390 } 391 } 392 const ImageReceiverMock = { 393 size: SizeMock, 394 capacity: "[PC Preview] unknow width", 395 format: "[PC Preview] unknow format", 396 getReceivingSurfaceId: function (...args) { 397 console.warn("ImageReceiver.getReceivingSurfaceId interface mocked in the Previewer. How this interface works on the Previewer" + 398 " may be different from that on a real device.") 399 const len = args.length 400 if (len > 0 && typeof args[len - 1] === 'function') { 401 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 402 } else { 403 return new Promise((resolve, reject) => { 404 resolve(paramMock.paramStringMock); 405 }) 406 } 407 }, 408 readLatestImage: function (...args) { 409 console.warn("ImageReceiver.readLatestImage interface mocked in the Previewer. How this interface works on the Previewer" + 410 " may be different from that on a real device.") 411 const len = args.length 412 if (len > 0 && typeof args[len - 1] === 'function') { 413 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.ImageMock); 414 } else { 415 return new Promise((resolve, reject) => { 416 resolve(paramMock.ImageMock); 417 }) 418 } 419 }, 420 readNextImage: function (...args) { 421 console.warn("ImageReceiver.readNextImage interface mocked in the Previewer. How this interface works on the Previewer" + 422 " may be different from that on a real device.") 423 const len = args.length 424 if (len > 0 && typeof args[len - 1] === 'function') { 425 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.ImageMock); 426 } else { 427 return new Promise((resolve, reject) => { 428 resolve(paramMock.ImageMock); 429 }) 430 } 431 }, 432 on: function (...args) { 433 console.warn("ImageReceiver.on interface mocked in the Previewer. How this interface works on the Previewer" + 434 " may be different from that on a real device.") 435 }, 436 release: function (...args) { 437 console.warn("ImageReceiver.release interface mocked in the Previewer. How this interface works on the Previewer" + 438 " may be different from that on a real device.") 439 const len = args.length 440 if (len > 0 && typeof args[len - 1] === 'function') { 441 args[len - 1].call(this, paramMock.businessErrorMock); 442 } else { 443 return new Promise((resolve, reject) => { 444 resolve(); 445 }) 446 } 447 } 448 } 449 const image = { 450 PixelMapFormat: { 451 UNKNOWN: 0, 452 RGB_565: 2, 453 RGBA_8888: 3, 454 }, 455 PropertyKey: { 456 BITS_PER_SAMPLE: "BitsPerSample", 457 ORIENTATION: "Orientation", 458 IMAGE_LENGTH: "ImageLength", 459 IMAGE_WIDTH: "ImageWidth", 460 GPS_LATITUDE: "GPSLatitude", 461 GPS_LONGITUDE: "GPSLongitude", 462 GPS_LATITUDE_REF: "GPSLatitudeRef", 463 GPS_LONGITUDE_REF: "GPSLongitudeRef", 464 }, 465 ImageFormat: { 466 YCBCR_422_SP: 1000, 467 JPEG: 2000, 468 }, 469 AlphaType: { 470 UNKNOWN: 0, 471 OPAQUE: 1, 472 PREMUL: 2, 473 UNPREMUL: 3, 474 }, 475 ScaleMode: { 476 FIT_TARGET_SIZE: 0, 477 CENTER_CROP: 1, 478 }, 479 ComponentType: { 480 YUV_Y: 1, 481 YUV_U: 2, 482 YUV_V: 3, 483 JPEG: 4, 484 }, 485 createPixelMap: function (...args) { 486 console.warn("image.createPixelMap interface mocked in the Previewer. How this interface works on the Previewer" + 487 " may be different from that on a real device.") 488 const len = args.length 489 if (len > 0 && typeof args[len - 1] === 'function') { 490 args[len - 1].call(this, paramMock.businessErrorMock, PixelMapMock); 491 } else { 492 return new Promise((resolve, reject) => { 493 resolve(PixelMapMock); 494 }) 495 } 496 }, 497 createImageSource: function () { 498 console.warn("image.createImageSource interface mocked in the Previewer. How this interface works" + 499 " on the Previewer may be different from that on a real device.") 500 return ImageSourceMock; 501 }, 502 CreateIncrementalSource: function () { 503 console.warn("image.CreateIncrementalSource interface mocked in the Previewer. How this interface works" + 504 " on the Previewer may be different from that on a real device.") 505 return ImageSourceMock; 506 }, 507 createImagePacker: function () { 508 console.warn("image.createImagePacker interface mocked in the Previewer. How this interface works" + 509 " on the Previewer may be different from that on a real device.") 510 return ImagePackerMock; 511 }, 512 createImageReceiver: function () { 513 console.warn("image.createImageReceiver interface mocked in the Previewer. How this interface works" + 514 " on the Previewer may be different from that on a real device.") 515 return ImageReceiverMock; 516 } 517 } 518 return image; 519} 520