• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Multimedia Subsystem Changelog
2
3## cl.multimedia.1 Changed the Return Value of image.Component.rowStride
4
5**Access Level**
6
7Public API
8
9**Reason for Change**
10
11The current return value is the width of the image. It does not align with the API definition.
12
13**Change Impact**
14
15This change is a compatible change.
16
17Before change:
18
19Developers process the camera preview stream data based on the width and height.
20
21```ts
22// previewProfile indicates the width and height of the camera resolution chosen by the application, for example, 1080 x 1080.
23// component.byteBuffer is the buffer for storing the preview stream data returned by the camera.
24
25receiver.readNextImage((err, nextImage: image.Image)=>{
26    nextImage.getComponent(image.ComponentType.JPEG, async(err, component: image.Component)=>{
27        let width = previewProfile.size.width
28        let height = previewProfile.size.height
29        // The preview stream data is returned in NV21 format.
30        let pixelMap = await image.createPixelMap(component.byteBuffer, {
31            size:{height: height, width: width},
32            srcPixelFormat: image.PixelMapFormat.NV21,
33        })
34        ...
35    })
36})
37```
38
39After change:
40
41Developers process the camera preview stream data based on the width, height, and stride.
42
43```ts
44// previewProfile indicates the width and height of the camera resolution chosen by the application, for example, 1080 x 1080.
45// component.byteBuffer is the buffer for storing the preview stream data returned by the camera.
46receiver.readNextImage((err, nextImage: image.Image)=>{
47    nextImage.getComponent(image.ComponentType.JPEG, async(err, component: image.Component)=>{
48        let width = previewProfile.size.width
49        let height = previewProfile.size.height
50        let stride = component.rowStride
51        // The preview stream data is returned in NV21 format.
52        if (stride == width) {
53            let pixelMap = await image.createPixelMap(component.byteBuffer, {
54                size:{height: height, width: width},
55                srcPixelFormat: image.PixelMapFormat.NV21,
56            })
57        } else {
58            // Usage 1: Remove the stride from the data contained in component.byteBuffer, create a new array called dstArr with the copied data, and pass it to other APIs that do not support stride.
59            const dstBufferSize = width * height * 1.5
60            const dstArr = new Uint8Array(dstBufferSize)
61            for (let j = 0; j < height * 1.5; j++) {
62                // Copy the first width bytes of each line of data in component.byteBuffer to dstArr.
63                const srcBuf = new Uint8Array(component.byteBuffer, j*stride, width)
64                dstArr.set(srcBuf, j*width)
65            }
66            let pixelMap = await image.createPixelMap(dstArr.buffer, {
67                size:{height: height, width: width},
68                srcPixelFormat: image.PixelMapFormat.NV21,
69            })
70
71            // Usage 2: To create a PixelMap for display purposes based on the preview stream data contained in the byteBuffer, you can create a PixelMap using the product of stride and height, and then call the crop API to remove any extra pixels.
72            let pixelMap = await image.createPixelMap(dstArr.buffer, {
73                size:{height: height, width: stride},
74                srcPixelFormat: image.PixelMapFormat.NV21,
75            })
76            pixelMap.cropSync({size:{width:width, height:height}, x:0, y:0})
77
78            // Usage 3: Pass the preview stream data contained in the byteBuffer and stride to the API that supports stride.
79        }
80        ...
81    })
82})
83```
84
85**Start API Level**
86
879
88
89**Change Since**
90
91OpenHarmony SDK 5.0.0.50
92
93**Key API/Component Changes**
94
95API in @ohos.multimedia.image.d.ts:
96
97image.Component.rowStride
98
99**Adaptation Guide**
100
101Process the camera preview stream data based on the width, height, and stride.
102
103```ts
104// previewProfile indicates the width and height of the camera resolution chosen by the application, for example, 1080 x 1080.
105// component.byteBuffer is the buffer for storing the preview stream data returned by the camera.
106receiver.readNextImage((err, nextImage: image.Image)=>{
107    nextImage.getComponent(image.ComponentType.JPEG, async(err, component: image.Component)=>{
108        let width = previewProfile.size.width
109        let height = previewProfile.size.height
110        let stride = component.rowStride
111        // The preview stream data is returned in NV21 format.
112        if (stride == width) {
113            let pixelMap = await image.createPixelMap(component.byteBuffer, {
114                size:{height: height, width: width},
115                srcPixelFormat: image.PixelMapFormat.NV21,
116            })
117        } else {
118            // Usage 1: Remove the stride from the data contained in component.byteBuffer, create a new array called dstArr with the copied data, and pass it to other APIs that do not support stride.
119            const dstBufferSize = width * height * 1.5
120            const dstArr = new Uint8Array(dstBufferSize)
121            for (let j = 0; j < height * 1.5; j++) {
122                // Copy the first width bytes of each line of data in component.byteBuffer to dstArr.
123                const srcBuf = new Uint8Array(component.byteBuffer, j*stride, width)
124                dstArr.set(srcBuf, j*width)
125            }
126            let pixelMap = await image.createPixelMap(dstArr.buffer, {
127                size:{height: height, width: width},
128                srcPixelFormat: image.PixelMapFormat.NV21,
129            })
130
131            // Usage 2: To create a PixelMap for display purposes based on the preview stream data contained in the byteBuffer, you can create a PixelMap using the product of stride and height, and then call the crop API to remove any extra pixels.
132            let pixelMap = await image.createPixelMap(dstArr.buffer, {
133                size:{height: height, width: stride},
134                srcPixelFormat: image.PixelMapFormat.NV21,
135            })
136            pixelMap.cropSync({size:{width:width, height:height}, x:0, y:0})
137
138            // Usage 3: Pass the preview stream data contained in the byteBuffer and stride to the API that supports stride.
139        }
140        ...
141    })
142})
143```
144
145## cl.multimedia.2 Changed the Return Value of rowStride in the OhosImageComponent API
146
147**Access Level**
148
149Public API
150
151**Reason for Change**
152
153The current return value is the width of the image. It does not align with the API definition.
154
155**Change Impact**
156
157This change is a compatible change.
158
159Before change:
160
161Developers process the camera preview stream data based on the width and height.
162
163```C++
164// previewProfile indicates the width and height of the camera resolution chosen by the application, for example, 1080 x 1080.
165// component.byteBuffer is the buffer for storing the preview stream data returned by the camera.
166int32_t ret;
167napi_value nextImage;
168ret = OH_Image_Receiver_ReadNextImage(imageReceiver_c, &nextImage);
169ImageNative* nextImage_native = OH_Image_InitImageNative(env, nextImage);
170OhosImageComponent imgComponent;
171ret = OH_Image_GetComponent(nextImage_native, jpegComponent, &imgComponent);
172
173uint8_t* srcBuffer = imgComponent.byteBuffer;
174OH_Pixelmap_InitializationOptions* options = nullptr;
175OH_PixelmapInitializationOptions_Create(&options);
176OH_PixelmapInitializationOptions_SetWidth(options, previewProfile.size.width);
177OH_PixelmapInitializationOptions_SetHeight(options, previewProfile.size.height);
178OH_PixelmapInitializationOptions_SetSrcPixelFormat(options, PIXEL_FORMAT_NV21);
179OH_PixelmapInitializationOptions_SetPixelFormat(options, PIXEL_FORMAT_NV21);
180OH_PixelmapNative* pixelmap = nullptr;
181OH_PixelmapNative_CreatePixelmap(static_cast<unsigned char*>(srcBuffer), imgComponent.size, options, &pixelmap);
182```
183
184After change:
185
186Developers process the camera preview stream data based on the width, height, and stride.
187
188```C++
189// previewProfile indicates the width and height of the camera resolution chosen by the application, for example, 1080 x 1080.
190// srcBuffer is the buffer for storing the preview stream data returned by the camera.
191int32_t ret;
192napi_value nextImage;
193ret = OH_Image_Receiver_ReadNextImage(imageReceiver_c, &nextImage);
194ImageNative* nextImage_native = OH_Image_InitImageNative(env, nextImage);
195OhosImageComponent imgComponent;
196ret = OH_Image_GetComponent(nextImage_native, jpegComponent, &imgComponent);
197
198uint8_t* srcBuffer = imgComponent.byteBuffer;
199OH_Pixelmap_InitializationOptions* options = nullptr;
200OH_PixelmapInitializationOptions_Create(&options);
201OH_PixelmapInitializationOptions_SetWidth(options, previewProfile.size.width);
202OH_PixelmapInitializationOptions_SetHeight(options, previewProfile.size.height);
203OH_PixelmapInitializationOptions_SetSrcPixelFormat(options, PIXEL_FORMAT_NV21);
204OH_PixelmapInitializationOptions_SetPixelFormat(options, PIXEL_FORMAT_NV21);
205// The preview stream data is returned in NV21 format.
206OH_PixelmapNative* pixelmap = nullptr;
207if (stride == width) {
208    OH_PixelmapNative_CreatePixelmap(static_cast<unsigned char*>(srcBuffer), imgComponent.size, options, &pixelmap);
209} else {
210    // Usage 1: Remove the stride from the data contained in srcBuffer, create a new array called dstBuffer with the copied data, and pass it to other APIs that do not support stride.
211    size_t dstbufferSize = previewProfile.size.width * previewProfile.size.height * 1.5;
212    std::unique_ptr<uint8_t[]> dstBuffer = std::make_unique<uint8_t[]>(dstbufferSize);
213    uint8_t* dstPtr = dstBuffer.get();
214    for (int j = 0; j < previewProfile.size.height * 1.5; j++) {
215        memcpy_s(dstPtr, srcBuffer, previewProfile.size.width);
216        dstPtr += previewProfile.size.width;
217        srcBuffer += imgComponent.rowStride;
218    }
219    OH_PixelmapNative_CreatePixelmap(dstBuffer.get(), dstbufferSize, options, &pixelmap);
220
221    // Usage 2: To create a PixelMap for display purposes based on the preview stream data contained in the srcBuffer, you can create a PixelMap using the product of stride and height, and then call the crop API to remove any extra pixels.
222    OH_PixelmapInitializationOptions_SetWidth(options, imgComponent.rowStride);
223    OH_PixelmapNative_CreatePixelmap(static_cast<unsigned char*>(srcBuffer), imgComponent.size, options, &pixelmap);
224    Image_Region region{0, 0, previewProfile.size.width, previewProfile.size.height};
225    OH_PixelmapNative_Crop(pixelmap, &region);
226
227    // Usage 3: Pass the preview stream data contained in the srcBuffer and stride to the API that supports stride.
228}
229```
230
231**Start API Level**
232
23310
234
235**Change Since**
236
237OpenHarmony SDK 5.0.0.50
238
239**Key API/Component Changes**
240
241API in <multimedia/image_framework/image_mdk.h>:
242
243**rowStride** in the **OhosImageComponent** API
244
245**Adaptation Guide**
246
247Process the camera preview stream data based on the width, height, and stride.
248```C++
249// previewProfile indicates the width and height of the camera resolution chosen by the application, for example, 1080 x 1080.
250// srcBuffer is the buffer for storing the preview stream data returned by the camera.
251int32_t ret;
252napi_value nextImage;
253ret = OH_Image_Receiver_ReadNextImage(imageReceiver_c, &nextImage);
254ImageNative* nextImage_native = OH_Image_InitImageNative(env, nextImage);
255OhosImageComponent imgComponent;
256ret = OH_Image_GetComponent(nextImage_native, jpegComponent, &imgComponent);
257
258uint8_t* srcBuffer = imgComponent.byteBuffer;
259OH_Pixelmap_InitializationOptions* options = nullptr;
260OH_PixelmapInitializationOptions_Create(&options);
261OH_PixelmapInitializationOptions_SetWidth(options, previewProfile.size.width);
262OH_PixelmapInitializationOptions_SetHeight(options, previewProfile.size.height);
263OH_PixelmapInitializationOptions_SetSrcPixelFormat(options, PIXEL_FORMAT_NV21);
264OH_PixelmapInitializationOptions_SetPixelFormat(options, PIXEL_FORMAT_NV21);
265// The preview stream data is returned in NV21 format.
266OH_PixelmapNative* pixelmap = nullptr;
267if (stride == width) {
268    OH_PixelmapNative_CreatePixelmap(static_cast<unsigned char*>(srcBuffer), imgComponent.size, options, &pixelmap);
269} else {
270    // Usage 1: Remove the stride from the data contained in srcBuffer, create a new array called dstBuffer with the copied data, and pass it to other APIs that do not support stride.
271    size_t dstbufferSize = previewProfile.size.width * previewProfile.size.height * 1.5;
272    std::unique_ptr<uint8_t[]> dstBuffer = std::make_unique<uint8_t[]>(dstbufferSize);
273    uint8_t* dstPtr = dstBuffer.get();
274    for (int j = 0; j < previewProfile.size.height * 1.5; j++) {
275        memcpy_s(dstPtr, srcBuffer, previewProfile.size.width);
276        dstPtr += previewProfile.size.width;
277        srcBuffer += imgComponent.rowStride;
278    }
279    OH_PixelmapNative_CreatePixelmap(dstBuffer.get(), dstbufferSize, options, &pixelmap);
280
281    // Usage 2: To create a PixelMap for display purposes based on the preview stream data contained in the srcBuffer, you can create a PixelMap using the product of stride and height, and then call the crop API to remove any extra pixels.
282    OH_PixelmapInitializationOptions_SetWidth(options, imgComponent.rowStride);
283    OH_PixelmapNative_CreatePixelmap(static_cast<unsigned char*>(srcBuffer), imgComponent.size, options, &pixelmap);
284    Image_Region region{0, 0, previewProfile.size.width, previewProfile.size.height};
285    OH_PixelmapNative_Crop(pixelmap, &region);
286
287    // Usage 3: Pass the preview stream data contained in the srcBuffer and stride to the API that supports stride.
288}
289```
290
291## cl.multimedia.3 Changed the Return Value of OH_ImageNative_GetRowStride
292
293**Access Level**
294
295Public API
296
297**Reason for Change**
298
299The current return value is the width of the image. It does not align with the API definition.
300
301**Change Impact**
302
303This change is a compatible change.
304
305Before change:
306
307Developers process the camera preview stream data based on the width and height.
308
309```C++
310// previewProfile indicates the width and height of the camera resolution chosen by the application, for example, 1080 x 1080.
311
312OH_ImageNative* image = nullptr;
313Image_ErrorCode errCode = OH_ImageReceiverNative_ReadNextImage(receiver, &image);
314size_t typeSize = 0;
315OH_ImageNative_GetComponentTypes(image, nullptr, &typeSize);
316uint32_t* types = new uint32_t[typeSize];
317OH_ImageNative_GetComponentTypes(image, &types, &typeSize);
318uint32_t component = types[0];
319OH_NativeBuffer* imageBuffer = nullptr;
320errCode = OH_ImageNative_GetByteBuffer(image, component, &imageBuffer);
321sizt_t bufferSize = 0;
322errCode = OH_ImageNative_GetByteBufferSize(image, component, &bufferSize);
323
324void* srcVir = nullptr;
325OH_NativeBuffer_Map(imageBuffer, &srcVir);
326OH_Pixelmap_InitializationOptions* options = nullptr;
327OH_PixelmapInitializationOptions_Create(&options);
328OH_PixelmapInitializationOptions_SetWidth(options, previewProfile.size.width);
329OH_PixelmapInitializationOptions_SetHeight(options, previewProfile.size.height);
330OH_PixelmapInitializationOptions_SetSrcPixelFormat(options, PIXEL_FORMAT_NV21);
331OH_PixelmapInitializationOptions_SetPixelFormat(options, PIXEL_FORMAT_NV21);
332OH_PixelmapNative* pixelmap = nullptr;
333OH_PixelmapNative_CreatePixelmap(static_cast<unsigned char*>(srcVir), bufferSize, options, &pixelmap);
334OH_NativeBuffer_Unmap(imageBuffer);
335```
336
337After change:
338
339Developers process the camera preview stream data based on the width, height, and stride.
340
341```C++
342// previewProfile indicates the width and height of the camera resolution chosen by the application, for example, 1080 x 1080.
343
344OH_ImageNative* image = nullptr;
345Image_ErrorCode errCode = OH_ImageReceiverNative_ReadNextImage(receiver, &image);
346size_t typeSize = 0;
347OH_ImageNative_GetComponentTypes(image, nullptr, &typeSize);
348uint32_t* types = new uint32_t[typeSize];
349OH_ImageNative_GetComponentTypes(image, &types, &typeSize);
350uint32_t component = types[0];
351OH_NativeBuffer* imageBuffer = nullptr;
352errCode = OH_ImageNative_GetByteBuffer(image, component, &imageBuffer);
353size_t bufferSize = 0;
354errCode = OH_ImageNative_GetByteBufferSize(image, component, &bufferSize);
355int32_t stride = 0;
356errCode = OH_ImageNative_GetRowStride(image, component, &stride);
357
358void* srcVir = nullptr;
359OH_NativeBuffer_Map(imageBuffer, &srcVir);
360OH_Pixelmap_InitializationOptions* options = nullptr;
361OH_PixelmapInitializationOptions_Create(&options);
362OH_PixelmapInitializationOptions_SetWidth(options, previewProfile.size.width);
363OH_PixelmapInitializationOptions_SetHeight(options, previewProfile.size.height);
364OH_PixelmapInitializationOptions_SetSrcPixelFormat(options, PIXEL_FORMAT_NV21);
365OH_PixelmapInitializationOptions_SetPixelFormat(options, PIXEL_FORMAT_NV21);
366OH_PixelmapNative* pixelmap = nullptr;
367if (stride == width) {
368    OH_PixelmapNative_CreatePixelmap(static_cast<unsigned char*>(srcVir), bufferSize, options, &pixelmap);
369} else {
370    // The preview stream data is returned in NV21 format.
371    // Usage 1: Remove the stride from the data contained in srcBuffer, create a new array called dstBuffer with the copied data, and pass it to other APIs that do not support stride.
372    size_t dstbufferSize = previewProfile.size.width * previewProfile.size.height * 1.5;
373    std::unique_ptr<uint8_t[]> dstBuffer = std::make_unique<uint8_t[]>(dstbufferSize);
374    uint8_t* dstPtr = dstBuffer.get();
375    uint8_t* srcBuffer = static_cast<uint8_t*>(srcVir);
376    for (int j = 0; j < previewProfile.size.height * 1.5; j++) {
377        memcpy_s(dstPtr, srcBuffer, previewProfile.size.width);
378        dstPtr += previewProfile.size.width;
379        srcBuffer += imgComponent.rowStride;
380    }
381    OH_PixelmapNative_CreatePixelmap(dstBuffer.get(), dstbufferSize, options, &pixelmap);
382
383    // Usage 2: To create a PixelMap for display purposes based on the preview stream data contained in the srcBuffer, you can create a PixelMap using the product of stride and height, and then call the crop API to remove any extra pixels.
384    OH_PixelmapInitializationOptions_SetWidth(options, imgComponent.rowStride);
385    OH_PixelmapNative_CreatePixelmap(static_cast<unsigned char*>(srcBuffer), imgComponent.size, options, &pixelmap);
386    Image_Region region{0, 0, previewProfile.size.width, previewProfile.size.height};
387    OH_PixelmapNative_Crop(pixelmap, &region);
388
389    // Usage 3: Pass the preview stream data contained in the srcBuffer and stride to the API that supports stride.
390}
391OH_NativeBuffer_Unmap(imageBuffer);
392```
393
394**Start API Level**
395
39612
397
398**Change Since**
399
400OpenHarmony SDK 5.0.0.50
401
402**Key API/Component Changes**
403
404API in <multimedia/image_framework/image/image_native.h>:
405
406OH_ImageNative_GetRowStride
407
408**Adaptation Guide**
409
410Process the camera preview stream data based on the width, height, and stride.
411
412```c++
413// previewProfile indicates the width and height of the camera resolution chosen by the application, for example, 1080 x 1080.
414
415OH_ImageNative* image = nullptr;
416Image_ErrorCode errCode = OH_ImageReceiverNative_ReadNextImage(receiver, &image);
417size_t typeSize = 0;
418OH_ImageNative_GetComponentTypes(image, nullptr, &typeSize);
419uint32_t* types = new uint32_t[typeSize];
420OH_ImageNative_GetComponentTypes(image, &types, &typeSize);
421uint32_t component = types[0];
422OH_NativeBuffer* imageBuffer = nullptr;
423errCode = OH_ImageNative_GetByteBuffer(image, component, &imageBuffer);
424size_t bufferSize = 0;
425errCode = OH_ImageNative_GetByteBufferSize(image, component, &bufferSize);
426int32_t stride = 0;
427errCode = OH_ImageNative_GetRowStride(image, component, &stride);
428
429void* srcVir = nullptr;
430OH_NativeBuffer_Map(imageBuffer, &srcVir);
431OH_Pixelmap_InitializationOptions* options = nullptr;
432OH_PixelmapInitializationOptions_Create(&options);
433OH_PixelmapInitializationOptions_SetWidth(options, previewProfile.size.width);
434OH_PixelmapInitializationOptions_SetHeight(options, previewProfile.size.height);
435OH_PixelmapInitializationOptions_SetSrcPixelFormat(options, PIXEL_FORMAT_NV21);
436OH_PixelmapInitializationOptions_SetPixelFormat(options, PIXEL_FORMAT_NV21);
437OH_PixelmapNative* pixelmap = nullptr;
438if (stride == width) {
439    OH_PixelmapNative_CreatePixelmap(static_cast<unsigned char*>(srcVir), bufferSize, options, &pixelmap);
440} else {
441    // The preview stream data is returned in NV21 format.
442    // Usage 1: Remove the stride from the data contained in srcBuffer, create a new array called dstBuffer with the copied data, and pass it to other APIs that do not support stride.
443    size_t dstbufferSize = previewProfile.size.width * previewProfile.size.height * 1.5;
444    std::unique_ptr<uint8_t[]> dstBuffer = std::make_unique<uint8_t[]>(dstbufferSize);
445    uint8_t* dstPtr = dstBuffer.get();
446    uint8_t* srcBuffer = static_cast<uint8_t*>(srcVir);
447    for (int j = 0; j < previewProfile.size.height * 1.5; j++) {
448        memcpy_s(dstPtr, srcBuffer, previewProfile.size.width);
449        dstPtr += previewProfile.size.width;
450        srcBuffer += imgComponent.rowStride;
451    }
452    OH_PixelmapNative_CreatePixelmap(dstBuffer.get(), dstbufferSize, options, &pixelmap);
453
454    // Usage 2: To create a PixelMap for display purposes based on the preview stream data contained in the srcBuffer, you can create a PixelMap using the product of stride and height, and then call the crop API to remove any extra pixels.
455    OH_PixelmapInitializationOptions_SetWidth(options, imgComponent.rowStride);
456    OH_PixelmapNative_CreatePixelmap(static_cast<unsigned char*>(srcBuffer), imgComponent.size, options, &pixelmap);
457    Image_Region region{0, 0, previewProfile.size.width, previewProfile.size.height};
458    OH_PixelmapNative_Crop(pixelmap, &region);
459
460    // Usage 3: Pass the preview stream data contained in the srcBuffer and stride to the API that supports stride.
461}
462OH_NativeBuffer_Unmap(imageBuffer);
463```
464