< prev index next >

src/java.desktop/share/native/common/awt/medialib/mlib_ImageCreate.c

Print this page


   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 210     return NULL;
 211   }
 212 
 213   image -> flags    = ((width & 0xf) << 8);          /* set width field */
 214   image -> flags   |= ((stride & 0xf) << 16);        /* set stride field */
 215   image -> flags   |= ((height & 0xf) << 12);        /* set height field */
 216   image -> flags   |= (mlib_addr)data & 0xff;
 217   image -> flags   |= MLIB_IMAGE_USERALLOCATED;      /* user allocated data */
 218 
 219   if ((stride != wb) ||
 220       ((type == MLIB_BIT) && (stride * 8 != width * channels))) {
 221     image -> flags |= MLIB_IMAGE_ONEDVECTOR;
 222   }
 223 
 224   image -> flags &= MLIB_IMAGE_ATTRIBUTESET;
 225 
 226   return image;
 227 }
 228 
 229 /***************************************************************/
 230 JNIEXPORT mlib_image* JNICALL mlib_ImageCreateStruct(mlib_type  type,

 231                                    mlib_s32   channels,
 232                                    mlib_s32   width,
 233                                    mlib_s32   height,
 234                                    mlib_s32   stride,
 235                                    const void *data)
 236 {
 237   mlib_image *image;
 238   if (stride <= 0) {
 239     return NULL;
 240   }
 241 
 242   image = (mlib_image *)mlib_malloc(sizeof(mlib_image));
 243   if (image == NULL) {
 244     return NULL;
 245   }
 246 
 247   if (mlib_ImageSet(image, type, channels, width, height, stride, data) == NULL) {
 248     mlib_free(image);
 249     image = NULL;
 250   }
 251 
 252   return image;
 253 }
 254 
 255 /***************************************************************/
 256 JNIEXPORT mlib_image* JNICALL mlib_ImageCreate(mlib_type type,

 257                              mlib_s32  channels,
 258                              mlib_s32  width,
 259                              mlib_s32  height)
 260 {
 261   mlib_image *image;
 262   mlib_s32        wb;                /* width in bytes */
 263   void       *data;
 264 
 265 /* sanity check */
 266   if (width <= 0 || height <= 0 || channels < 1 || channels > 4) {
 267     return NULL;
 268   };
 269 
 270   if (!SAFE_TO_MULT(width, channels)) {
 271     return NULL;
 272   }
 273 
 274   wb = width * channels;
 275 
 276   switch (type) {


 335   image -> format   = MLIB_FORMAT_UNKNOWN;
 336 
 337   image -> paddings[0] = 0;
 338   image -> paddings[1] = 0;
 339   image -> paddings[2] = 0;
 340   image -> paddings[3] = 0;
 341 
 342   image -> bitoffset = 0;
 343 
 344   if ((type == MLIB_BIT) && (wb * 8 != width * channels)) {
 345     image -> flags |= MLIB_IMAGE_ONEDVECTOR;       /* not 1-d vector */
 346   }
 347 
 348   image -> flags &= MLIB_IMAGE_ATTRIBUTESET;
 349   image -> state  = NULL;
 350 
 351   return image;
 352 }
 353 
 354 /***************************************************************/
 355 JNIEXPORT void JNICALL mlib_ImageDelete(mlib_image *img)

 356 {
 357   if (img == NULL) return;
 358   if ((img -> flags & MLIB_IMAGE_USERALLOCATED) == 0) {
 359     mlib_free(img -> data);
 360   }
 361 
 362   mlib_ImageDeleteRowTable(img);
 363   mlib_free(img);
 364 }
 365 
 366 /***************************************************************/
 367 mlib_image *mlib_ImageCreateSubimage(mlib_image *img,
 368                                      mlib_s32   x,
 369                                      mlib_s32   y,
 370                                      mlib_s32   w,
 371                                      mlib_s32   h)
 372 {
 373   mlib_image     *subimage;
 374   mlib_type      type;
 375   mlib_s32       channels;


   1 /*
   2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 210     return NULL;
 211   }
 212 
 213   image -> flags    = ((width & 0xf) << 8);          /* set width field */
 214   image -> flags   |= ((stride & 0xf) << 16);        /* set stride field */
 215   image -> flags   |= ((height & 0xf) << 12);        /* set height field */
 216   image -> flags   |= (mlib_addr)data & 0xff;
 217   image -> flags   |= MLIB_IMAGE_USERALLOCATED;      /* user allocated data */
 218 
 219   if ((stride != wb) ||
 220       ((type == MLIB_BIT) && (stride * 8 != width * channels))) {
 221     image -> flags |= MLIB_IMAGE_ONEDVECTOR;
 222   }
 223 
 224   image -> flags &= MLIB_IMAGE_ATTRIBUTESET;
 225 
 226   return image;
 227 }
 228 
 229 /***************************************************************/
 230 JNIEXPORT
 231 mlib_image* mlib_ImageCreateStruct(mlib_type  type,
 232                                    mlib_s32   channels,
 233                                    mlib_s32   width,
 234                                    mlib_s32   height,
 235                                    mlib_s32   stride,
 236                                    const void *data)
 237 {
 238   mlib_image *image;
 239   if (stride <= 0) {
 240     return NULL;
 241   }
 242 
 243   image = (mlib_image *)mlib_malloc(sizeof(mlib_image));
 244   if (image == NULL) {
 245     return NULL;
 246   }
 247 
 248   if (mlib_ImageSet(image, type, channels, width, height, stride, data) == NULL) {
 249     mlib_free(image);
 250     image = NULL;
 251   }
 252 
 253   return image;
 254 }
 255 
 256 /***************************************************************/
 257 JNIEXPORT
 258 mlib_image* mlib_ImageCreate(mlib_type type,
 259                              mlib_s32  channels,
 260                              mlib_s32  width,
 261                              mlib_s32  height)
 262 {
 263   mlib_image *image;
 264   mlib_s32        wb;                /* width in bytes */
 265   void       *data;
 266 
 267 /* sanity check */
 268   if (width <= 0 || height <= 0 || channels < 1 || channels > 4) {
 269     return NULL;
 270   };
 271 
 272   if (!SAFE_TO_MULT(width, channels)) {
 273     return NULL;
 274   }
 275 
 276   wb = width * channels;
 277 
 278   switch (type) {


 337   image -> format   = MLIB_FORMAT_UNKNOWN;
 338 
 339   image -> paddings[0] = 0;
 340   image -> paddings[1] = 0;
 341   image -> paddings[2] = 0;
 342   image -> paddings[3] = 0;
 343 
 344   image -> bitoffset = 0;
 345 
 346   if ((type == MLIB_BIT) && (wb * 8 != width * channels)) {
 347     image -> flags |= MLIB_IMAGE_ONEDVECTOR;       /* not 1-d vector */
 348   }
 349 
 350   image -> flags &= MLIB_IMAGE_ATTRIBUTESET;
 351   image -> state  = NULL;
 352 
 353   return image;
 354 }
 355 
 356 /***************************************************************/
 357 JNIEXPORT
 358 void mlib_ImageDelete(mlib_image *img)
 359 {
 360   if (img == NULL) return;
 361   if ((img -> flags & MLIB_IMAGE_USERALLOCATED) == 0) {
 362     mlib_free(img -> data);
 363   }
 364 
 365   mlib_ImageDeleteRowTable(img);
 366   mlib_free(img);
 367 }
 368 
 369 /***************************************************************/
 370 mlib_image *mlib_ImageCreateSubimage(mlib_image *img,
 371                                      mlib_s32   x,
 372                                      mlib_s32   y,
 373                                      mlib_s32   w,
 374                                      mlib_s32   h)
 375 {
 376   mlib_image     *subimage;
 377   mlib_type      type;
 378   mlib_s32       channels;


< prev index next >