MCPcopy Create free account
hub / github.com/HandBrake/HandBrake / hb_image_init

Function hb_image_init

libhb/fifo.c:1085–1143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1083}
1084
1085hb_image_t * hb_image_init(int pix_fmt, int width, int height)
1086{
1087 const AVPixFmtDescriptor * desc = av_pix_fmt_desc_get(pix_fmt);
1088 uint8_t has_plane[4] = {0,};
1089 int ii, pp;
1090
1091 if (desc == NULL)
1092 {
1093 return NULL;
1094 }
1095
1096 hb_image_t *image = calloc(1, sizeof(hb_image_t));
1097 if (image == NULL)
1098 {
1099 return NULL;
1100 }
1101
1102 int size = 0;
1103 for (ii = 0; ii < desc->nb_components; ii++)
1104 {
1105 // For non-planar formats, comp[ii].plane can contain the
1106 // same value for multiple comp.
1107 pp = desc->comp[ii].plane;
1108 if (pp > image->max_plane)
1109 {
1110 image->max_plane = pp;
1111 }
1112 if (!has_plane[pp])
1113 {
1114 has_plane[pp] = 1;
1115 size += hb_image_stride( pix_fmt, width, pp ) *
1116 hb_image_height( pix_fmt, height, pp );
1117 }
1118 }
1119
1120 image->data = av_malloc(size);
1121 if (image->data == NULL)
1122 {
1123 free(image);
1124 return NULL;
1125 }
1126 image->format = pix_fmt;
1127 image->width = width;
1128 image->height = height;
1129 memset(image->data, 0, size);
1130
1131 uint8_t * data = image->data;
1132 for (pp = 0; pp <= image->max_plane; pp++)
1133 {
1134 image->plane[pp].data = data;
1135 image->plane[pp].stride = hb_image_stride(pix_fmt, width, pp);
1136 image->plane[pp].width = hb_image_width(pix_fmt, width, pp);
1137 image->plane[pp].height = hb_image_height(pix_fmt, height, pp);
1138 image->plane[pp].size = image->plane[pp].stride *
1139 image->plane[pp].height;
1140 data += image->plane[pp].size;
1141 }
1142 return image;

Callers 2

hb_get_previewFunction · 0.85
hb_json_to_imageFunction · 0.85

Calls 3

hb_image_strideFunction · 0.85
hb_image_heightFunction · 0.85
hb_image_widthFunction · 0.85

Tested by

no test coverage detected